M README.md => README.md +1 -1
@@ 22,7 22,7 @@ create cross-platform GUIs.
* ✅ uiMultilineEntry
* ✅ uiMenu and uiMenuItem
* ❌ uiArea
-* ❌ Helpers: ui{Open,Save}File, uiMsgBox, uiMsgBoxError
+* ✅ Dialogs: ui{Open,Save}File, uiMsgBox, uiMsgBoxError
* ✅ uiColorButton
* ✅ uiForm
* ❌ uiGrid
A libui/dialogs.ha => libui/dialogs.ha +52 -0
@@ 0,0 1,52 @@
+use types::c;
+
+// Requests to open a file. Returns the path, or void if the dialog has been
+// cancelled.
+export fn open_file(parent: *window) (str | void) = {
+ match (c_uiOpenFile(parent)) {
+ case let path: *c::char =>
+ return c::tostr(path)!;
+ case =>
+ return;
+ };
+};
+
+// Requests to save a file. Returns the path, or void if the dialog has been
+// cancelled.
+export fn save_file(parent: *window) (str | void) = {
+ match (c_uiSaveFile(parent)) {
+ case let path: *c::char =>
+ return c::tostr(path)!;
+ case =>
+ return;
+ };
+};
+
+// Opens a simple message dialog.
+export fn message_box(parent: *window, title: str, description: str) void = {
+ const title = c::fromstr(title);
+ defer free(title);
+ const description = c::fromstr(description);
+ defer free(description);
+
+ c_uiMsgBox(parent, title, description);
+};
+
+// Opens a simple message dialog with an error style.
+export fn message_box_error(
+ parent: *window,
+ title: str,
+ description: str,
+) void = {
+ const title = c::fromstr(title);
+ defer free(title);
+ const description = c::fromstr(description);
+ defer free(description);
+
+ c_uiMsgBoxError(parent, title, description);
+};
+
+@symbol("uiOpenFile") fn c_uiOpenFile(*window) nullable *c::char;
+@symbol("uiSaveFile") fn c_uiSaveFile(*window) nullable *c::char;
+@symbol("uiMsgBox") fn c_uiMsgBox(*window, *c::char, *c::char) void;
+@symbol("uiMsgBoxError") fn c_uiMsgBoxError(*window, *c::char, *c::char) void;