Changeset 0d1d0ea in mainline
- Timestamp:
- 2022-03-31T14:37:31Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d68239a1
- Parents:
- 7ca7215
- git-author:
- Jiri Svoboda <jiri@…> (2022-03-30 17:37:11)
- git-committer:
- Jiri Svoboda <jiri@…> (2022-03-31 14:37:31)
- Location:
- uspace/lib/ui
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/ui/paint.h
r7ca7215 r0d1d0ea 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 59 59 extern errno_t ui_paint_text_hbrace(ui_resource_t *, gfx_rect_t *, 60 60 ui_box_style_t, gfx_color_t *); 61 extern errno_t ui_paint_text_rect(ui_resource_t *, gfx_rect_t *, gfx_color_t *, 62 const char *); 61 63 extern void ui_text_fmt_init(ui_text_fmt_t *); 62 64 extern gfx_coord_t ui_text_width(gfx_font_t *, const char *); -
uspace/lib/ui/private/scrollbar.h
r7ca7215 r0d1d0ea 107 107 108 108 extern errno_t ui_scrollbar_paint_gfx(ui_scrollbar_t *); 109 extern errno_t ui_scrollbar_paint_text_horiz(ui_scrollbar_t *); 110 extern errno_t ui_scrollbar_paint_text_vert(ui_scrollbar_t *); 109 extern errno_t ui_scrollbar_paint_text(ui_scrollbar_t *); 111 110 extern void ui_scrollbar_get_geom(ui_scrollbar_t *, ui_scrollbar_geom_t *); 112 111 -
uspace/lib/ui/src/paint.c
r7ca7215 r0d1d0ea 555 555 } 556 556 557 /** Fill rectangle with text character. 558 * 559 * @param resource UI resource 560 * @param rect Rectangle 561 * @param color Color 562 * @param gchar Character to fill with 563 * @return EOK on success or an error code 564 */ 565 errno_t ui_paint_text_rect(ui_resource_t *resource, gfx_rect_t *rect, 566 gfx_color_t *color, const char *gchar) 567 { 568 gfx_coord2_t pos; 569 gfx_text_fmt_t fmt; 570 gfx_rect_t srect; 571 gfx_coord_t w, i; 572 char *buf; 573 size_t gcharsz; 574 errno_t rc; 575 576 gfx_rect_points_sort(rect, &srect); 577 578 gfx_text_fmt_init(&fmt); 579 fmt.font = resource->font; 580 fmt.color = color; 581 fmt.halign = gfx_halign_left; 582 fmt.valign = gfx_valign_top; 583 584 w = srect.p1.x - srect.p0.x; 585 if (w == 0) 586 return EOK; 587 588 gcharsz = str_size(gchar); 589 590 buf = malloc(w * gcharsz + 1); 591 if (buf == NULL) 592 return ENOMEM; 593 594 for (i = 0; i < w; i++) 595 str_cpy(buf + i * gcharsz, (w - i) * gcharsz + 1, gchar); 596 buf[w * gcharsz] = '\0'; 597 598 pos.x = srect.p0.x; 599 for (pos.y = srect.p0.y; pos.y < srect.p1.y; pos.y++) { 600 rc = gfx_puttext(&pos, &fmt, buf); 601 if (rc != EOK) 602 goto error; 603 } 604 605 free(buf); 606 return EOK; 607 error: 608 free(buf); 609 return rc; 610 } 611 557 612 /** Initialize UI text formatting structure. 558 613 * -
uspace/lib/ui/src/scrollbar.c
r7ca7215 r0d1d0ea 526 526 } 527 527 528 /** Paint horizontalscrollbar in text mode.528 /** Paint scrollbar in text mode. 529 529 * 530 530 * @param scrollbar Scrollbar 531 531 * @return EOK on success or an error code 532 532 */ 533 errno_t ui_scrollbar_paint_text _horiz(ui_scrollbar_t *scrollbar)533 errno_t ui_scrollbar_paint_text(ui_scrollbar_t *scrollbar) 534 534 { 535 535 ui_resource_t *resource; 536 gfx_coord2_t pos; 537 gfx_text_fmt_t fmt; 538 gfx_coord_t w, i; 539 char *buf; 540 const char *gchar; 541 size_t gcharsz; 536 ui_scrollbar_geom_t geom; 542 537 errno_t rc; 543 538 544 539 resource = ui_window_get_res(scrollbar->window); 540 ui_scrollbar_get_geom(scrollbar, &geom); 545 541 546 542 /* Paint scrollbar through */ 547 543 548 pos = scrollbar->rect.p0; 549 pos.x += ui_scrollbar_btn_len_text; 550 551 gfx_text_fmt_init(&fmt); 552 fmt.font = resource->font; 553 fmt.color = resource->sbar_through_color; 554 fmt.halign = gfx_halign_left; 555 fmt.valign = gfx_valign_top; 556 557 w = scrollbar->rect.p1.x - scrollbar->rect.p0.x - 558 2 * ui_scrollbar_btn_len_text; 559 assert(w >= 0); 560 if (w < 0) 561 return EINVAL; 562 563 gchar = "\u2592"; 564 gcharsz = str_size(gchar); 565 566 buf = malloc(w * gcharsz + 1); 567 if (buf == NULL) 568 return ENOMEM; 569 570 for (i = 0; i < w; i++) 571 str_cpy(buf + i * gcharsz, (w - i) * gcharsz + 1, gchar); 572 buf[w * gcharsz] = '\0'; 573 574 rc = gfx_puttext(&pos, &fmt, buf); 575 free(buf); 544 rc = ui_paint_text_rect(resource, &geom.through_rect, 545 resource->sbar_through_color, "\u2592"); 576 546 if (rc != EOK) 577 547 goto error; … … 579 549 /* Paint scrollbar thumb */ 580 550 581 pos.x += scrollbar->pos; 582 583 gchar = "\u25a0"; 584 gcharsz = str_size(gchar); 585 w = scrollbar->thumb_len; 586 587 buf = malloc(w * gcharsz + 1); 588 if (buf == NULL) 589 return ENOMEM; 590 591 for (i = 0; i < w; i++) 592 str_cpy(buf + i * gcharsz, (w - i) * gcharsz + 1, gchar); 593 buf[w * gcharsz] = '\0'; 594 595 rc = gfx_puttext(&pos, &fmt, buf); 596 free(buf); 597 if (rc != EOK) 598 goto error; 551 rc = ui_paint_text_rect(resource, &geom.thumb_rect, 552 resource->sbar_through_color, "\u25a0"); 553 if (rc != EOK) 554 goto error; 555 556 /* Paint buttons */ 599 557 600 558 rc = ui_pbutton_paint(scrollbar->up_btn); … … 615 573 } 616 574 617 /** Paint vertical scrollbar in text mode.575 /** Paint scrollbar. 618 576 * 619 577 * @param scrollbar Scrollbar 620 578 * @return EOK on success or an error code 621 579 */ 622 errno_t ui_scrollbar_paint_text_vert(ui_scrollbar_t *scrollbar)623 {624 ui_resource_t *resource;625 ui_scrollbar_geom_t geom;626 gfx_coord2_t pos;627 gfx_text_fmt_t fmt;628 errno_t rc;629 630 resource = ui_window_get_res(scrollbar->window);631 ui_scrollbar_get_geom(scrollbar, &geom);632 633 /* Paint scrollbar through */634 635 gfx_text_fmt_init(&fmt);636 fmt.font = resource->font;637 fmt.color = resource->sbar_through_color;638 fmt.halign = gfx_halign_left;639 fmt.valign = gfx_valign_top;640 641 pos.x = scrollbar->rect.p0.x;642 for (pos.y = geom.through_rect.p0.y; pos.y < geom.through_rect.p1.y;643 pos.y++) {644 rc = gfx_puttext(&pos, &fmt, "\u2592");645 if (rc != EOK)646 goto error;647 }648 649 /* Paint scrollbar thumb */650 651 pos.x = geom.thumb_rect.p0.x;652 for (pos.y = geom.thumb_rect.p0.y; pos.y < geom.thumb_rect.p1.y;653 pos.y++) {654 rc = gfx_puttext(&pos, &fmt, "\u25a0");655 if (rc != EOK)656 goto error;657 }658 659 rc = ui_pbutton_paint(scrollbar->up_btn);660 if (rc != EOK)661 goto error;662 663 rc = ui_pbutton_paint(scrollbar->down_btn);664 if (rc != EOK)665 goto error;666 667 rc = gfx_update(resource->gc);668 if (rc != EOK)669 goto error;670 671 return EOK;672 error:673 return rc;674 }675 676 /** Paint scrollbar.677 *678 * @param scrollbar Scrollbar679 * @return EOK on success or an error code680 */681 580 errno_t ui_scrollbar_paint(ui_scrollbar_t *scrollbar) 682 581 { … … 684 583 685 584 if (resource->textmode) { 686 if (scrollbar->dir == ui_sbd_horiz) 687 return ui_scrollbar_paint_text_horiz(scrollbar); 688 else 689 return ui_scrollbar_paint_text_vert(scrollbar); 585 return ui_scrollbar_paint_text(scrollbar); 690 586 } else { 691 587 return ui_scrollbar_paint_gfx(scrollbar); -
uspace/lib/ui/test/paint.c
r7ca7215 r0d1d0ea 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 313 313 } 314 314 315 /** Paint text rectangle */ 316 PCUT_TEST(text_rect) 317 { 318 errno_t rc; 319 gfx_context_t *gc = NULL; 320 ui_resource_t *resource = NULL; 321 gfx_color_t *color = NULL; 322 test_gc_t tgc; 323 gfx_rect_t rect; 324 325 memset(&tgc, 0, sizeof(tgc)); 326 rc = gfx_context_new(&ops, &tgc, &gc); 327 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 328 329 rc = ui_resource_create(gc, false, &resource); 330 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 331 PCUT_ASSERT_NOT_NULL(resource); 332 333 rc = gfx_color_new_rgb_i16(1, 2, 3, &color); 334 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 335 336 rect.p0.x = 10; 337 rect.p0.y = 20; 338 rect.p1.x = 30; 339 rect.p1.y = 40; 340 341 /* Paint text box */ 342 rc = ui_paint_text_rect(resource, &rect, color, "A"); 343 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 344 345 gfx_color_delete(color); 346 ui_resource_destroy(resource); 347 rc = gfx_context_delete(gc); 348 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 349 } 350 315 351 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect) 316 352 { -
uspace/lib/ui/test/scrollbar.c
r7ca7215 r0d1d0ea 206 206 } 207 207 208 /** Paint horizontalscrollbar in text mode */208 /** Paint scrollbar in text mode */ 209 209 PCUT_TEST(paint_text_horiz) 210 210 { … … 235 235 ui_scrollbar_set_rect(scrollbar, &rect); 236 236 237 rc = ui_scrollbar_paint_text_horiz(scrollbar); 238 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 239 240 ui_scrollbar_destroy(scrollbar); 241 ui_window_destroy(window); 242 ui_destroy(ui); 243 } 244 245 /** Paint vertical scrollbar in text mode */ 246 PCUT_TEST(paint_text_vert) 247 { 248 ui_t *ui = NULL; 249 ui_window_t *window = NULL; 250 ui_wnd_params_t params; 251 ui_scrollbar_t *scrollbar; 252 gfx_rect_t rect; 253 errno_t rc; 254 255 rc = ui_create_disp(NULL, &ui); 256 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 257 258 ui_wnd_params_init(¶ms); 259 params.caption = "Hello"; 260 261 rc = ui_window_create(ui, ¶ms, &window); 262 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 263 PCUT_ASSERT_NOT_NULL(window); 264 265 rc = ui_scrollbar_create(ui, window, ui_sbd_vert, &scrollbar); 266 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 267 268 rect.p0.x = 1; 269 rect.p0.y = 1; 270 rect.p1.x = 2; 271 rect.p1.y = 10; 272 ui_scrollbar_set_rect(scrollbar, &rect); 273 274 rc = ui_scrollbar_paint_text_vert(scrollbar); 237 rc = ui_scrollbar_paint_text(scrollbar); 275 238 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 276 239
Note:
See TracChangeset
for help on using the changeset viewer.