Changeset d63623f in mainline for uspace/lib/ui/src/entry.c
- Timestamp:
- 2021-07-16T17:45:12Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4afb6c9
- Parents:
- 61bf9dd9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/entry.c
r61bf9dd9 rd63623f 256 256 { 257 257 ui_resource_t *res; 258 ui_entry_geom_t geom; 258 259 gfx_text_fmt_t fmt; 259 260 gfx_coord2_t pos; 260 gfx_coord_t hpad;261 gfx_coord_t vpad;262 gfx_coord_t width;263 261 gfx_rect_t inside; 264 262 errno_t rc; … … 266 264 res = ui_window_get_res(entry->window); 267 265 268 if (res->textmode) { 269 hpad = ui_entry_hpad_text; 270 vpad = ui_entry_vpad_text; 271 } else { 272 hpad = ui_entry_hpad; 273 vpad = ui_entry_vpad; 274 } 266 ui_entry_get_geom(entry, &geom); 275 267 276 268 if (res->textmode == false) { … … 293 285 goto error; 294 286 295 width = gfx_text_width(res->font, entry->text); 296 297 switch (entry->halign) { 298 case gfx_halign_left: 299 case gfx_halign_justify: 300 pos.x = inside.p0.x + hpad; 301 break; 302 case gfx_halign_center: 303 pos.x = (inside.p0.x + inside.p1.x) / 2 - width / 2; 304 break; 305 case gfx_halign_right: 306 pos.x = inside.p1.x - hpad - 1 - width; 307 break; 308 } 309 310 pos.y = inside.p0.y + vpad; 287 pos = geom.text_pos; 311 288 312 289 gfx_text_fmt_init(&fmt); … … 347 324 error: 348 325 return rc; 326 } 327 328 /** Find position in text entry. 329 * 330 * @param entry Text entry 331 * @param fpos Position for which we need to find text offset 332 * @return Corresponding byte offset in entry text 333 */ 334 size_t ui_entry_find_pos(ui_entry_t *entry, gfx_coord2_t *fpos) 335 { 336 ui_resource_t *res; 337 ui_entry_geom_t geom; 338 gfx_text_fmt_t fmt; 339 340 res = ui_window_get_res(entry->window); 341 342 ui_entry_get_geom(entry, &geom); 343 344 gfx_text_fmt_init(&fmt); 345 fmt.halign = gfx_halign_left; 346 fmt.valign = gfx_valign_top; 347 348 return gfx_text_find_pos(res->font, &geom.text_pos, &fmt, 349 entry->text, fpos); 349 350 } 350 351 … … 567 568 568 569 if (gfx_pix_inside_rect(&pos, &entry->rect)) { 569 ui_entry_activate(entry); 570 entry->pos = ui_entry_find_pos(entry, &pos); 571 if (entry->active) 572 ui_entry_paint(entry); 573 else 574 ui_entry_activate(entry); 570 575 571 576 return ui_claimed; … … 604 609 } 605 610 611 /** Get text entry geometry. 612 * 613 * @param entry Text entry 614 * @param geom Structure to fill in with computed geometry 615 */ 616 void ui_entry_get_geom(ui_entry_t *entry, ui_entry_geom_t *geom) 617 { 618 gfx_coord_t hpad; 619 gfx_coord_t vpad; 620 gfx_coord_t width; 621 ui_resource_t *res; 622 623 res = ui_window_get_res(entry->window); 624 625 if (res->textmode) { 626 hpad = ui_entry_hpad_text; 627 vpad = ui_entry_vpad_text; 628 } else { 629 hpad = ui_entry_hpad; 630 vpad = ui_entry_vpad; 631 } 632 633 if (res->textmode == false) { 634 ui_paint_get_inset_frame_inside(res, &entry->rect, 635 &geom->interior_rect); 636 } else { 637 geom->interior_rect = entry->rect; 638 } 639 640 width = gfx_text_width(res->font, entry->text); 641 642 switch (entry->halign) { 643 case gfx_halign_left: 644 case gfx_halign_justify: 645 geom->text_pos.x = geom->interior_rect.p0.x + hpad; 646 break; 647 case gfx_halign_center: 648 geom->text_pos.x = (geom->interior_rect.p0.x + 649 geom->interior_rect.p1.x) / 2 - width / 2; 650 break; 651 case gfx_halign_right: 652 geom->text_pos.x = geom->interior_rect.p1.x - hpad - 1 - width; 653 break; 654 } 655 656 geom->text_pos.y = geom->interior_rect.p0.y + vpad; 657 } 658 606 659 /** Activate text entry. 607 660 * … … 618 671 619 672 entry->active = true; 620 entry->pos = str_size(entry->text);621 673 (void) ui_entry_paint(entry); 622 674
Note:
See TracChangeset
for help on using the changeset viewer.