Changeset 5de71df in mainline for uspace/app/uidemo/uidemo.c


Ignore:
Timestamp:
2021-07-28T18:22:58Z (4 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.

File:
1 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");
Note: See TracChangeset for help on using the changeset viewer.