Changeset db3895d in mainline for uspace/lib/ui/src


Ignore:
Timestamp:
2021-06-10T17:10:11Z (4 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

Location:
uspace/lib/ui/src
Files:
2 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}
  • uspace/lib/ui/src/window.c

    r90f1f19 rdb3895d  
    646646}
    647647
     648/** Set cursor when pointer is hovering over a control.
     649 *
     650 * @param window Window
     651 * @param cursor Cursor
     652 */
     653void ui_window_set_ctl_cursor(ui_window_t *window, ui_stock_cursor_t cursor)
     654{
     655        display_stock_cursor_t dcursor;
     656
     657        dcursor = wnd_dcursor_from_cursor(cursor);
     658
     659        if (window->dwindow != NULL)
     660                (void) display_window_set_cursor(window->dwindow, dcursor);
     661}
     662
    648663/** Paint window
    649664 *
     
    770785}
    771786
    772 /** Window decoration requested changing cursor.
    773  *
    774  * @param wdecor Window decoration
    775  * @param arg Argument (window)
    776  * @param cursor Cursor to set
    777  */
    778 static void wd_set_cursor(ui_wdecor_t *wdecor, void *arg,
    779     ui_stock_cursor_t cursor)
    780 {
    781         ui_window_t *window = (ui_window_t *) arg;
     787/** Get display stock cursor from UI stock cursor.
     788 *
     789 * @param cursor UI stock cursor
     790 * @return Display stock cursor
     791 */
     792display_stock_cursor_t wnd_dcursor_from_cursor(ui_stock_cursor_t cursor)
     793{
    782794        display_stock_cursor_t dcursor;
    783 
    784         if (cursor == window->cursor)
    785                 return;
    786795
    787796        dcursor = dcurs_arrow;
     
    803812                dcursor = dcurs_size_urdl;
    804813                break;
    805         }
     814        case ui_curs_ibeam:
     815                dcursor = dcurs_ibeam;
     816                break;
     817        }
     818
     819        return dcursor;
     820}
     821
     822/** Window decoration requested changing cursor.
     823 *
     824 * @param wdecor Window decoration
     825 * @param arg Argument (window)
     826 * @param cursor Cursor to set
     827 */
     828static void wd_set_cursor(ui_wdecor_t *wdecor, void *arg,
     829    ui_stock_cursor_t cursor)
     830{
     831        ui_window_t *window = (ui_window_t *) arg;
     832        display_stock_cursor_t dcursor;
     833
     834        if (cursor == window->cursor)
     835                return;
     836
     837        dcursor = wnd_dcursor_from_cursor(cursor);
    806838
    807839        if (window->dwindow != NULL)
    808840                (void) display_window_set_cursor(window->dwindow, dcursor);
     841
    809842        window->cursor = cursor;
    810843}
Note: See TracChangeset for help on using the changeset viewer.