Changeset d68239a1 in mainline for uspace/lib/ui/src
- Timestamp:
- 2022-04-04T14:48:41Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 86fff971
- Parents:
- 0d1d0ea
- git-author:
- Jiri Svoboda <jiri@…> (2022-04-03 17:48:17)
- git-committer:
- Jiri Svoboda <jiri@…> (2022-04-04 14:48:41)
- Location:
- uspace/lib/ui/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/paint.c
r0d1d0ea rd68239a1 360 360 } 361 361 362 /** Paint upward pointing triangle. 363 * 364 * @param gc Graphic context 365 * @param pos Center position 366 * @param n Length of triangle side 367 */ 368 errno_t ui_paint_up_triangle(gfx_context_t *gc, gfx_coord2_t *pos, 369 gfx_coord_t n) 370 { 371 gfx_coord_t i; 372 errno_t rc; 373 gfx_rect_t rect; 374 375 for (i = 0; i < n; i++) { 376 rect.p0.x = pos->x - i; 377 rect.p0.y = pos->y - n / 2 + i; 378 rect.p1.x = pos->x + i + 1; 379 rect.p1.y = pos->y - n / 2 + i + 1; 380 rc = gfx_fill_rect(gc, &rect); 381 if (rc != EOK) 382 return rc; 383 } 384 385 return EOK; 386 } 387 388 /** Paint downward pointing triangle. 389 * 390 * @param gc Graphic context 391 * @param pos Center position 392 * @param n Length of triangle side 393 */ 394 errno_t ui_paint_down_triangle(gfx_context_t *gc, gfx_coord2_t *pos, 395 gfx_coord_t n) 396 { 397 gfx_coord_t i; 398 errno_t rc; 399 gfx_rect_t rect; 400 401 for (i = 0; i < n; i++) { 402 rect.p0.x = pos->x - i; 403 rect.p0.y = pos->y + n / 2 - i; 404 rect.p1.x = pos->x + i + 1; 405 rect.p1.y = pos->y + n / 2 - i + 1; 406 rc = gfx_fill_rect(gc, &rect); 407 if (rc != EOK) 408 return rc; 409 } 410 411 return EOK; 412 } 413 414 /** Paint left pointing triangle. 415 * 416 * @param gc Graphic context 417 * @param pos Center position 418 * @param n Length of triangle side 419 */ 420 errno_t ui_paint_left_triangle(gfx_context_t *gc, gfx_coord2_t *pos, 421 gfx_coord_t n) 422 { 423 gfx_coord_t i; 424 errno_t rc; 425 gfx_rect_t rect; 426 427 for (i = 0; i < n; i++) { 428 rect.p0.x = pos->x - n / 2 + i; 429 rect.p0.y = pos->y - i; 430 rect.p1.x = pos->x - n / 2 + i + 1; 431 rect.p1.y = pos->y + i + 1; 432 rc = gfx_fill_rect(gc, &rect); 433 if (rc != EOK) 434 return rc; 435 } 436 437 return EOK; 438 } 439 440 /** Paint right pointing triangle. 441 * 442 * @param gc Graphic context 443 * @param pos Center position 444 * @param n Length of triangle side 445 */ 446 errno_t ui_paint_right_triangle(gfx_context_t *gc, gfx_coord2_t *pos, 447 gfx_coord_t n) 448 { 449 gfx_coord_t i; 450 errno_t rc; 451 gfx_rect_t rect; 452 453 for (i = 0; i < n; i++) { 454 rect.p0.x = pos->x + n / 2 - i; 455 rect.p0.y = pos->y - i; 456 rect.p1.x = pos->x + n / 2 - i + 1; 457 rect.p1.y = pos->y + i + 1; 458 rc = gfx_fill_rect(gc, &rect); 459 if (rc != EOK) 460 return rc; 461 } 462 463 return EOK; 464 } 465 362 466 /** Paint a text box. 363 467 * -
uspace/lib/ui/src/pbutton.c
r0d1d0ea rd68239a1 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 32 32 /** 33 33 * @file Push button 34 * 35 * Push button either uses text as decoration, or it can use a caller-provided 36 * function to paint the decoration. 34 37 */ 35 38 … … 136 139 } 137 140 141 /** Set push button decoration ops. 142 * 143 * @param pbutton Push button 144 * @param ops Push button decoration callbacks 145 * @param arg Decoration ops argument 146 */ 147 void ui_pbutton_set_decor_ops(ui_pbutton_t *pbutton, 148 ui_pbutton_decor_ops_t *ops, void *arg) 149 { 150 pbutton->decor_ops = ops; 151 pbutton->decor_arg = arg; 152 } 153 138 154 /** Set button rectangle. 139 155 * … … 306 322 } 307 323 308 gfx_text_fmt_init(&fmt); 309 fmt.font = pbutton->res->font; 310 fmt.color = pbutton->res->btn_text_color; 311 fmt.halign = gfx_halign_center; 312 fmt.valign = gfx_valign_center; 313 314 rc = gfx_puttext(&pos, &fmt, pbutton->caption); 315 if (rc != EOK) 316 goto error; 324 if (pbutton->decor_ops != NULL && pbutton->decor_ops->paint != NULL) { 325 /* Custom decoration */ 326 rc = pbutton->decor_ops->paint(pbutton, pbutton->decor_arg, 327 &pos); 328 if (rc != EOK) 329 goto error; 330 } else { 331 /* Text decoration */ 332 gfx_text_fmt_init(&fmt); 333 fmt.font = pbutton->res->font; 334 fmt.color = pbutton->res->btn_text_color; 335 fmt.halign = gfx_halign_center; 336 fmt.valign = gfx_valign_center; 337 338 rc = gfx_puttext(&pos, &fmt, pbutton->caption); 339 if (rc != EOK) 340 goto error; 341 } 317 342 318 343 rc = ui_pbutton_paint_frame(pbutton); -
uspace/lib/ui/src/scrollbar.c
r0d1d0ea rd68239a1 78 78 enum { 79 79 /** Scrollbar button width */ 80 ui_scrollbar_btn_len = 2 0,80 ui_scrollbar_btn_len = 21, 81 81 /** Scrollbar button width in text mode */ 82 82 ui_scrollbar_btn_len_text = 1, … … 86 86 ui_scrollbar_thumb_bevel_width = 2, 87 87 /** Scrollbar default thumb length */ 88 ui_scrollbar_def_thumb_len = 2 0,88 ui_scrollbar_def_thumb_len = 21, 89 89 /** Scrollbar default thumb length in text mode */ 90 90 ui_scrollbar_def_thumb_len_text = 1, … … 97 97 static void ui_scrollbar_up_btn_down(ui_pbutton_t *, void *); 98 98 static void ui_scrollbar_up_btn_up(ui_pbutton_t *, void *); 99 static errno_t ui_scrollbar_up_btn_decor_paint(ui_pbutton_t *, void *, 100 gfx_coord2_t *); 101 static errno_t ui_scrollbar_down_btn_decor_paint(ui_pbutton_t *, void *, 102 gfx_coord2_t *); 99 103 static void ui_scrollbar_down_btn_down(ui_pbutton_t *, void *); 100 104 static void ui_scrollbar_down_btn_up(ui_pbutton_t *, void *); … … 108 112 }; 109 113 114 static ui_pbutton_decor_ops_t ui_scrollbar_up_btn_decor_ops = { 115 .paint = ui_scrollbar_up_btn_decor_paint 116 }; 117 110 118 static ui_pbutton_cb_t ui_scrollbar_down_btn_cb = { 111 119 .down = ui_scrollbar_down_btn_down, 112 120 .up = ui_scrollbar_down_btn_up 121 }; 122 123 static ui_pbutton_decor_ops_t ui_scrollbar_down_btn_decor_ops = { 124 .paint = ui_scrollbar_down_btn_decor_paint 113 125 }; 114 126 … … 188 200 189 201 ui_pbutton_set_cb(scrollbar->up_btn, &ui_scrollbar_up_btn_cb, 190 (void *) scrollbar); 202 scrollbar); 203 204 ui_pbutton_set_decor_ops(scrollbar->up_btn, 205 &ui_scrollbar_up_btn_decor_ops, (void *) scrollbar); 191 206 192 207 rc = ui_pbutton_create(resource, down_text, &scrollbar->down_btn); … … 196 211 ui_pbutton_set_cb(scrollbar->down_btn, &ui_scrollbar_down_btn_cb, 197 212 (void *) scrollbar); 213 214 ui_pbutton_set_decor_ops(scrollbar->down_btn, 215 &ui_scrollbar_down_btn_decor_ops, (void *) scrollbar); 198 216 199 217 scrollbar->thumb_len = resource->textmode ? … … 961 979 } 962 980 981 /** Paint up button decoration. 982 * 983 * @param pbutton Push button 984 * @param arg Argument (ui_scrollbar_t *) 985 * @param pos Center position 986 */ 987 static errno_t ui_scrollbar_up_btn_decor_paint(ui_pbutton_t *pbutton, 988 void *arg, gfx_coord2_t *pos) 989 { 990 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 991 errno_t rc; 992 993 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_text_color); 994 if (rc != EOK) 995 return rc; 996 997 if (scrollbar->dir == ui_sbd_horiz) 998 return ui_paint_left_triangle(pbutton->res->gc, pos, 5); 999 else 1000 return ui_paint_up_triangle(pbutton->res->gc, pos, 5); 1001 } 1002 1003 /** Paint down button decoration. 1004 * 1005 * @param pbutton Push button 1006 * @param arg Argument (ui_scrollbar_t *) 1007 * @param pos Center position 1008 */ 1009 static errno_t ui_scrollbar_down_btn_decor_paint(ui_pbutton_t *pbutton, 1010 void *arg, gfx_coord2_t *pos) 1011 { 1012 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 1013 errno_t rc; 1014 1015 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_text_color); 1016 if (rc != EOK) 1017 return rc; 1018 1019 if (scrollbar->dir == ui_sbd_horiz) 1020 return ui_paint_right_triangle(pbutton->res->gc, pos, 5); 1021 else 1022 return ui_paint_down_triangle(pbutton->res->gc, pos, 5); 1023 } 1024 963 1025 /** Scrollbar down button pressed. 964 1026 *
Note:
See TracChangeset
for help on using the changeset viewer.