Changeset dbb42c9 in mainline
- Timestamp:
- 2021-08-01T14:47:33Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1e242121
- Parents:
- 5de71df
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
r5de71df rdbb42c9 129 129 if (rc != EOK) 130 130 printf("Error changing entry text.\n"); 131 (void) ui_entry_paint(demo->entry);132 131 } else { 133 132 rc = ui_entry_set_text(demo->entry, "Cancel pressed"); 134 133 if (rc != EOK) 135 134 printf("Error changing entry text.\n"); 136 (void) ui_entry_paint(demo->entry);137 135 } 138 136 } -
uspace/lib/ui/private/entry.h
r5de71df rdbb42c9 40 40 #include <gfx/coord.h> 41 41 #include <gfx/text.h> 42 #include <stdbool.h> 42 43 43 44 /** Actual structure of text entry. … … 58 59 /** Text */ 59 60 char *text; 61 /** Current scroll position (in pixels) */ 62 gfx_coord_t scroll_pos; 60 63 /** Cursor position in the text (offset in bytes) */ 61 64 unsigned pos; … … 81 84 /** Interior rectangle */ 82 85 gfx_rect_t interior_rect; 86 /** Text rectangle */ 87 gfx_rect_t text_rect; 83 88 /** Text anchor position */ 84 89 gfx_coord2_t text_pos; 90 /** Text anchor X coordinate */ 91 gfx_coord_t anchor_x; 85 92 } ui_entry_geom_t; 86 93 … … 94 101 extern void ui_entry_activate(ui_entry_t *); 95 102 extern void ui_entry_deactivate(ui_entry_t *); 103 extern void ui_entry_scroll_update(ui_entry_t *, bool); 96 104 97 105 #endif -
uspace/lib/ui/src/entry.c
r5de71df rdbb42c9 67 67 ui_entry_cursor_width = 2, 68 68 ui_entry_sel_hpad = 0, 69 ui_entry_sel_vpad = 2 69 ui_entry_sel_vpad = 2, 70 /** Additional amount to scroll to the left after revealing cursor */ 71 ui_entry_left_scroll_margin = 30 70 72 }; 71 73 … … 156 158 { 157 159 entry->halign = halign; 160 ui_entry_scroll_update(entry, true); 161 ui_entry_paint(entry); 158 162 } 159 163 … … 186 190 entry->pos = str_size(text); 187 191 entry->sel_start = entry->pos; 192 ui_entry_scroll_update(entry, false); 193 ui_entry_paint(entry); 188 194 189 195 return EOK; … … 452 458 entry->pos = off1; 453 459 entry->sel_start = off1; 460 ui_entry_scroll_update(entry, false); 454 461 ui_entry_paint(entry); 455 462 } … … 494 501 495 502 entry->sel_start = entry->pos; 503 ui_entry_scroll_update(entry, false); 496 504 ui_entry_paint(entry); 497 505 … … 526 534 entry->sel_start = off; 527 535 536 ui_entry_scroll_update(entry, false); 528 537 ui_entry_paint(entry); 529 538 } … … 551 560 str_size(entry->text + off) + 1); 552 561 562 ui_entry_scroll_update(entry, false); 553 563 ui_entry_paint(entry); 554 564 } … … 875 885 gfx_coord_t hpad; 876 886 gfx_coord_t vpad; 877 gfx_coord_t width;878 887 ui_resource_t *res; 879 888 … … 895 904 } 896 905 897 width = gfx_text_width(res->font, entry->text); 906 geom->text_rect.p0.x = geom->interior_rect.p0.x + hpad; 907 geom->text_rect.p0.y = geom->interior_rect.p0.y + vpad; 908 geom->text_rect.p1.x = geom->interior_rect.p1.x - hpad; 909 geom->text_rect.p1.y = geom->interior_rect.p1.y - vpad; 910 911 geom->text_pos.x = geom->interior_rect.p0.x + hpad + 912 entry->scroll_pos; 913 geom->text_pos.y = geom->interior_rect.p0.y + vpad; 898 914 899 915 switch (entry->halign) { 900 916 case gfx_halign_left: 901 917 case gfx_halign_justify: 902 geom-> text_pos.x = geom->interior_rect.p0.x + hpad;918 geom->anchor_x = geom->text_rect.p0.x; 903 919 break; 904 920 case gfx_halign_center: 905 geom-> text_pos.x = (geom->interior_rect.p0.x +906 geom-> interior_rect.p1.x) / 2 - width/ 2;921 geom->anchor_x = (geom->text_rect.p0.x + 922 geom->text_rect.p1.x) / 2; 907 923 break; 908 924 case gfx_halign_right: 909 geom->text_pos.x = geom->interior_rect.p1.x - hpad - 1 - width; 910 break; 911 } 912 913 geom->text_pos.y = geom->interior_rect.p0.y + vpad; 925 geom->anchor_x = geom->text_rect.p1.x; 926 break; 927 } 914 928 } 915 929 … … 945 959 if (!shift) 946 960 entry->sel_start = entry->pos; 961 962 ui_entry_scroll_update(entry, false); 947 963 (void) ui_entry_paint(entry); 948 964 } … … 959 975 if (!shift) 960 976 entry->sel_start = entry->pos; 977 978 ui_entry_scroll_update(entry, false); 961 979 (void) ui_entry_paint(entry); 962 980 } … … 978 996 if (!shift) 979 997 entry->sel_start = entry->pos; 998 999 ui_entry_scroll_update(entry, false); 980 1000 (void) ui_entry_paint(entry); 981 1001 } … … 997 1017 if (!shift) 998 1018 entry->sel_start = entry->pos; 1019 1020 ui_entry_scroll_update(entry, false); 999 1021 (void) ui_entry_paint(entry); 1000 1022 } … … 1021 1043 } 1022 1044 1045 /** Update text entry scroll position. 1046 * 1047 * @param entry Text entry 1048 * @param realign @c true iff we should left-align short text. 1049 * This should be only used when changing text alignment, 1050 * because left-aligned text entries should not realign 1051 * the text to the left side under normal circumstances. 1052 */ 1053 void ui_entry_scroll_update(ui_entry_t *entry, bool realign) 1054 { 1055 ui_entry_geom_t geom; 1056 gfx_coord_t x; 1057 gfx_coord_t width; 1058 gfx_coord2_t tpos; 1059 gfx_coord2_t anchor; 1060 gfx_text_fmt_t fmt; 1061 ui_resource_t *res; 1062 1063 res = ui_window_get_res(entry->window); 1064 1065 ui_entry_get_geom(entry, &geom); 1066 1067 /* Compute position where cursor is currently displayed at */ 1068 x = geom.text_pos.x + ui_entry_lwidth(entry); 1069 1070 /* Is cursor off to the left? */ 1071 if (x < geom.text_rect.p0.x) { 1072 /* 1073 * Scroll to make cursor visible and put some space between it 1074 * and the left edge of the text rectangle. 1075 */ 1076 entry->scroll_pos += geom.text_rect.p0.x - x + 1077 ui_entry_left_scroll_margin; 1078 1079 /* 1080 * We don't want to scroll further than what's needed 1081 * to reveal the beginning of the text. 1082 */ 1083 if (entry->scroll_pos > 0) 1084 entry->scroll_pos = 0; 1085 } 1086 1087 /* 1088 * Is cursor off to the right? Note that the width of the cursor 1089 * is deliberately not taken into account (i.e. we only care 1090 * about the left edge of the cursor). 1091 */ 1092 if (x > geom.text_rect.p1.x) 1093 entry->scroll_pos -= x + 2 - geom.text_rect.p1.x; 1094 1095 width = gfx_text_width(res->font, entry->text); 1096 1097 if (width < geom.text_rect.p1.x - geom.text_rect.p0.x && 1098 (realign || entry->halign != gfx_halign_left)) { 1099 /* Text fits inside entry, so we need to align it */ 1100 anchor.x = geom.anchor_x; 1101 anchor.y = 0; 1102 gfx_text_fmt_init(&fmt); 1103 fmt.halign = entry->halign; 1104 gfx_text_start_pos(res->font, &anchor, &fmt, entry->text, 1105 &tpos); 1106 entry->scroll_pos = tpos.x - geom.text_rect.p0.x; 1107 } else if (geom.text_pos.x + width < geom.text_rect.p1.x && 1108 entry->halign != gfx_halign_left) { 1109 /* Text is long, unused space on the right */ 1110 entry->scroll_pos += geom.text_rect.p1.x - 1111 geom.text_pos.x - width; 1112 } 1113 } 1114 1023 1115 /** @} 1024 1116 */
Note:
See TracChangeset
for help on using the changeset viewer.