1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /*
- * src/demo.c
- * https://gitlab.com/bztsrc/smgui
- *
- * Copyright (C) 2024 bzt (bztsrc@gitlab), MIT license
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
- * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
- * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * @brief State-Mode GUI demo program
- */
- #define UI_IMPLEMENTATION
- #include <ui.h>
- int main(int argc, char **argv)
- {
- /* strings are gathered into an array so that you can change the language on-the-fly */
- enum { WINDOW_TITLE, POPUP_TITLE, BUTTON_TITLE, EASY_TITLE, HARD_TITLE, VOLUME_TITLE };
- char *lang[] = { "Basic demo", "Show", "Button", "easy", "hard", "Volume:" };
- /* variables to store game states */
- int button = 0, difficulty = 0, volume = 25;
- /* form referencing those variables, you use a HTML flow like layout */
- ui_t ctx;
- ui_form_t popup[] = {
- { .type = UI_BUTTON, .flags = UI_FORCEBR, .ptr = &button, .value = 1, .label = BUTTON_TITLE },
- { .type = UI_RADIO, .flags = UI_NOBR, .ptr = &difficulty, .value = 0, .y = 5, .label = EASY_TITLE },
- { .type = UI_RADIO, .flags = UI_FORCEBR, .ptr = &difficulty, .value = 1, .x = 20, .label = HARD_TITLE },
- { .type = UI_LABEL, .flags = UI_NOBR, .y = 5, .label = VOLUME_TITLE },
- { .type = UI_SLIDER, .ptr = &volume, .max = 100 },
- { .type = UI_END }
- };
- ui_form_t form[] = {
- { .type = UI_POPUP, .align = UI_CENTER | UI_MIDDLE, .x = UI_PERCENT(50), .y = UI_PERCENT(50), .m = 10,
- .ptr = &popup, .label = POPUP_TITLE },
- { .type = UI_END }
- };
- /* initialize the UI context, pass it the string array, the window size and icon */
- ui_init(&ctx, sizeof(lang)/sizeof(lang[0]), lang, 640, 480, NULL);
- /* wait until user closes the window */
- while(ui_event(&ctx, form)) {
- /* handle button, you could do this from another thread if you want */
- if(button) {
- printf("button clicked\n");
- button = 0;
- ui_refresh(&ctx);
- }
- }
- /* destroy window, free resources */
- ui_free(&ctx);
- (void)argc; (void)argv;
- return 0;
- }
|