Changeset faca61b8 in mainline for uspace/lib/ui/test/pbutton.c


Ignore:
Timestamp:
2020-10-15T10:05:42Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8ef48ece
Parents:
4ed00d3
git-author:
Jiri Svoboda <jiri@…> (2020-10-14 19:05:34)
git-committer:
Jiri Svoboda <jiri@…> (2020-10-15 10:05:42)
Message:

Push button needs to handle position events itself

Also, release event should release the button regardless if it is
positioned inside or outside.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/test/pbutton.c

    r4ed00d3 rfaca61b8  
    185185}
    186186
     187/** ui_pos_event() correctly translates POS_PRESS/POS_RELEASE */
     188PCUT_TEST(pos_event_press_release)
     189{
     190        ui_pbutton_t *pbutton;
     191        pos_event_t event;
     192        gfx_rect_t rect;
     193        errno_t rc;
     194
     195        rc = ui_pbutton_create(NULL, "Hello", &pbutton);
     196        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     197
     198        PCUT_ASSERT_FALSE(pbutton->held);
     199
     200        rect.p0.x = 10;
     201        rect.p0.y = 20;
     202        rect.p1.x = 30;
     203        rect.p1.y = 40;
     204        ui_pbutton_set_rect(pbutton, &rect);
     205
     206        /* Press outside does nothing */
     207        event.type = POS_PRESS;
     208        event.hpos = 9;
     209        event.vpos = 20;
     210        ui_pbutton_pos_event(pbutton, &event);
     211        PCUT_ASSERT_FALSE(pbutton->held);
     212
     213        /* Press inside depresses button */
     214        event.type = POS_PRESS;
     215        event.hpos = 10;
     216        event.vpos = 20;
     217        ui_pbutton_pos_event(pbutton, &event);
     218        PCUT_ASSERT_TRUE(pbutton->held);
     219
     220        /* Release outside (or anywhere) relases button */
     221        event.type = POS_RELEASE;
     222        event.hpos = 9;
     223        event.vpos = 20;
     224        ui_pbutton_pos_event(pbutton, &event);
     225        PCUT_ASSERT_FALSE(pbutton->held);
     226
     227        ui_pbutton_destroy(pbutton);
     228}
     229
    187230static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    188231{
     
    214257                tbm->alloc.off0 = 0;
    215258                tbm->alloc.pixels = calloc(sizeof(uint32_t),
    216                         (params->rect.p1.x - params->rect.p0.x) *
    217                         (params->rect.p1.y - params->rect.p0.y));
     259                    (params->rect.p1.x - params->rect.p0.x) *
     260                    (params->rect.p1.y - params->rect.p0.y));
    218261                tbm->myalloc = true;
    219262                if (tbm->alloc.pixels == NULL) {
Note: See TracChangeset for help on using the changeset viewer.