Changeset 5de71df in mainline


Ignore:
Timestamp:
2021-07-28T18:22:58Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dbb42c9
Parents:
a106037
Message:

Demonstrate entry alignment and read-only flag

We already have radio buttons and a check box that don't really
do anything useful so we might just use them.

Location:
uspace
Files:
4 edited

Legend:

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

    ra106037 r5de71df  
    9696};
    9797
     98/** Horizontal alignment selected by each radio button */
     99static const gfx_halign_t uidemo_halign[3] = {
     100        gfx_halign_left,
     101        gfx_halign_center,
     102        gfx_halign_right
     103};
     104
    98105/** Window close button was clicked.
    99106 *
     
    139146{
    140147        ui_demo_t *demo = (ui_demo_t *) arg;
    141         errno_t rc;
    142 
    143         if (enable) {
    144                 rc = ui_entry_set_text(demo->entry, "Checked");
    145                 if (rc != EOK)
    146                         printf("Error changing entry text.\n");
    147                 (void) ui_entry_paint(demo->entry);
    148         } else {
    149                 rc = ui_entry_set_text(demo->entry, "Unchecked");
    150                 if (rc != EOK)
    151                         printf("Error changing entry text.\n");
    152                 (void) ui_entry_paint(demo->entry);
    153         }
     148
     149        ui_entry_set_read_only(demo->entry, enable);
    154150}
    155151
     
    163159{
    164160        ui_demo_t *demo = (ui_demo_t *) garg;
    165         const char *text = (const char *) barg;
    166         errno_t rc;
    167 
    168         rc = ui_entry_set_text(demo->entry, text);
    169         if (rc != EOK)
    170                 printf("Error changing entry text.\n");
     161        gfx_halign_t halign = *(gfx_halign_t *) barg;
     162
     163        ui_entry_set_halign(demo->entry, halign);
    171164        (void) ui_entry_paint(demo->entry);
    172165}
     
    578571        }
    579572
    580         rc = ui_checkbox_create(ui_res, "Check me", &demo.checkbox);
     573        rc = ui_checkbox_create(ui_res, "Read only", &demo.checkbox);
    581574        if (rc != EOK) {
    582575                printf("Error creating check box.\n");
     
    604597        }
    605598
    606         rc = ui_rbutton_create(demo.rbgroup, "Option 1", (void *) "First",
    607             &demo.rb1);
     599        rc = ui_rbutton_create(demo.rbgroup, "Left", (void *) &uidemo_halign[0],
     600            &demo.rbleft);
    608601        if (rc != EOK) {
    609602                printf("Error creating radio button.\n");
     
    618611        rect.p1.x = 140;
    619612        rect.p1.y = 240;
    620         ui_rbutton_set_rect(demo.rb1, &rect);
    621 
    622         rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rb1));
    623         if (rc != EOK) {
    624                 printf("Error adding control to layout.\n");
    625                 return rc;
    626         }
    627 
    628         rc = ui_rbutton_create(demo.rbgroup, "Option 2", (void *) "Second",
    629             &demo.rb2);
     613        ui_rbutton_set_rect(demo.rbleft, &rect);
     614
     615        rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbleft));
     616        if (rc != EOK) {
     617                printf("Error adding control to layout.\n");
     618                return rc;
     619        }
     620
     621        rc = ui_rbutton_create(demo.rbgroup, "Center", (void *) &uidemo_halign[1],
     622            &demo.rbcenter);
    630623        if (rc != EOK) {
    631624                printf("Error creating radio button.\n");
     
    637630        rect.p1.x = 140;
    638631        rect.p1.y = 270;
    639         ui_rbutton_set_rect(demo.rb2, &rect);
    640 
    641         rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rb2));
    642         if (rc != EOK) {
    643                 printf("Error adding control to layout.\n");
    644                 return rc;
    645         }
    646 
    647         rc = ui_rbutton_create(demo.rbgroup, "Option 3", (void *) "Third",
    648             &demo.rb3);
     632        ui_rbutton_set_rect(demo.rbcenter, &rect);
     633        ui_rbutton_select(demo.rbcenter);
     634
     635        rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbcenter));
     636        if (rc != EOK) {
     637                printf("Error adding control to layout.\n");
     638                return rc;
     639        }
     640
     641        rc = ui_rbutton_create(demo.rbgroup, "Right", (void *) &uidemo_halign[2],
     642            &demo.rbright);
    649643        if (rc != EOK) {
    650644                printf("Error creating radio button.\n");
     
    656650        rect.p1.x = 140;
    657651        rect.p1.y = 300;
    658         ui_rbutton_set_rect(demo.rb3, &rect);
    659 
    660         rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rb3));
     652        ui_rbutton_set_rect(demo.rbright, &rect);
     653
     654        rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbright));
    661655        if (rc != EOK) {
    662656                printf("Error adding control to layout.\n");
  • uspace/app/uidemo/uidemo.h

    ra106037 r5de71df  
    6767        ui_checkbox_t *checkbox;
    6868        ui_rbutton_group_t *rbgroup;
    69         ui_rbutton_t *rb1;
    70         ui_rbutton_t *rb2;
    71         ui_rbutton_t *rb3;
     69        ui_rbutton_t *rbleft;
     70        ui_rbutton_t *rbcenter;
     71        ui_rbutton_t *rbright;
    7272        ui_slider_t *slider;
    7373} ui_demo_t;
  • uspace/lib/ui/include/ui/rbutton.h

    ra106037 r5de71df  
    6161extern void ui_rbutton_enter(ui_rbutton_t *);
    6262extern void ui_rbutton_leave(ui_rbutton_t *);
     63extern void ui_rbutton_select(ui_rbutton_t *);
    6364extern void ui_rbutton_selected(ui_rbutton_t *);
    6465extern ui_evclaim_t ui_rbutton_pos_event(ui_rbutton_t *, pos_event_t *);
  • uspace/lib/ui/src/rbutton.c

    ra106037 r5de71df  
    316316void ui_rbutton_release(ui_rbutton_t *rbutton)
    317317{
    318         ui_rbutton_t *old_selected;
    319 
    320318        if (!rbutton->held)
    321319                return;
     
    325323        if (rbutton->inside) {
    326324                /* Activate radio button */
    327                 old_selected = rbutton->group->selected;
    328 
    329                 if (old_selected != rbutton) {
    330                         rbutton->group->selected = rbutton;
    331                         ui_rbutton_paint(old_selected);
    332                 }
    333 
    334                 /* Repaint and notify */
    335                 (void) ui_rbutton_paint(rbutton);
    336 
    337                 if (old_selected != rbutton)
    338                         ui_rbutton_selected(rbutton);
     325                ui_rbutton_select(rbutton);
    339326        }
    340327}
     
    368355}
    369356
    370 /** Button was selected.
     357/** Select radio button.
     358 *
     359 * @param rbutton Radio button
     360 */
     361void ui_rbutton_select(ui_rbutton_t *rbutton)
     362{
     363        ui_rbutton_t *old_selected;
     364
     365        old_selected = rbutton->group->selected;
     366
     367        if (old_selected != rbutton) {
     368                rbutton->group->selected = rbutton;
     369                ui_rbutton_paint(old_selected);
     370        }
     371
     372        /* Repaint and notify */
     373        (void) ui_rbutton_paint(rbutton);
     374
     375        if (old_selected != rbutton)
     376                ui_rbutton_selected(rbutton);
     377}
     378
     379/** Notify that button was selected.
    371380 *
    372381 * @param rbutton Radio button
Note: See TracChangeset for help on using the changeset viewer.