-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from lucasvalenteds/sample-login-form
Add sample for type Form
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |