diff --git a/build.gradle b/build.gradle index 27c72f28..24f67c93 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,18 @@ konanArtifacts { linkerOpts "build/samples.res" } } + + program('sampleForm') { + srcFiles 'samples/form/main.kt' + srcFiles fileTree('src/main/kotlin') + libraries { + artifact 'libui' + } + target 'mingw', { + dependsOn 'windres' + linkerOpts "build/samples.res" + } + } } task windres(type: Exec) { diff --git a/samples/form/README.md b/samples/form/README.md new file mode 100644 index 00000000..0950ac1b --- /dev/null +++ b/samples/form/README.md @@ -0,0 +1,7 @@ +# Form + +The sample shows a window with a basic login form. It has a field for username with plain text and another field for password with masked text that hides its content. Also there is a button with `Login` text. + +| Platform | Preview | +| :--: | :--: | +| Linux | ![Screenshot on Ubuntu](form-ubuntu.png) diff --git a/samples/form/form-ubuntu.png b/samples/form/form-ubuntu.png new file mode 100644 index 00000000..e412c89b Binary files /dev/null and b/samples/form/form-ubuntu.png differ diff --git a/samples/form/main.kt b/samples/form/main.kt new file mode 100644 index 00000000..14fac296 --- /dev/null +++ b/samples/form/main.kt @@ -0,0 +1,38 @@ +import kotlinx.cinterop.* +import libui.* + +fun main(args: Array) = memScoped { + val options = alloc() + val error = uiInit(options.ptr) + if (error != null) throw Error("Error: '${error.toKString()}'") + + val window = Window( + title = "Authentication required", + width = 320, + height = 200, + hasMenubar = false) + window.margined = true + + val box = VerticalBox().apply { padded = true } + + val (username, password) = Entry() to PasswordEntry() + + val button = Button(text = "Login") + uiButtonOnClicked( + button, + staticCFunction { _, _ -> /* TODO: Get text from username and password */ }, + button) + + val form = Form().apply { padded = true } + uiFormAppend(form, "Username", username.reinterpret(), 0) + uiFormAppend(form, "Password", password.reinterpret(), 0) + + uiBoxAppend(box, form.reinterpret(), 0) + uiBoxAppend(box, button.reinterpret(), 0) + + uiWindowSetChild(window, box.reinterpret()) + uiWindowOnClosing(window, staticCFunction { _, _ -> uiQuit(); 1 }, null) + uiControlShow(window.reinterpret()) + uiMain() + uiUninit() +}