Skip to content

Add sample for type Form #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions samples/form/README.md
Original file line number Diff line number Diff line change
@@ -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)
Binary file added samples/form/form-ubuntu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions samples/form/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import kotlinx.cinterop.*
import libui.*

fun main(args: Array<String>) = memScoped {
val options = alloc<uiInitOptions>()
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()
}