Changeset 81ec7e1 in mainline
- Timestamp:
- 2021-08-31T08:57:24Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b79c91cc
- Parents:
- ff6e91b
- git-author:
- Jiri Svoboda <jiri@…> (2021-08-30 20:57:08)
- git-committer:
- Jiri Svoboda <jiri@…> (2021-08-31 08:57:24)
- Location:
- uspace/lib/ui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/types/ui/paint.h
rff6e91b r81ec7e1 66 66 } ui_box_chars_t; 67 67 68 /** Horizontal brace characters for a particular box style. */ 69 typedef struct { 70 const char *start; 71 const char *middle; 72 const char *end; 73 } ui_brace_chars_t; 74 68 75 /** Box style */ 69 76 typedef enum { -
uspace/lib/ui/include/ui/paint.h
rff6e91b r81ec7e1 57 57 extern errno_t ui_paint_text_box(ui_resource_t *, gfx_rect_t *, 58 58 ui_box_style_t, gfx_color_t *); 59 extern errno_t ui_paint_text_hbrace(ui_resource_t *, gfx_rect_t *, 60 ui_box_style_t, gfx_color_t *); 59 61 60 62 #endif -
uspace/lib/ui/src/menuentry.c
rff6e91b r81ec7e1 349 349 350 350 if (mentry->separator) { 351 rect.p0 = geom.caption_pos; 352 rect.p1.x = geom.shortcut_pos.x; 353 rect.p1.y = rect.p0.y + 2; 354 rc = ui_paint_bevel(res->gc, &rect, res->wnd_shadow_color, 355 res->wnd_highlight_color, 1, NULL); 356 if (rc != EOK) 357 goto error; 351 if (res->textmode) { 352 rect = geom.outer_rect; 353 rect.p0.x -= 1; 354 rect.p1.x += 1; 355 356 rc = ui_paint_text_hbrace(res, &rect, ui_box_single, 357 res->wnd_face_color); 358 if (rc != EOK) 359 goto error; 360 } else { 361 rect.p0 = geom.caption_pos; 362 rect.p1.x = geom.shortcut_pos.x; 363 rect.p1.y = rect.p0.y + 2; 364 rc = ui_paint_bevel(res->gc, &rect, res->wnd_shadow_color, 365 res->wnd_highlight_color, 1, NULL); 366 if (rc != EOK) 367 goto error; 368 } 358 369 } 359 370 -
uspace/lib/ui/src/paint.c
rff6e91b r81ec7e1 62 62 }; 63 63 64 /** Single horizontal brace characters */ 65 static ui_brace_chars_t single_hbrace_chars = { 66 .start = "\u251c", 67 .middle = "\u2500", 68 .end = "\u2524" 69 }; 70 71 /** Double horizontal brace characters */ 72 static ui_brace_chars_t double_hbrace_chars = { 73 .start = "\u2560", 74 .middle = "\u2550", 75 .end = "\u2563" 76 }; 77 64 78 /** Paint bevel. 65 79 * … … 462 476 } 463 477 478 /** Paint a text horizontal brace. 479 * 480 * @param resource UI resource 481 * @param rect Rectangle inside which to paint the brace (height should 482 * be 1). 483 * @param style Box style 484 * @param color Color 485 * @return EOK on success or an error code 486 */ 487 errno_t ui_paint_text_hbrace(ui_resource_t *resource, gfx_rect_t *rect, 488 ui_box_style_t style, gfx_color_t *color) 489 { 490 errno_t rc; 491 gfx_text_fmt_t fmt; 492 gfx_rect_t srect; 493 gfx_coord2_t pos; 494 gfx_coord2_t dim; 495 size_t bufsz; 496 size_t off; 497 int i; 498 char *str = NULL; 499 ui_brace_chars_t *hbc = NULL; 500 501 gfx_rect_points_sort(rect, &srect); 502 gfx_rect_dims(&srect, &dim); 503 504 /* Is rectangle large enough to hold brace? */ 505 if (dim.x < 2 || dim.y < 1) 506 return EOK; 507 508 switch (style) { 509 case ui_box_single: 510 hbc = &single_hbrace_chars; 511 break; 512 case ui_box_double: 513 hbc = &double_hbrace_chars; 514 break; 515 } 516 517 if (hbc == NULL) 518 return EINVAL; 519 520 gfx_text_fmt_init(&fmt); 521 fmt.color = color; 522 523 bufsz = str_size(hbc->start) + 524 str_size(hbc->middle) * (dim.x - 2) + 525 str_size(hbc->end) + 1; 526 527 str = malloc(bufsz); 528 if (str == NULL) 529 return ENOMEM; 530 531 str_cpy(str, bufsz, hbc->start); 532 off = str_size(hbc->start); 533 534 for (i = 1; i < dim.x - 1; i++) { 535 str_cpy(str + off, bufsz - off, hbc->middle); 536 off += str_size(hbc->middle); 537 } 538 539 str_cpy(str + off, bufsz - off, hbc->end); 540 off += str_size(hbc->end); 541 str[off] = '\0'; 542 543 pos = rect->p0; 544 rc = gfx_puttext(resource->font, &pos, &fmt, str); 545 if (rc != EOK) 546 goto error; 547 548 free(str); 549 return EOK; 550 error: 551 if (str != NULL) 552 free(str); 553 return rc; 554 } 555 464 556 /** @} 465 557 */ -
uspace/lib/ui/test/paint.c
rff6e91b r81ec7e1 277 277 } 278 278 279 /** Paint text horizontal brace */ 280 PCUT_TEST(text_hbrace) 281 { 282 errno_t rc; 283 gfx_context_t *gc = NULL; 284 ui_resource_t *resource = NULL; 285 gfx_color_t *color = NULL; 286 test_gc_t tgc; 287 gfx_rect_t rect; 288 289 memset(&tgc, 0, sizeof(tgc)); 290 rc = gfx_context_new(&ops, &tgc, &gc); 291 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 292 293 rc = ui_resource_create(gc, false, &resource); 294 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 295 PCUT_ASSERT_NOT_NULL(resource); 296 297 rc = gfx_color_new_rgb_i16(1, 2, 3, &color); 298 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 299 300 rect.p0.x = 10; 301 rect.p0.y = 20; 302 rect.p1.x = 30; 303 rect.p1.y = 40; 304 305 /* Paint text horizontal brace */ 306 rc = ui_paint_text_hbrace(resource, &rect, ui_box_single, 307 color); 308 309 gfx_color_delete(color); 310 ui_resource_destroy(resource); 311 rc = gfx_context_delete(gc); 312 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 313 } 314 279 315 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect) 280 316 {
Note:
See TracChangeset
for help on using the changeset viewer.