Changeset 1026cc4 in mainline for uspace/app/uidemo/uidemo.c


Ignore:
Timestamp:
2022-03-20T19:51:09Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
26c90dd
Parents:
5ef85c0
Message:

Clicking scrollbar through to generate page up / page down

File:
1 edited

Legend:

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

    r5ef85c0 r1026cc4  
    8989static void scrollbar_up(ui_scrollbar_t *, void *);
    9090static void scrollbar_down(ui_scrollbar_t *, void *);
     91static void scrollbar_page_up(ui_scrollbar_t *, void *);
     92static void scrollbar_page_down(ui_scrollbar_t *, void *);
    9193static void scrollbar_moved(ui_scrollbar_t *, void *, gfx_coord_t);
    9294
     
    9496        .up = scrollbar_up,
    9597        .down = scrollbar_down,
     98        .page_up = scrollbar_page_up,
     99        .page_down = scrollbar_page_down,
    96100        .moved = scrollbar_moved
    97101};
     
    232236static void scrollbar_up(ui_scrollbar_t *scrollbar, void *arg)
    233237{
    234         ui_demo_t *demo = (ui_demo_t *) arg;
    235238        gfx_coord_t pos;
    236         char *str;
    237         errno_t rc;
    238         int rv;
    239239
    240240        pos = ui_scrollbar_get_pos(scrollbar);
     
    242242
    243243        pos = ui_scrollbar_get_pos(scrollbar);
    244 
    245         rv = asprintf(&str, "Scrollbar: %d of %d", (int) pos,
    246             ui_scrollbar_move_length(scrollbar));
    247         if (rv < 0) {
    248                 printf("Out of memory.\n");
    249                 return;
    250         }
    251 
    252         rc = ui_entry_set_text(demo->entry, str);
    253         if (rc != EOK)
    254                 printf("Error changing entry text.\n");
    255         (void) ui_entry_paint(demo->entry);
    256 
    257         free(str);
     244        scrollbar_moved(scrollbar, arg, pos);
    258245}
    259246
     
    265252static void scrollbar_down(ui_scrollbar_t *scrollbar, void *arg)
    266253{
    267         ui_demo_t *demo = (ui_demo_t *) arg;
    268254        gfx_coord_t pos;
    269         char *str;
    270         errno_t rc;
    271         int rv;
    272255
    273256        pos = ui_scrollbar_get_pos(scrollbar);
     
    275258
    276259        pos = ui_scrollbar_get_pos(scrollbar);
    277 
    278         rv = asprintf(&str, "Scrollbar: %d of %d", (int) pos,
    279             ui_scrollbar_move_length(scrollbar));
    280         if (rv < 0) {
    281                 printf("Out of memory.\n");
    282                 return;
    283         }
    284 
    285         rc = ui_entry_set_text(demo->entry, str);
    286         if (rc != EOK)
    287                 printf("Error changing entry text.\n");
    288         (void) ui_entry_paint(demo->entry);
    289 
    290         free(str);
     260        scrollbar_moved(scrollbar, arg, pos);
     261}
     262
     263/** Scrollbar page up event.
     264 *
     265 * @param scrollbar Scrollbar
     266 * @param arg Argument (demo)
     267 */
     268static void scrollbar_page_up(ui_scrollbar_t *scrollbar, void *arg)
     269{
     270        gfx_coord_t pos;
     271
     272        pos = ui_scrollbar_get_pos(scrollbar);
     273        ui_scrollbar_set_pos(scrollbar, pos -
     274            ui_scrollbar_through_length(scrollbar) / 4);
     275
     276        pos = ui_scrollbar_get_pos(scrollbar);
     277        scrollbar_moved(scrollbar, arg, pos);
     278}
     279
     280/** Scrollbar page down event.
     281 *
     282 * @param scrollbar Scrollbar
     283 * @param arg Argument (demo)
     284 */
     285static void scrollbar_page_down(ui_scrollbar_t *scrollbar, void *arg)
     286{
     287        gfx_coord_t pos;
     288
     289        pos = ui_scrollbar_get_pos(scrollbar);
     290        ui_scrollbar_set_pos(scrollbar, pos +
     291            ui_scrollbar_through_length(scrollbar) / 4);
     292
     293        pos = ui_scrollbar_get_pos(scrollbar);
     294        scrollbar_moved(scrollbar, arg, pos);
    291295}
    292296
Note: See TracChangeset for help on using the changeset viewer.