Changes in uspace/lib/ui/src/entry.c [b987eb4:a106037] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/entry.c
rb987eb4 ra106037 67 67 ui_entry_cursor_width = 2, 68 68 ui_entry_sel_hpad = 0, 69 ui_entry_sel_vpad = 2, 70 /** Additional amount to scroll to the left after revealing cursor */ 71 ui_entry_left_scroll_margin = 30 69 ui_entry_sel_vpad = 2 72 70 }; 73 71 … … 158 156 { 159 157 entry->halign = halign; 160 ui_entry_scroll_update(entry, true);161 ui_entry_paint(entry);162 158 } 163 159 … … 191 187 entry->sel_start = entry->pos; 192 188 193 ui_entry_scroll_update(entry, false);194 ui_entry_paint(entry);195 196 189 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;206 190 } 207 191 … … 314 298 315 299 gfx_text_fmt_init(&fmt); 316 fmt.font = res->font;317 300 fmt.color = res->entry_fg_color; 318 301 fmt.halign = gfx_halign_left; … … 330 313 entry->text[off1] = '\0'; 331 314 332 rc = gfx_puttext( &pos, &fmt, entry->text);315 rc = gfx_puttext(res->font, &pos, &fmt, entry->text); 333 316 if (rc != EOK) { 334 317 (void) gfx_set_clip_rect(res->gc, NULL); … … 336 319 } 337 320 338 gfx_text_cont( &pos, &fmt, entry->text, &cpos, &cfmt);321 gfx_text_cont(res->font, &pos, &fmt, entry->text, &cpos, &cfmt); 339 322 entry->text[off1] = c; 340 323 … … 344 327 c = entry->text[off2]; 345 328 entry->text[off2] = '\0'; 346 cfmt.color = res->entry_ sel_text_fg_color;347 348 gfx_text_rect( &cpos, &cfmt, entry->text + off1, &sel);329 cfmt.color = res->entry_bg_color; 330 331 gfx_text_rect(res->font, &cpos, &cfmt, entry->text + off1, &sel); 349 332 sel.p0.x -= ui_entry_sel_hpad; 350 333 sel.p0.y -= ui_entry_sel_vpad; … … 352 335 sel.p1.y += ui_entry_sel_vpad; 353 336 354 rc = gfx_set_color(res->gc, res->entry_ sel_text_bg_color);337 rc = gfx_set_color(res->gc, res->entry_fg_color); 355 338 if (rc != EOK) 356 339 goto error; … … 360 343 goto error; 361 344 362 rc = gfx_puttext( &cpos, &cfmt, entry->text + off1);345 rc = gfx_puttext(res->font, &cpos, &cfmt, entry->text + off1); 363 346 if (rc != EOK) { 364 347 (void) gfx_set_clip_rect(res->gc, NULL); … … 366 349 } 367 350 368 gfx_text_cont(&cpos, &cfmt, entry->text + off1, &cpos, &cfmt); 351 gfx_text_cont(res->font, &cpos, &cfmt, entry->text + off1, 352 &cpos, &cfmt); 369 353 370 354 entry->text[off2] = c; … … 374 358 cfmt.color = res->entry_fg_color; 375 359 376 rc = gfx_puttext( &cpos, &cfmt, entry->text + off2);360 rc = gfx_puttext(res->font, &cpos, &cfmt, entry->text + off2); 377 361 if (rc != EOK) { 378 362 (void) gfx_set_clip_rect(res->gc, NULL); … … 421 405 422 406 gfx_text_fmt_init(&fmt); 423 fmt.font = res->font;424 407 fmt.halign = gfx_halign_left; 425 408 fmt.valign = gfx_valign_top; 426 409 427 return gfx_text_find_pos(&geom.text_pos, &fmt, entry->text, fpos); 410 return gfx_text_find_pos(res->font, &geom.text_pos, &fmt, 411 entry->text, fpos); 428 412 } 429 413 … … 468 452 entry->pos = off1; 469 453 entry->sel_start = off1; 470 ui_entry_scroll_update(entry, false);471 454 ui_entry_paint(entry); 472 455 } … … 511 494 512 495 entry->sel_start = entry->pos; 513 ui_entry_scroll_update(entry, false);514 496 ui_entry_paint(entry); 515 497 … … 544 526 entry->sel_start = off; 545 527 546 ui_entry_scroll_update(entry, false);547 528 ui_entry_paint(entry); 548 529 } … … 570 551 str_size(entry->text + off) + 1); 571 552 572 ui_entry_scroll_update(entry, false);573 553 ui_entry_paint(entry); 574 554 } … … 664 644 break; 665 645 } 646 666 647 return ui_claimed; 667 648 } … … 742 723 if (!entry->active) 743 724 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 } 744 734 745 735 /* … … 758 748 if (event->type == KEY_RELEASE && event->key == KC_RSHIFT) 759 749 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 }770 750 771 751 if (event->type == KEY_PRESS && … … 895 875 gfx_coord_t hpad; 896 876 gfx_coord_t vpad; 877 gfx_coord_t width; 897 878 ui_resource_t *res; 898 879 … … 914 895 } 915 896 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; 897 width = gfx_text_width(res->font, entry->text); 924 898 925 899 switch (entry->halign) { 926 900 case gfx_halign_left: 927 901 case gfx_halign_justify: 928 geom-> anchor_x = geom->text_rect.p0.x;902 geom->text_pos.x = geom->interior_rect.p0.x + hpad; 929 903 break; 930 904 case gfx_halign_center: 931 geom-> anchor_x = (geom->text_rect.p0.x +932 geom-> text_rect.p1.x)/ 2;905 geom->text_pos.x = (geom->interior_rect.p0.x + 906 geom->interior_rect.p1.x) / 2 - width / 2; 933 907 break; 934 908 case gfx_halign_right: 935 geom->anchor_x = geom->text_rect.p1.x; 936 break; 937 } 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; 938 914 } 939 915 … … 969 945 if (!shift) 970 946 entry->sel_start = entry->pos; 971 972 ui_entry_scroll_update(entry, false);973 947 (void) ui_entry_paint(entry); 974 948 } … … 985 959 if (!shift) 986 960 entry->sel_start = entry->pos; 987 988 ui_entry_scroll_update(entry, false);989 961 (void) ui_entry_paint(entry); 990 962 } … … 1006 978 if (!shift) 1007 979 entry->sel_start = entry->pos; 1008 1009 ui_entry_scroll_update(entry, false);1010 980 (void) ui_entry_paint(entry); 1011 981 } … … 1027 997 if (!shift) 1028 998 entry->sel_start = entry->pos; 1029 1030 ui_entry_scroll_update(entry, false);1031 999 (void) ui_entry_paint(entry); 1032 1000 } … … 1053 1021 } 1054 1022 1055 /** Update text entry scroll position.1056 *1057 * @param entry Text entry1058 * @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 realign1061 * 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 it1084 * 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 needed1091 * 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 cursor1099 * is deliberately not taken into account (i.e. we only care1100 * 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 1125 1023 /** @} 1126 1024 */
Note:
See TracChangeset
for help on using the changeset viewer.