Changeset d4ea1f6 in mainline
- Timestamp:
- 2022-03-21T17:38:57Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8965860c
- Parents:
- 26c90dd
- Location:
- uspace/lib/ui
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/types/ui/pbutton.h
r26c90dd rd4ea1f6 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 43 43 typedef struct ui_pbutton_cb { 44 44 void (*clicked)(ui_pbutton_t *, void *); 45 void (*down)(ui_pbutton_t *, void *); 46 void (*up)(ui_pbutton_t *, void *); 45 47 } ui_pbutton_cb_t; 46 48 -
uspace/lib/ui/include/ui/pbutton.h
r26c90dd rd4ea1f6 59 59 extern void ui_pbutton_leave(ui_pbutton_t *); 60 60 extern void ui_pbutton_clicked(ui_pbutton_t *); 61 extern void ui_pbutton_down(ui_pbutton_t *); 62 extern void ui_pbutton_up(ui_pbutton_t *); 61 63 extern ui_evclaim_t ui_pbutton_pos_event(ui_pbutton_t *, pos_event_t *); 62 64 -
uspace/lib/ui/private/scrollbar.h
r26c90dd rd4ea1f6 59 59 gfx_coord_t thumb_len; 60 60 /** Up button */ 61 struct ui_pbutton * btn_up;61 struct ui_pbutton *up_btn; 62 62 /** Down button */ 63 struct ui_pbutton * btn_down;63 struct ui_pbutton *down_btn; 64 64 /** Thumb is currently held down */ 65 65 bool thumb_held; -
uspace/lib/ui/src/pbutton.c
r26c90dd rd4ea1f6 429 429 pbutton->held = true; 430 430 (void) ui_pbutton_paint(pbutton); 431 ui_pbutton_down(pbutton); 431 432 } 432 433 … … 446 447 ui_pbutton_clicked(pbutton); 447 448 } 449 450 ui_pbutton_up(pbutton); 448 451 } 449 452 … … 476 479 } 477 480 478 /** Button was clicked.481 /** Send button clicked event. 479 482 * 480 483 * @param pbutton Push button … … 484 487 if (pbutton->cb != NULL && pbutton->cb->clicked != NULL) 485 488 pbutton->cb->clicked(pbutton, pbutton->arg); 489 } 490 491 /** Send button down event. 492 * 493 * @param pbutton Push button 494 */ 495 void ui_pbutton_down(ui_pbutton_t *pbutton) 496 { 497 if (pbutton->cb != NULL && pbutton->cb->down != NULL) 498 pbutton->cb->down(pbutton, pbutton->arg); 499 } 500 501 /** Send button up event. 502 * 503 * @param pbutton Push button 504 */ 505 void ui_pbutton_up(ui_pbutton_t *pbutton) 506 { 507 if (pbutton->cb != NULL && pbutton->cb->up != NULL) 508 pbutton->cb->up(pbutton, pbutton->arg); 486 509 } 487 510 -
uspace/lib/ui/src/scrollbar.c
r26c90dd rd4ea1f6 91 91 }; 92 92 93 static void ui_scrollbar_ btn_up_clicked(ui_pbutton_t *, void *);94 static void ui_scrollbar_ btn_down_clicked(ui_pbutton_t *, void *);93 static void ui_scrollbar_up_btn_down(ui_pbutton_t *, void *); 94 static void ui_scrollbar_down_btn_down(ui_pbutton_t *, void *); 95 95 static void ui_scrollbar_ctl_destroy(void *); 96 96 static errno_t ui_scrollbar_ctl_paint(void *); 97 97 static ui_evclaim_t ui_scrollbar_ctl_pos_event(void *, pos_event_t *); 98 98 99 ui_pbutton_cb_t ui_scrollbar_ btn_up_cb = {100 . clicked = ui_scrollbar_btn_up_clicked99 ui_pbutton_cb_t ui_scrollbar_up_btn_cb = { 100 .down = ui_scrollbar_up_btn_down 101 101 }; 102 102 103 ui_pbutton_cb_t ui_scrollbar_ btn_down_cb = {104 . clicked = ui_scrollbar_btn_down_clicked103 ui_pbutton_cb_t ui_scrollbar_down_btn_cb = { 104 .down = ui_scrollbar_down_btn_down 105 105 }; 106 106 … … 136 136 137 137 rc = ui_pbutton_create(resource, resource->textmode ? "\u25c4" : "<", 138 &scrollbar-> btn_up);139 if (rc != EOK) 140 goto error; 141 142 ui_pbutton_set_cb(scrollbar-> btn_up, &ui_scrollbar_btn_up_cb,138 &scrollbar->up_btn); 139 if (rc != EOK) 140 goto error; 141 142 ui_pbutton_set_cb(scrollbar->up_btn, &ui_scrollbar_up_btn_cb, 143 143 (void *) scrollbar); 144 144 145 145 rc = ui_pbutton_create(resource, resource->textmode ? "\u25ba" : ">", 146 &scrollbar-> btn_down);147 if (rc != EOK) 148 goto error; 149 150 ui_pbutton_set_cb(scrollbar-> btn_down, &ui_scrollbar_btn_down_cb,146 &scrollbar->down_btn); 147 if (rc != EOK) 148 goto error; 149 150 ui_pbutton_set_cb(scrollbar->down_btn, &ui_scrollbar_down_btn_cb, 151 151 (void *) scrollbar); 152 152 … … 172 172 return; 173 173 174 ui_pbutton_destroy(scrollbar-> btn_up);175 ui_pbutton_destroy(scrollbar-> btn_down);174 ui_pbutton_destroy(scrollbar->up_btn); 175 ui_pbutton_destroy(scrollbar->down_btn); 176 176 ui_control_delete(scrollbar->control); 177 177 free(scrollbar); … … 212 212 213 213 ui_scrollbar_get_geom(scrollbar, &geom); 214 ui_pbutton_set_rect(scrollbar-> btn_up, &geom.up_btn_rect);215 ui_pbutton_set_rect(scrollbar-> btn_down, &geom.down_btn_rect);214 ui_pbutton_set_rect(scrollbar->up_btn, &geom.up_btn_rect); 215 ui_pbutton_set_rect(scrollbar->down_btn, &geom.down_btn_rect); 216 216 } 217 217 … … 458 458 goto error; 459 459 460 rc = ui_pbutton_paint(scrollbar-> btn_up);461 if (rc != EOK) 462 goto error; 463 464 rc = ui_pbutton_paint(scrollbar-> btn_down);460 rc = ui_pbutton_paint(scrollbar->up_btn); 461 if (rc != EOK) 462 goto error; 463 464 rc = ui_pbutton_paint(scrollbar->down_btn); 465 465 if (rc != EOK) 466 466 goto error; … … 544 544 goto error; 545 545 546 rc = ui_pbutton_paint(scrollbar-> btn_up);547 if (rc != EOK) 548 goto error; 549 550 rc = ui_pbutton_paint(scrollbar-> btn_down);546 rc = ui_pbutton_paint(scrollbar->up_btn); 547 if (rc != EOK) 548 goto error; 549 550 rc = ui_pbutton_paint(scrollbar->down_btn); 551 551 if (rc != EOK) 552 552 goto error; … … 813 813 pos.y = event->vpos; 814 814 815 claimed = ui_pbutton_pos_event(scrollbar-> btn_up, event);815 claimed = ui_pbutton_pos_event(scrollbar->up_btn, event); 816 816 if (claimed == ui_claimed) 817 817 return ui_claimed; 818 818 819 claimed = ui_pbutton_pos_event(scrollbar-> btn_down, event);819 claimed = ui_pbutton_pos_event(scrollbar->down_btn, event); 820 820 if (claimed == ui_claimed) 821 821 return ui_claimed; … … 853 853 } 854 854 855 /** Scrollbar up button clicked.855 /** Scrollbar up button pressed. 856 856 * 857 857 * @param pbutton Up button 858 858 * @param arg Argument (ui_scrollbar_t *) 859 859 */ 860 static void ui_scrollbar_ btn_up_clicked(ui_pbutton_t *pbutton, void *arg)860 static void ui_scrollbar_up_btn_down(ui_pbutton_t *pbutton, void *arg) 861 861 { 862 862 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; … … 865 865 } 866 866 867 /** Scrollbar down button clicked.867 /** Scrollbar down button pressed. 868 868 * 869 869 * @param pbutton Down button 870 870 * @param arg Argument (ui_scrollbar_t *) 871 871 */ 872 static void ui_scrollbar_ btn_down_clicked(ui_pbutton_t *pbutton, void *arg)872 static void ui_scrollbar_down_btn_down(ui_pbutton_t *pbutton, void *arg) 873 873 { 874 874 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; -
uspace/lib/ui/test/pbutton.c
r26c90dd rd4ea1f6 63 63 64 64 static void test_pbutton_clicked(ui_pbutton_t *, void *); 65 static void test_pbutton_down(ui_pbutton_t *, void *); 66 static void test_pbutton_up(ui_pbutton_t *, void *); 65 67 66 68 static ui_pbutton_cb_t test_pbutton_cb = { 67 .clicked = test_pbutton_clicked 69 .clicked = test_pbutton_clicked, 70 .down = test_pbutton_down, 71 .up = test_pbutton_up 68 72 }; 69 73 … … 90 94 typedef struct { 91 95 bool clicked; 96 bool down; 97 bool up; 92 98 } test_cb_resp_t; 93 99 … … 225 231 } 226 232 233 /** Test ui_pbutton_down() */ 234 PCUT_TEST(down) 235 { 236 errno_t rc; 237 ui_pbutton_t *pbutton; 238 test_cb_resp_t resp; 239 240 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 241 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 242 243 /* Down with no callbacks set */ 244 ui_pbutton_clicked(pbutton); 245 246 /* Down with callback not implementing down */ 247 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL); 248 ui_pbutton_down(pbutton); 249 250 /* Down with real callback set */ 251 resp.down = false; 252 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp); 253 ui_pbutton_down(pbutton); 254 PCUT_ASSERT_TRUE(resp.down); 255 256 ui_pbutton_destroy(pbutton); 257 } 258 259 /** Test ui_pbutton_up() */ 260 PCUT_TEST(up) 261 { 262 errno_t rc; 263 ui_pbutton_t *pbutton; 264 test_cb_resp_t resp; 265 266 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 267 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 268 269 /* Up with no callbacks set */ 270 ui_pbutton_clicked(pbutton); 271 272 /* Up with callback not implementing up */ 273 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL); 274 ui_pbutton_up(pbutton); 275 276 /* Up with real callback set */ 277 resp.up = false; 278 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp); 279 ui_pbutton_up(pbutton); 280 PCUT_ASSERT_TRUE(resp.up); 281 282 ui_pbutton_destroy(pbutton); 283 } 284 227 285 /** Press and release button */ 228 286 PCUT_TEST(press_release) … … 247 305 248 306 resp.clicked = false; 307 resp.down = false; 308 resp.up = false; 249 309 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp); 250 310 … … 255 315 PCUT_ASSERT_TRUE(pbutton->held); 256 316 PCUT_ASSERT_TRUE(pbutton->inside); 317 PCUT_ASSERT_TRUE(resp.down); 318 PCUT_ASSERT_FALSE(resp.up); 257 319 PCUT_ASSERT_FALSE(resp.clicked); 258 320 … … 260 322 PCUT_ASSERT_FALSE(pbutton->held); 261 323 PCUT_ASSERT_TRUE(pbutton->inside); 324 PCUT_ASSERT_TRUE(resp.up); 262 325 PCUT_ASSERT_TRUE(resp.clicked); 263 326 … … 588 651 } 589 652 653 static void test_pbutton_down(ui_pbutton_t *pbutton, void *arg) 654 { 655 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 656 657 resp->down = true; 658 } 659 660 static void test_pbutton_up(ui_pbutton_t *pbutton, void *arg) 661 { 662 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 663 664 resp->up = true; 665 } 666 590 667 PCUT_EXPORT(pbutton); -
uspace/lib/ui/test/scrollbar.c
r26c90dd rd4ea1f6 1024 1024 event.vpos = 20; 1025 1025 claim = ui_scrollbar_pos_event(scrollbar, &event); 1026 PCUT_ASSERT_TRUE(scrollbar-> btn_up->held);1026 PCUT_ASSERT_TRUE(scrollbar->up_btn->held); 1027 1027 PCUT_ASSERT_EQUALS(ui_claimed, claim); 1028 1028 … … 1181 1181 event.vpos = 20; 1182 1182 claim = ui_scrollbar_pos_event(scrollbar, &event); 1183 PCUT_ASSERT_TRUE(scrollbar-> btn_down->held);1183 PCUT_ASSERT_TRUE(scrollbar->down_btn->held); 1184 1184 PCUT_ASSERT_EQUALS(ui_claimed, claim); 1185 1185
Note:
See TracChangeset
for help on using the changeset viewer.