Changeset d68239a1 in mainline
- 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
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
r0d1d0ea rd68239a1 1088 1088 rect.p0.y = 340; 1089 1089 rect.p1.x = 220; 1090 rect.p1.y = 36 2;1090 rect.p1.y = 363; 1091 1091 } 1092 1092 … … 1119 1119 rect.p0.x = 220; 1120 1120 rect.p0.y = 53; 1121 rect.p1.x = 24 2;1121 rect.p1.x = 243; 1122 1122 rect.p1.y = 340; 1123 1123 } -
uspace/lib/ui/include/types/ui/pbutton.h
r0d1d0ea rd68239a1 37 37 #define _UI_TYPES_PBUTTON_H 38 38 39 #include <errno.h> 40 #include <gfx/coord.h> 41 39 42 struct ui_pbutton; 40 43 typedef struct ui_pbutton ui_pbutton_t; … … 47 50 } ui_pbutton_cb_t; 48 51 52 /** Push button decoration ops */ 53 typedef struct ui_pbutton_decor_ops { 54 errno_t (*paint)(ui_pbutton_t *, void *, gfx_coord2_t *); 55 } ui_pbutton_decor_ops_t; 56 49 57 #endif 50 58 -
uspace/lib/ui/include/ui/paint.h
r0d1d0ea rd68239a1 55 55 extern errno_t ui_paint_filled_circle(gfx_context_t *, gfx_coord2_t *, 56 56 gfx_coord_t, ui_fcircle_part_t); 57 extern errno_t ui_paint_up_triangle(gfx_context_t *, gfx_coord2_t *, 58 gfx_coord_t); 59 extern errno_t ui_paint_down_triangle(gfx_context_t *, gfx_coord2_t *, 60 gfx_coord_t); 61 extern errno_t ui_paint_left_triangle(gfx_context_t *, gfx_coord2_t *, 62 gfx_coord_t); 63 extern errno_t ui_paint_right_triangle(gfx_context_t *, gfx_coord2_t *, 64 gfx_coord_t); 57 65 extern errno_t ui_paint_text_box(ui_resource_t *, gfx_rect_t *, 58 66 ui_box_style_t, gfx_color_t *); -
uspace/lib/ui/include/ui/pbutton.h
r0d1d0ea rd68239a1 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 51 51 extern ui_control_t *ui_pbutton_ctl(ui_pbutton_t *); 52 52 extern void ui_pbutton_set_cb(ui_pbutton_t *, ui_pbutton_cb_t *, void *); 53 extern void ui_pbutton_set_decor_ops(ui_pbutton_t *, ui_pbutton_decor_ops_t *, 54 void *); 53 55 extern void ui_pbutton_set_rect(ui_pbutton_t *, gfx_rect_t *); 54 56 extern void ui_pbutton_set_default(ui_pbutton_t *, bool); -
uspace/lib/ui/private/pbutton.h
r0d1d0ea rd68239a1 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 54 54 /** Callback argument */ 55 55 void *arg; 56 /** Custom decoration ops or @c NULL */ 57 struct ui_pbutton_decor_ops *decor_ops; 58 /** Decoration argument */ 59 void *decor_arg; 56 60 /** Push button rectangle */ 57 61 gfx_rect_t rect; -
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 * -
uspace/lib/ui/test/paint.c
r0d1d0ea rd68239a1 225 225 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 226 226 227 center.x = 0; 228 center.y = 0; 229 227 230 /* Paint filled circle / upper-left half */ 228 231 rc = ui_paint_filled_circle(gc, ¢er, 10, ui_fcircle_upleft); … … 235 238 /* Paint entire filled circle */ 236 239 rc = ui_paint_filled_circle(gc, ¢er, 10, ui_fcircle_entire); 240 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 241 242 rc = gfx_context_delete(gc); 243 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 244 } 245 246 /** Paint up pointing triangle */ 247 PCUT_TEST(up_triangle) 248 { 249 errno_t rc; 250 gfx_context_t *gc = NULL; 251 test_gc_t tgc; 252 gfx_coord2_t center; 253 254 memset(&tgc, 0, sizeof(tgc)); 255 rc = gfx_context_new(&ops, &tgc, &gc); 256 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 257 258 center.x = 0; 259 center.y = 0; 260 261 rc = ui_paint_up_triangle(gc, ¢er, 5); 262 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 263 264 rc = gfx_context_delete(gc); 265 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 266 } 267 268 /** Paint down pointing triangle */ 269 PCUT_TEST(down_triangle) 270 { 271 errno_t rc; 272 gfx_context_t *gc = NULL; 273 test_gc_t tgc; 274 gfx_coord2_t center; 275 276 memset(&tgc, 0, sizeof(tgc)); 277 rc = gfx_context_new(&ops, &tgc, &gc); 278 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 279 280 center.x = 0; 281 center.y = 0; 282 283 rc = ui_paint_down_triangle(gc, ¢er, 5); 284 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 285 286 rc = gfx_context_delete(gc); 287 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 288 } 289 290 /** Paint left pointing triangle */ 291 PCUT_TEST(left_triangle) 292 { 293 errno_t rc; 294 gfx_context_t *gc = NULL; 295 test_gc_t tgc; 296 gfx_coord2_t center; 297 298 memset(&tgc, 0, sizeof(tgc)); 299 rc = gfx_context_new(&ops, &tgc, &gc); 300 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 301 302 center.x = 0; 303 center.y = 0; 304 305 rc = ui_paint_left_triangle(gc, ¢er, 5); 306 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 307 308 rc = gfx_context_delete(gc); 309 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 310 } 311 312 /** Paint right pointing triangle */ 313 PCUT_TEST(right_triangle) 314 { 315 errno_t rc; 316 gfx_context_t *gc = NULL; 317 test_gc_t tgc; 318 gfx_coord2_t center; 319 320 memset(&tgc, 0, sizeof(tgc)); 321 rc = gfx_context_new(&ops, &tgc, &gc); 322 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 323 324 center.x = 0; 325 center.y = 0; 326 327 rc = ui_paint_right_triangle(gc, ¢er, 5); 237 328 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 238 329 -
uspace/lib/ui/test/scrollbar.c
r0d1d0ea rd68239a1 319 319 320 320 /* Total length minus buttons */ 321 PCUT_ASSERT_INT_EQUALS(110 - 10 - 2 * 2 0, length);321 PCUT_ASSERT_INT_EQUALS(110 - 10 - 2 * 21, length); 322 322 323 323 ui_scrollbar_destroy(scrollbar); … … 361 361 362 362 /* Total length minus buttons minus default thumb length */ 363 PCUT_ASSERT_INT_EQUALS(110 - 10 - 2 * 2 0 - 20, length);363 PCUT_ASSERT_INT_EQUALS(110 - 10 - 2 * 21 - 21, length); 364 364 365 365 ui_scrollbar_destroy(scrollbar); … … 492 492 ui_scrollbar_set_pos(scrollbar, 42); 493 493 pos = ui_scrollbar_get_pos(scrollbar); 494 /* The value is clipped to the maximum possible position ( 40) */495 PCUT_ASSERT_INT_EQUALS( 40, pos);494 /* The value is clipped to the maximum possible position (37) */ 495 PCUT_ASSERT_INT_EQUALS(37, pos); 496 496 497 497 ui_scrollbar_destroy(scrollbar);
Note:
See TracChangeset
for help on using the changeset viewer.