Skip to content

Commit f8ae989

Browse files
authored
Merge pull request msink#1 from lucasvalenteds/sample-login-form
Add sample for type Form
2 parents 69f77f9 + 00617a8 commit f8ae989

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ konanArtifacts {
3939
linkerOpts "build/samples.res"
4040
}
4141
}
42+
43+
program('sampleForm') {
44+
srcFiles 'samples/form/main.kt'
45+
srcFiles fileTree('src/main/kotlin')
46+
libraries {
47+
artifact 'libui'
48+
}
49+
target 'mingw', {
50+
dependsOn 'windres'
51+
linkerOpts "build/samples.res"
52+
}
53+
}
4254
}
4355

4456
task windres(type: Exec) {

samples/form/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Form
2+
3+
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.
4+
5+
| Platform | Preview |
6+
| :--: | :--: |
7+
| Linux | ![Screenshot on Ubuntu](form-ubuntu.png)

samples/form/form-ubuntu.png

12 KB
Loading

samples/form/main.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import kotlinx.cinterop.*
2+
import libui.*
3+
4+
fun main(args: Array<String>) = memScoped {
5+
val options = alloc<uiInitOptions>()
6+
val error = uiInit(options.ptr)
7+
if (error != null) throw Error("Error: '${error.toKString()}'")
8+
9+
val window = Window(
10+
title = "Authentication required",
11+
width = 320,
12+
height = 200,
13+
hasMenubar = false)
14+
window.margined = true
15+
16+
val box = VerticalBox().apply { padded = true }
17+
18+
val (username, password) = Entry() to PasswordEntry()
19+
20+
val button = Button(text = "Login")
21+
uiButtonOnClicked(
22+
button,
23+
staticCFunction { _, _ -> /* TODO: Get text from username and password */ },
24+
button)
25+
26+
val form = Form().apply { padded = true }
27+
uiFormAppend(form, "Username", username.reinterpret(), 0)
28+
uiFormAppend(form, "Password", password.reinterpret(), 0)
29+
30+
uiBoxAppend(box, form.reinterpret(), 0)
31+
uiBoxAppend(box, button.reinterpret(), 0)
32+
33+
uiWindowSetChild(window, box.reinterpret())
34+
uiWindowOnClosing(window, staticCFunction { _, _ -> uiQuit(); 1 }, null)
35+
uiControlShow(window.reinterpret())
36+
uiMain()
37+
uiUninit()
38+
}

0 commit comments

Comments
 (0)