Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/uidemo/uidemo.c

    r08499f0 ref4d684  
    11/*
    2  * Copyright (c) 2026 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3333 */
    3434
    35 #include <fibril_synch.h>
    3635#include <gfx/bitmap.h>
    3736#include <gfx/coord.h>
     
    6160#include "uidemo.h"
    6261
    63 enum {
    64         scrollbar_update_interval_ms = 1000,
    65         ui_demo_progress_step = 17
    66 };
    67 
    6862static errno_t bitmap_moire(gfx_bitmap_t *, gfx_coord_t, gfx_coord_t);
    6963
     
    114108static void uidemo_file_load(ui_menu_entry_t *, void *);
    115109static void uidemo_file_message(ui_menu_entry_t *, void *);
    116 static void uidemo_file_confirmation(ui_menu_entry_t *, void *);
    117110static void uidemo_file_exit(ui_menu_entry_t *, void *);
    118111static void uidemo_edit_modify(ui_menu_entry_t *, void *);
     
    347340}
    348341
    349 /** Display a message window with OK button.
     342/** Display a message window.
    350343 *
    351344 * @param demo UI demo
     
    412405        mdparams.caption = "Message For You";
    413406        mdparams.text = "Hello, world!";
    414 
    415         rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog);
    416         if (rc != EOK) {
    417                 printf("Error creating message dialog.\n");
    418                 return;
    419         }
    420 
    421         ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo);
    422 }
    423 
    424 /** File / Confirmation menu entry selected.
    425  *
    426  * @param mentry Menu entry
    427  * @param arg Argument (demo)
    428  */
    429 static void uidemo_file_confirmation(ui_menu_entry_t *mentry, void *arg)
    430 {
    431         ui_demo_t *demo = (ui_demo_t *) arg;
    432         ui_msg_dialog_params_t mdparams;
    433         ui_msg_dialog_t *dialog;
    434         errno_t rc;
    435 
    436         ui_msg_dialog_params_init(&mdparams);
    437         mdparams.caption = "Confirmation";
    438         mdparams.text = "This will not actually do anything. Proceed?";
    439         mdparams.choice = umdc_ok_cancel;
    440407
    441408        rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog);
     
    720687        (void) demo;
    721688        ui_msg_dialog_destroy(dialog);
    722 }
    723 
    724 static void ui_demo_timer_fun(void *arg)
    725 {
    726         ui_demo_t *demo = (ui_demo_t *) arg;
    727 
    728         if (demo->progress_value < 100) {
    729                 demo->progress_value += ui_demo_progress_step;
    730                 if (demo->progress_value > 100)
    731                         demo->progress_value = 100;
    732         } else {
    733                 demo->progress_value = 0;
    734         }
    735 
    736         ui_progress_set_value(demo->progress, demo->progress_value);
    737 
    738         if (ui_tab_is_selected(demo->tbars)) {
    739                 ui_lock(demo->ui);
    740                 ui_progress_paint(demo->progress);
    741                 ui_unlock(demo->ui);
    742         }
    743 
    744         fibril_timer_set(demo->timer, 1000 * scrollbar_update_interval_ms,
    745             ui_demo_timer_fun, (void *)demo);
    746689}
    747690
     
    798741        }
    799742
    800         /* Only allow making the window larger */
    801         gfx_rect_dims(&params.rect, &params.min_size);
    802 
    803743        rc = ui_window_create(ui, &params, &window);
    804744        if (rc != EOK) {
     
    838778
    839779        ui_menu_entry_set_cb(mmsg, uidemo_file_message, (void *) &demo);
    840 
    841         rc = ui_menu_entry_create(demo.mfile, "~C~onfirmation", "", &mmsg);
    842         if (rc != EOK) {
    843                 printf("Error creating menu.\n");
    844                 return rc;
    845         }
    846 
    847         ui_menu_entry_set_cb(mmsg, uidemo_file_confirmation, (void *) &demo);
    848780
    849781        rc = ui_menu_entry_create(demo.mfile, "~L~oad", "", &mload);
     
    981913
    982914        rc = ui_tab_create(demo.tabset, "Lists", &demo.tlists);
    983         if (rc != EOK) {
    984                 printf("Error creating tab.\n");
    985                 return rc;
    986         }
    987 
    988         rc = ui_tab_create(demo.tabset, "Bars", &demo.tbars);
    989915        if (rc != EOK) {
    990916                printf("Error creating tab.\n");
     
    14651391        ui_tab_add(demo.tlists, ui_fixed_ctl(demo.lfixed));
    14661392
    1467         rc = ui_fixed_create(&demo.bars_fixed);
    1468         if (rc != EOK) {
    1469                 printf("Error creating fixed layout.\n");
    1470                 return rc;
    1471         }
    1472 
    1473         rc = ui_progress_create(ui_res, 0, &demo.progress);
    1474         if (rc != EOK) {
    1475                 printf("Error creating entry.\n");
    1476                 return rc;
    1477         }
    1478 
    1479         /* FIXME: Auto layout */
    1480         if (ui_is_textmode(ui)) {
    1481                 rect.p0.x = 4;
    1482                 rect.p0.y = 5;
    1483                 rect.p1.x = 42;
    1484                 rect.p1.y = 6;
    1485         } else {
    1486                 rect.p0.x = 15;
    1487                 rect.p0.y = 88;
    1488                 rect.p1.x = 243;
    1489                 rect.p1.y = 113;
    1490         }
    1491 
    1492         ui_progress_set_rect(demo.progress, &rect);
    1493 
    1494         rc = ui_fixed_add(demo.bars_fixed, ui_progress_ctl(demo.progress));
    1495         if (rc != EOK) {
    1496                 printf("Error adding control to layout.\n");
    1497                 return rc;
    1498         }
    1499 
    1500         ui_tab_add(demo.tbars, ui_fixed_ctl(demo.bars_fixed));
    1501 
    15021393        ui_window_add(window, ui_fixed_ctl(demo.fixed));
    15031394
    1504         demo.timer = fibril_timer_create(NULL);
    1505         if (demo.timer == NULL) {
    1506                 printf("Error creating timer.\n");
    1507                 return ENOMEM;
    1508         }
    1509 
    1510         fibril_timer_set(demo.timer, 1000 * scrollbar_update_interval_ms,
    1511             ui_demo_timer_fun, (void *)&demo);
    1512 
    15131395        rc = ui_window_paint(window);
    15141396        if (rc != EOK) {
     
    15181400
    15191401        ui_run(ui);
    1520 
    1521         fibril_timer_clear(demo.timer);
    1522         fibril_timer_destroy(demo.timer);
    15231402
    15241403        ui_window_destroy(window);
Note: See TracChangeset for help on using the changeset viewer.