Changeset bb14312 in mainline for uspace/lib/ui
- Timestamp:
- 2021-06-26T16:40:28Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1215db9
- Parents:
- 69511176
- Location:
- uspace/lib/ui
- Files:
-
- 4 edited
-
private/entry.h (modified) (1 diff)
-
src/entry.c (modified) (7 diffs)
-
src/ui.c (modified) (2 diffs)
-
test/entry.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/private/entry.h
r69511176 rbb14312 67 67 extern void ui_entry_backspace(ui_entry_t *); 68 68 extern ui_evclaim_t ui_entry_key_press_unmod(ui_entry_t *, kbd_event_t *); 69 extern void ui_entry_activate(ui_entry_t *); 70 extern void ui_entry_deactivate(ui_entry_t *); 69 71 70 72 #endif -
uspace/lib/ui/src/entry.c
r69511176 rbb14312 39 39 #include <errno.h> 40 40 #include <gfx/context.h> 41 #include <gfx/cursor.h> 41 42 #include <gfx/render.h> 42 43 #include <gfx/text.h> … … 62 63 ui_entry_vpad_text = 0, 63 64 ui_entry_cursor_overshoot = 1, 64 ui_entry_cursor_width = 2, 65 ui_entry_cursor_width_text = 1 65 ui_entry_cursor_width = 2 66 66 }; 67 67 … … 107 107 entry->halign = gfx_halign_left; 108 108 *rentry = entry; 109 109 110 return EOK; 110 111 } … … 194 195 gfx_rect_t rect; 195 196 gfx_font_metrics_t metrics; 196 gfx_coord_t w;197 197 errno_t rc; 198 198 199 199 res = ui_window_get_res(entry->window); 200 200 201 if (res->textmode) { 202 rc = gfx_cursor_set_pos(res->gc, pos); 203 return rc; 204 } 205 201 206 gfx_font_get_metrics(res->font, &metrics); 202 203 w = res->textmode ? ui_entry_cursor_width_text :204 ui_entry_cursor_width;205 207 206 208 rect.p0.x = pos->x; 207 209 rect.p0.y = pos->y - ui_entry_cursor_overshoot; 208 rect.p1.x = pos->x + w;210 rect.p1.x = pos->x + ui_entry_cursor_width; 209 211 rect.p1.y = pos->y + metrics.ascent + metrics.descent + 1 + 210 212 ui_entry_cursor_overshoot; … … 399 401 ui_entry_backspace(entry); 400 402 401 if (event->key == KC_ESCAPE) { 402 entry->active = false; 403 (void) ui_entry_paint(entry); 404 } 403 if (event->key == KC_ESCAPE) 404 ui_entry_deactivate(entry); 405 405 406 406 return ui_claimed; … … 475 475 476 476 if (gfx_pix_inside_rect(&pos, &entry->rect)) { 477 if (!entry->active) { 478 entry->active = true; 479 (void) ui_entry_paint(entry); 480 } 477 ui_entry_activate(entry); 481 478 482 479 return ui_claimed; 483 480 } else { 484 if (entry->active) { 485 entry->active = false; 486 (void) ui_entry_paint(entry); 487 } 481 ui_entry_deactivate(entry); 488 482 } 489 483 } … … 518 512 } 519 513 514 /** Activate text entry. 515 * 516 * @param entry Text entry 517 */ 518 void ui_entry_activate(ui_entry_t *entry) 519 { 520 ui_resource_t *res; 521 522 res = ui_window_get_res(entry->window); 523 524 if (entry->active) 525 return; 526 527 entry->active = true; 528 (void) ui_entry_paint(entry); 529 530 if (res->textmode) 531 gfx_cursor_set_visible(res->gc, true); 532 } 533 534 /** Deactivate text entry. 535 * 536 * @param entry Text entry 537 */ 538 void ui_entry_deactivate(ui_entry_t *entry) 539 { 540 ui_resource_t *res; 541 542 res = ui_window_get_res(entry->window); 543 544 if (!entry->active) 545 return; 546 547 entry->active = false; 548 (void) ui_entry_paint(entry); 549 550 if (res->textmode) 551 gfx_cursor_set_visible(res->gc, false); 552 } 553 520 554 /** @} 521 555 */ -
uspace/lib/ui/src/ui.c
r69511176 rbb14312 128 128 return EIO; 129 129 130 console_cursor_visibility(console, false); 131 130 132 /* ws == ui_ws_console */ 131 133 rc = ui_create_cons(console, &ui); … … 203 205 if (ui->cgc != NULL) 204 206 console_gc_delete(ui->cgc); 205 if (ui->console != NULL) 207 if (ui->console != NULL) { 208 console_cursor_visibility(ui->console, true); 206 209 console_done(ui->console); 210 } 207 211 if (ui->display != NULL) 208 212 display_close(ui->display); -
uspace/lib/ui/test/entry.c
r69511176 rbb14312 270 270 } 271 271 272 /** ui_entry_activate() / ui_entry_deactivate() */ 273 PCUT_TEST(activate_deactivate) 274 { 275 errno_t rc; 276 ui_t *ui = NULL; 277 ui_window_t *window = NULL; 278 ui_wnd_params_t params; 279 ui_entry_t *entry; 280 281 rc = ui_create_disp(NULL, &ui); 282 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 283 284 ui_wnd_params_init(¶ms); 285 params.caption = "Hello"; 286 287 rc = ui_window_create(ui, ¶ms, &window); 288 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 289 PCUT_ASSERT_NOT_NULL(window); 290 291 rc = ui_entry_create(window, "ABC", &entry); 292 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 293 294 PCUT_ASSERT_FALSE(entry->active); 295 296 ui_entry_activate(entry); 297 PCUT_ASSERT_TRUE(entry->active); 298 299 ui_entry_deactivate(entry); 300 PCUT_ASSERT_FALSE(entry->active); 301 302 ui_entry_destroy(entry); 303 ui_window_destroy(window); 304 ui_destroy(ui); 305 } 306 272 307 PCUT_EXPORT(entry);
Note:
See TracChangeset
for help on using the changeset viewer.
