helloworld.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * src/helloworld.c
  3. * https://gitlab.com/bztsrc/smgui
  4. *
  5. * Copyright (C) 2024 bzt (bztsrc@gitlab), MIT license
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to
  9. * deal in the Software without restriction, including without limitation the
  10. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  11. * sell copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
  20. * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  22. * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * @brief State-Mode GUI Hello World demo program
  25. */
  26. #define UI_IMPLEMENTATION
  27. #include <ui.h>
  28. int main(int argc, char **argv)
  29. {
  30. /* strings are gathered into an array so that you can change the language on-the-fly */
  31. enum { WINDOW_TITLE, HELLO_WORLD };
  32. char *english[] = { "Window title", "Hello World!" };
  33. ui_t ctx; /* the main context */
  34. ui_form_t form[2] = { /* your layout */
  35. { .type = UI_LABEL, .align = UI_CENTER, .x = UI_PERCENT(50), .y = 100, .label = HELLO_WORLD },
  36. { .type = UI_END }
  37. };
  38. /* initialize the UI context, pass it the string array, the window size and icon */
  39. ui_init(&ctx, 2, english, 640, 480, NULL);
  40. /* wait until user closes the window */
  41. while(ui_event(&ctx, form)) { }
  42. /* destroy window, free resources */
  43. ui_free(&ctx);
  44. (void)argc; (void)argv;
  45. return 0;
  46. }