Changeset faca61b8 in mainline for uspace/lib
- Timestamp:
- 2020-10-15T10:05:42Z (5 years ago)
- 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)
- Location:
- uspace/lib/ui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/ui/pbutton.h
r4ed00d3 rfaca61b8 39 39 #include <errno.h> 40 40 #include <gfx/coord.h> 41 #include <io/pos_event.h> 41 42 #include <types/ui/pbutton.h> 42 43 #include <types/ui/resource.h> … … 51 52 extern void ui_pbutton_press(ui_pbutton_t *); 52 53 extern void ui_pbutton_release(ui_pbutton_t *); 54 extern void ui_pbutton_pos_event(ui_pbutton_t *, pos_event_t *); 53 55 54 56 #endif -
uspace/lib/ui/src/pbutton.c
r4ed00d3 rfaca61b8 39 39 #include <gfx/render.h> 40 40 #include <gfx/text.h> 41 #include <io/pos_event.h> 41 42 #include <stdlib.h> 42 43 #include <str.h> … … 408 409 } 409 410 411 /** Handle push button position event. 412 * 413 * @param pbutton Push button 414 * @param pos_event Position event 415 */ 416 void ui_pbutton_pos_event(ui_pbutton_t *pbutton, pos_event_t *event) 417 { 418 gfx_coord2_t pos; 419 420 pos.x = event->hpos; 421 pos.y = event->vpos; 422 423 if (gfx_pix_inside_rect(&pos, &pbutton->rect)) { 424 if (event->type == POS_PRESS) { 425 ui_pbutton_press(pbutton); 426 (void) ui_pbutton_paint(pbutton); 427 } 428 } 429 430 if (event->type == POS_RELEASE && pbutton->held) { 431 ui_pbutton_release(pbutton); 432 (void) ui_pbutton_paint(pbutton); 433 } 434 } 435 410 436 /** @} 411 437 */ -
uspace/lib/ui/test/pbutton.c
r4ed00d3 rfaca61b8 185 185 } 186 186 187 /** ui_pos_event() correctly translates POS_PRESS/POS_RELEASE */ 188 PCUT_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 187 230 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 188 231 { … … 214 257 tbm->alloc.off0 = 0; 215 258 tbm->alloc.pixels = calloc(sizeof(uint32_t), 216 217 259 (params->rect.p1.x - params->rect.p0.x) * 260 (params->rect.p1.y - params->rect.p0.y)); 218 261 tbm->myalloc = true; 219 262 if (tbm->alloc.pixels == NULL) { -
uspace/lib/ui/test/resource.c
r4ed00d3 rfaca61b8 114 114 tbm->alloc.off0 = 0; 115 115 tbm->alloc.pixels = calloc(sizeof(uint32_t), 116 117 116 (params->rect.p1.x - params->rect.p0.x) * 117 (params->rect.p1.y - params->rect.p0.y)); 118 118 tbm->myalloc = true; 119 119 if (tbm->alloc.pixels == NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.