Changes in uspace/lib/ui/src/entry.c [a106037:b987eb4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/entry.c
ra106037 rb987eb4 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 … … 187 191 entry->sel_start = entry->pos; 188 192 193 ui_entry_scroll_update(entry, false); 194 ui_entry_paint(entry); 195 189 196 return EOK; 197 } 198 199 /** Get entry text. 200 * 201 * @return Pointer to entry text. 202 */ 203 const char *ui_entry_get_text(ui_entry_t *entry) 204 { 205 return entry->text; 190 206 } 191 207 … … 298 314 299 315 gfx_text_fmt_init(&fmt); 316 fmt.font = res->font; 300 317 fmt.color = res->entry_fg_color; 301 318 fmt.halign = gfx_halign_left; … … 313 330 entry->text[off1] = '\0'; 314 331 315 rc = gfx_puttext( res->font,&pos, &fmt, entry->text);332 rc = gfx_puttext(&pos, &fmt, entry->text); 316 333 if (rc != EOK) { 317 334 (void) gfx_set_clip_rect(res->gc, NULL); … … 319 336 } 320 337 321 gfx_text_cont( res->font,&pos, &fmt, entry->text, &cpos, &cfmt);338 gfx_text_cont(&pos, &fmt, entry->text, &cpos, &cfmt); 322 339 entry->text[off1] = c; 323 340 … … 327 344 c = entry->text[off2]; 328 345 entry->text[off2] = '\0'; 329 cfmt.color = res->entry_ bg_color;330 331 gfx_text_rect( res->font,&cpos, &cfmt, entry->text + off1, &sel);346 cfmt.color = res->entry_sel_text_fg_color; 347 348 gfx_text_rect(&cpos, &cfmt, entry->text + off1, &sel); 332 349 sel.p0.x -= ui_entry_sel_hpad; 333 350 sel.p0.y -= ui_entry_sel_vpad; … … 335 352 sel.p1.y += ui_entry_sel_vpad; 336 353 337 rc = gfx_set_color(res->gc, res->entry_ fg_color);354 rc = gfx_set_color(res->gc, res->entry_sel_text_bg_color); 338 355 if (rc != EOK) 339 356 goto error; … … 343 360 goto error; 344 361 345 rc = gfx_puttext( res->font,&cpos, &cfmt, entry->text + off1);362 rc = gfx_puttext(&cpos, &cfmt, entry->text + off1); 346 363 if (rc != EOK) { 347 364 (void) gfx_set_clip_rect(res->gc, NULL); … … 349 366 } 350 367 351 gfx_text_cont(res->font, &cpos, &cfmt, entry->text + off1, 352 &cpos, &cfmt); 368 gfx_text_cont(&cpos, &cfmt, entry->text + off1, &cpos, &cfmt); 353 369 354 370 entry->text[off2] = c; … … 358 374 cfmt.color = res->entry_fg_color; 359 375 360 rc = gfx_puttext( res->font,&cpos, &cfmt, entry->text + off2);376 rc = gfx_puttext(&cpos, &cfmt, entry->text + off2); 361 377 if (rc != EOK) { 362 378 (void) gfx_set_clip_rect(res->gc, NULL); … … 405 421 406 422 gfx_text_fmt_init(&fmt); 423 fmt.font = res->font; 407 424 fmt.halign = gfx_halign_left; 408 425 fmt.valign = gfx_valign_top; 409 426 410 return gfx_text_find_pos(res->font, &geom.text_pos, &fmt, 411 entry->text, fpos); 427 return gfx_text_find_pos(&geom.text_pos, &fmt, entry->text, fpos); 412 428 } 413 429 … … 452 468 entry->pos = off1; 453 469 entry->sel_start = off1; 470 ui_entry_scroll_update(entry, false); 454 471 ui_entry_paint(entry); 455 472 } … … 494 511 495 512 entry->sel_start = entry->pos; 513 ui_entry_scroll_update(entry, false); 496 514 ui_entry_paint(entry); 497 515 … … 526 544 entry->sel_start = off; 527 545 546 ui_entry_scroll_update(entry, false); 528 547 ui_entry_paint(entry); 529 548 } … … 551 570 str_size(entry->text + off) + 1); 552 571 572 ui_entry_scroll_update(entry, false); 553 573 ui_entry_paint(entry); 554 574 } … … 644 664 break; 645 665 } 646 647 666 return ui_claimed; 648 667 } … … 723 742 if (!entry->active) 724 743 return ui_unclaimed; 725 726 if (event->type == KEY_PRESS && event->c >= ' ') {727 off = 0;728 rc = chr_encode(event->c, buf, &off, sizeof(buf));729 if (rc == EOK) {730 buf[off] = '\0';731 (void) ui_entry_insert_str(entry, buf);732 }733 }734 744 735 745 /* … … 748 758 if (event->type == KEY_RELEASE && event->key == KC_RSHIFT) 749 759 entry->rshift_held = false; 760 761 if (event->type == KEY_PRESS && 762 (event->mods & (KM_CTRL | KM_ALT)) == 0 && event->c >= ' ') { 763 off = 0; 764 rc = chr_encode(event->c, buf, &off, sizeof(buf)); 765 if (rc == EOK) { 766 buf[off] = '\0'; 767 (void) ui_entry_insert_str(entry, buf); 768 } 769 } 750 770 751 771 if (event->type == KEY_PRESS && … … 875 895 gfx_coord_t hpad; 876 896 gfx_coord_t vpad; 877 gfx_coord_t width;878 897 ui_resource_t *res; 879 898 … … 895 914 } 896 915 897 width = gfx_text_width(res->font, entry->text); 916 geom->text_rect.p0.x = geom->interior_rect.p0.x + hpad; 917 geom->text_rect.p0.y = geom->interior_rect.p0.y + vpad; 918 geom->text_rect.p1.x = geom->interior_rect.p1.x - hpad; 919 geom->text_rect.p1.y = geom->interior_rect.p1.y - vpad; 920 921 geom->text_pos.x = geom->interior_rect.p0.x + hpad + 922 entry->scroll_pos; 923 geom->text_pos.y = geom->interior_rect.p0.y + vpad; 898 924 899 925 switch (entry->halign) { 900 926 case gfx_halign_left: 901 927 case gfx_halign_justify: 902 geom-> text_pos.x = geom->interior_rect.p0.x + hpad;928 geom->anchor_x = geom->text_rect.p0.x; 903 929 break; 904 930 case gfx_halign_center: 905 geom-> text_pos.x = (geom->interior_rect.p0.x +906 geom-> interior_rect.p1.x) / 2 - width/ 2;931 geom->anchor_x = (geom->text_rect.p0.x + 932 geom->text_rect.p1.x) / 2; 907 933 break; 908 934 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; 935 geom->anchor_x = geom->text_rect.p1.x; 936 break; 937 } 914 938 } 915 939 … … 945 969 if (!shift) 946 970 entry->sel_start = entry->pos; 971 972 ui_entry_scroll_update(entry, false); 947 973 (void) ui_entry_paint(entry); 948 974 } … … 959 985 if (!shift) 960 986 entry->sel_start = entry->pos; 987 988 ui_entry_scroll_update(entry, false); 961 989 (void) ui_entry_paint(entry); 962 990 } … … 978 1006 if (!shift) 979 1007 entry->sel_start = entry->pos; 1008 1009 ui_entry_scroll_update(entry, false); 980 1010 (void) ui_entry_paint(entry); 981 1011 } … … 997 1027 if (!shift) 998 1028 entry->sel_start = entry->pos; 1029 1030 ui_entry_scroll_update(entry, false); 999 1031 (void) ui_entry_paint(entry); 1000 1032 } … … 1021 1053 } 1022 1054 1055 /** Update text entry scroll position. 1056 * 1057 * @param entry Text entry 1058 * @param realign @c true iff we should left-align short text. 1059 * This should be only used when changing text alignment, 1060 * because left-aligned text entries should not realign 1061 * the text to the left side under normal circumstances. 1062 */ 1063 void ui_entry_scroll_update(ui_entry_t *entry, bool realign) 1064 { 1065 ui_entry_geom_t geom; 1066 gfx_coord_t x; 1067 gfx_coord_t width; 1068 gfx_coord2_t tpos; 1069 gfx_coord2_t anchor; 1070 gfx_text_fmt_t fmt; 1071 ui_resource_t *res; 1072 1073 res = ui_window_get_res(entry->window); 1074 1075 ui_entry_get_geom(entry, &geom); 1076 1077 /* Compute position where cursor is currently displayed at */ 1078 x = geom.text_pos.x + ui_entry_lwidth(entry); 1079 1080 /* Is cursor off to the left? */ 1081 if (x < geom.text_rect.p0.x) { 1082 /* 1083 * Scroll to make cursor visible and put some space between it 1084 * and the left edge of the text rectangle. 1085 */ 1086 entry->scroll_pos += geom.text_rect.p0.x - x + 1087 ui_entry_left_scroll_margin; 1088 1089 /* 1090 * We don't want to scroll further than what's needed 1091 * to reveal the beginning of the text. 1092 */ 1093 if (entry->scroll_pos > 0) 1094 entry->scroll_pos = 0; 1095 } 1096 1097 /* 1098 * Is cursor off to the right? Note that the width of the cursor 1099 * is deliberately not taken into account (i.e. we only care 1100 * about the left edge of the cursor). 1101 */ 1102 if (x > geom.text_rect.p1.x) 1103 entry->scroll_pos -= x - geom.text_rect.p1.x; 1104 1105 width = gfx_text_width(res->font, entry->text); 1106 1107 if (width < geom.text_rect.p1.x - geom.text_rect.p0.x && 1108 (realign || entry->halign != gfx_halign_left)) { 1109 /* Text fits inside entry, so we need to align it */ 1110 anchor.x = geom.anchor_x; 1111 anchor.y = 0; 1112 gfx_text_fmt_init(&fmt); 1113 fmt.font = res->font; 1114 fmt.halign = entry->halign; 1115 gfx_text_start_pos(&anchor, &fmt, entry->text, &tpos); 1116 entry->scroll_pos = tpos.x - geom.text_rect.p0.x; 1117 } else if (geom.text_pos.x + width < geom.text_rect.p1.x && 1118 entry->halign != gfx_halign_left) { 1119 /* Text is long, unused space on the right */ 1120 entry->scroll_pos += geom.text_rect.p1.x - 1121 geom.text_pos.x - width; 1122 } 1123 } 1124 1023 1125 /** @} 1024 1126 */
Note:
See TracChangeset
for help on using the changeset viewer.