Changeset db3895d in mainline for uspace/lib/ui/src/entry.c


Ignore:
Timestamp:
2021-06-10T17:10:11Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
af5d62eb
Parents:
90f1f19
Message:

Set cursor shape to I-beam when hovering over text entry

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/entry.c

    r90f1f19 rdb3895d  
    4747#include <ui/entry.h>
    4848#include <ui/ui.h>
     49#include <ui/window.h>
    4950#include "../private/entry.h"
    5051#include "../private/resource.h"
     
    7071/** Create new text entry.
    7172 *
    72  * @param resource UI resource
     73 * @param window UI window
    7374 * @param text Text
    7475 * @param rentry Place to store pointer to new text entry
    7576 * @return EOK on success, ENOMEM if out of memory
    7677 */
    77 errno_t ui_entry_create(ui_resource_t *resource, const char *text,
     78errno_t ui_entry_create(ui_window_t *window, const char *text,
    7879    ui_entry_t **rentry)
    7980{
     
    9899        }
    99100
    100         entry->res = resource;
     101        entry->window = window;
    101102        entry->halign = gfx_halign_left;
    102103        *rentry = entry;
     
    174175errno_t ui_entry_paint(ui_entry_t *entry)
    175176{
     177        ui_resource_t *res;
    176178        gfx_text_fmt_t fmt;
    177179        gfx_coord2_t pos;
     
    181183        errno_t rc;
    182184
    183         if (entry->res->textmode) {
     185        res = ui_window_get_res(entry->window);
     186
     187        if (res->textmode) {
    184188                hpad = ui_entry_hpad_text;
    185189                vpad = ui_entry_vpad_text;
     
    189193        }
    190194
    191         if (entry->res->textmode == false) {
     195        if (res->textmode == false) {
    192196                /* Paint inset frame */
    193                 rc = ui_paint_inset_frame(entry->res, &entry->rect, &inside);
     197                rc = ui_paint_inset_frame(res, &entry->rect, &inside);
    194198                if (rc != EOK)
    195199                        goto error;
     
    200204        /* Paint entry background */
    201205
    202         rc = gfx_set_color(entry->res->gc, entry->res->entry_bg_color);
     206        rc = gfx_set_color(res->gc, res->entry_bg_color);
    203207        if (rc != EOK)
    204208                goto error;
    205209
    206         rc = gfx_fill_rect(entry->res->gc, &inside);
     210        rc = gfx_fill_rect(res->gc, &inside);
    207211        if (rc != EOK)
    208212                goto error;
     
    224228
    225229        gfx_text_fmt_init(&fmt);
    226         fmt.color = entry->res->entry_fg_color;
     230        fmt.color = res->entry_fg_color;
    227231        fmt.halign = entry->halign;
    228232        fmt.valign = gfx_valign_top;
    229233
    230         rc = gfx_puttext(entry->res->font, &pos, &fmt, entry->text);
     234        rc = gfx_puttext(res->font, &pos, &fmt, entry->text);
    231235        if (rc != EOK)
    232236                goto error;
    233237
    234         rc = gfx_update(entry->res->gc);
     238        rc = gfx_update(res->gc);
    235239        if (rc != EOK)
    236240                goto error;
     
    273277{
    274278        ui_entry_t *entry = (ui_entry_t *) arg;
    275 
    276         (void) entry;
     279        gfx_coord2_t pos;
     280
     281        if (event->type == POS_UPDATE) {
     282                pos.x = event->hpos;
     283                pos.y = event->vpos;
     284
     285                if (gfx_pix_inside_rect(&pos, &entry->rect)) {
     286                        if (!entry->pointer_inside) {
     287                                ui_window_set_ctl_cursor(entry->window,
     288                                    ui_curs_ibeam);
     289                                entry->pointer_inside = true;
     290                        }
     291                } else {
     292                        if (entry->pointer_inside) {
     293                                ui_window_set_ctl_cursor(entry->window,
     294                                    ui_curs_arrow);
     295                                entry->pointer_inside = false;
     296                        }
     297                }
     298        }
     299
    277300        return ui_unclaimed;
    278301}
Note: See TracChangeset for help on using the changeset viewer.