Changeset 81ec7e1 in mainline for uspace/lib/ui/src/paint.c
- Timestamp:
- 2021-08-31T08:57:24Z (4 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 */
Note:
See TracChangeset
for help on using the changeset viewer.