From 62a26977c793acde24ffad1f81647c0a4f68ed09 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Mon, 11 Sep 2017 15:56:52 +0200 Subject: libui: primp file picker dialogs * support for filters, for Windows (tested) and GTK (theoretical) * add extra parameter for setting the start directory, but not supported yet --- src/libui_sdl/main.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/libui_sdl/main.cpp') diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index c0992ef..e67ba8a 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -21,8 +21,7 @@ #include #include -#include -#include +#include "libui/ui.h" #include "../types.h" #include "../version.h" @@ -34,6 +33,14 @@ SDL_GLContext MainGL; void RunMainWindow(); +void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg) +{ + char* file = uiOpenFile(window, "DS ROM (*.nds)|*.nds;*.srl|Any file|*.*", NULL); + if (!file) return; + + printf("file opened: %s\n", file); +} + int main(int argc, char** argv) { srand(time(NULL)); @@ -47,8 +54,34 @@ int main(int argc, char** argv) return 1; } - RunMainWindow(); + uiInitOptions ui_opt; + memset(&ui_opt, 0, sizeof(uiInitOptions)); + const char* ui_err = uiInit(&ui_opt); + if (ui_err != NULL) + { + printf("libui shat itself :( %s\n", ui_err); + uiFreeInitError(ui_err); + return 1; + } + + //RunMainWindow(); + + uiMenu* menu; + uiMenuItem* menuitem; + + menu = uiNewMenu("File"); + menuitem = uiMenuAppendItem(menu, "Open..."); + uiMenuItemOnClicked(menuitem, OnOpenFile, NULL); + uiMenuAppendSeparator(menu); + uiMenuAppendItem(menu, "Quit"); + + uiWindow* win; + win = uiNewWindow("melonDS " MELONDS_VERSION, 256, 384, 1); + + uiControlShow(uiControl(win)); + uiMain(); + uiUninit(); SDL_Quit(); return 0; } -- cgit v1.2.3