51 lines
2.0 KiB
Plaintext
51 lines
2.0 KiB
Plaintext
#import "kryon.h"
|
|
#import "file_dialog.h"
|
|
#import "stdio.h"
|
|
|
|
app "Kryon File Dialog Example" {
|
|
size 800 600
|
|
fps 60
|
|
font examples
|
|
theme THEME_SKY light
|
|
}
|
|
|
|
state {
|
|
dlg: FileDialog = {0}
|
|
status: [256] char = "Choose an action."
|
|
last_path: [512] char = ""
|
|
dlg_ready: int = 0
|
|
}
|
|
|
|
screen FileDialogExample(viewport: Rectangle) {
|
|
Background(GetThemeBackground())
|
|
if dlg_ready == 0 {
|
|
InitFileDialog(&dlg)
|
|
dlg_ready = 1
|
|
}
|
|
Text("Kryon File Dialog", ScaleUIPx(32), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
|
Text("Dialog backend and result state", ScaleUIPx(32), ScaleUIPx(66), UI_TEXT_16, GetThemeIcon())
|
|
if GenericButton(101, ScaleUIPx(32), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Open File", UI_BUTTON_STYLE_PRIMARY, 0, NULL) {
|
|
BeginLoadFileDialog(&dlg,"Open File")
|
|
snprintf(status,sizeof(status),"Open file requested.")
|
|
}
|
|
if GenericButton(102, ScaleUIPx(226), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Save File", UI_BUTTON_STYLE_SECONDARY, 0, NULL) {
|
|
BeginSaveFileDialog(&dlg,"Save File","untitled.kry")
|
|
snprintf(status,sizeof(status),"Save file requested.")
|
|
}
|
|
if GenericButton(103, ScaleUIPx(420), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Select Folder", UI_BUTTON_STYLE_SECONDARY, 0, NULL) {
|
|
BeginSelectFileDialogFolder(&dlg,"Select Folder")
|
|
snprintf(status,sizeof(status),"Folder selection requested.")
|
|
}
|
|
dialog_result: int = UpdateFileDialog(&dlg)
|
|
if dialog_result == 1 {
|
|
snprintf(last_path,sizeof(last_path),"%s",GetFileDialogPath(&dlg))
|
|
snprintf(status,sizeof(status),"Selected: %s",last_path)
|
|
}
|
|
if dialog_result < 0 {
|
|
snprintf(status,sizeof(status),"Dialog cancelled.")
|
|
}
|
|
Text("Status", ScaleUIPx(32), ScaleUIPx(210), 18, GetThemeText())
|
|
Text(status, ScaleUIPx(32), ScaleUIPx(242), UI_TEXT_16, GetThemeText())
|
|
Text(last_path, ScaleUIPx(32), ScaleUIPx(274), UI_TEXT_16, GetThemeIcon())
|
|
}
|