Skip to content

Commit

Permalink
Merge pull request #1 from lucasvalenteds/sample-login-form
Browse files Browse the repository at this point in the history
Add sample for type Form
  • Loading branch information
msink authored May 22, 2018
2 parents 69f77f9 + 00617a8 commit f8ae989
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
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()
}

0 comments on commit f8ae989

Please sign in to comment.