Changeset db3895d in mainline for uspace/lib/ui/test/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/test/entry.c

    r90f1f19 rdb3895d  
    3535#include <ui/entry.h>
    3636#include <ui/resource.h>
     37#include <ui/ui.h>
     38#include <ui/window.h>
    3739#include "../private/entry.h"
    3840
     
    4042
    4143PCUT_TEST_SUITE(entry);
    42 
    43 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
    44 static errno_t testgc_set_color(void *, gfx_color_t *);
    45 static errno_t testgc_fill_rect(void *, gfx_rect_t *);
    46 static errno_t testgc_update(void *);
    47 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
    48     gfx_bitmap_alloc_t *, void **);
    49 static errno_t testgc_bitmap_destroy(void *);
    50 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    51 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
    52 
    53 static gfx_context_ops_t ops = {
    54         .set_clip_rect = testgc_set_clip_rect,
    55         .set_color = testgc_set_color,
    56         .fill_rect = testgc_fill_rect,
    57         .update = testgc_update,
    58         .bitmap_create = testgc_bitmap_create,
    59         .bitmap_destroy = testgc_bitmap_destroy,
    60         .bitmap_render = testgc_bitmap_render,
    61         .bitmap_get_alloc = testgc_bitmap_get_alloc
    62 };
    63 
    64 typedef struct {
    65         bool bm_created;
    66         bool bm_destroyed;
    67         gfx_bitmap_params_t bm_params;
    68         void *bm_pixels;
    69         gfx_rect_t bm_srect;
    70         gfx_coord2_t bm_offs;
    71         bool bm_rendered;
    72         bool bm_got_alloc;
    73 } test_gc_t;
    74 
    75 typedef struct {
    76         test_gc_t *tgc;
    77         gfx_bitmap_alloc_t alloc;
    78         bool myalloc;
    79 } testgc_bitmap_t;
    80 
    81 typedef struct {
    82         bool clicked;
    83 } test_cb_resp_t;
    8444
    8545/** Create and destroy text entry */
     
    187147{
    188148        errno_t rc;
    189         gfx_context_t *gc = NULL;
    190         test_gc_t tgc;
    191         ui_resource_t *resource = NULL;
     149        ui_t *ui = NULL;
     150        ui_window_t *window = NULL;
     151        ui_wnd_params_t params;
    192152        ui_entry_t *entry;
    193153
    194         memset(&tgc, 0, sizeof(tgc));
    195         rc = gfx_context_new(&ops, &tgc, &gc);
     154        rc = ui_create_disp(NULL, &ui);
    196155        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    197156
    198         rc = ui_resource_create(gc, false, &resource);
     157        ui_wnd_params_init(&params);
     158        params.caption = "Hello";
     159
     160        rc = ui_window_create(ui, &params, &window);
    199161        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    200         PCUT_ASSERT_NOT_NULL(resource);
     162        PCUT_ASSERT_NOT_NULL(window);
    201163
    202         rc = ui_entry_create(resource, "Hello", &entry);
     164        rc = ui_entry_create(window, "Hello", &entry);
    203165        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    204166
     
    207169
    208170        ui_entry_destroy(entry);
    209         ui_resource_destroy(resource);
    210 
    211         rc = gfx_context_delete(gc);
    212         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    213 }
    214 
    215 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
    216 {
    217         (void) arg;
    218         (void) rect;
    219         return EOK;
    220 }
    221 
    222 static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    223 {
    224         (void) arg;
    225         (void) color;
    226         return EOK;
    227 }
    228 
    229 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    230 {
    231         (void) arg;
    232         (void) rect;
    233         return EOK;
    234 }
    235 
    236 static errno_t testgc_update(void *arg)
    237 {
    238         (void) arg;
    239         return EOK;
    240 }
    241 
    242 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    243     gfx_bitmap_alloc_t *alloc, void **rbm)
    244 {
    245         test_gc_t *tgc = (test_gc_t *) arg;
    246         testgc_bitmap_t *tbm;
    247 
    248         tbm = calloc(1, sizeof(testgc_bitmap_t));
    249         if (tbm == NULL)
    250                 return ENOMEM;
    251 
    252         if (alloc == NULL) {
    253                 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
    254                     sizeof(uint32_t);
    255                 tbm->alloc.off0 = 0;
    256                 tbm->alloc.pixels = calloc(sizeof(uint32_t),
    257                     (params->rect.p1.x - params->rect.p0.x) *
    258                     (params->rect.p1.y - params->rect.p0.y));
    259                 tbm->myalloc = true;
    260                 if (tbm->alloc.pixels == NULL) {
    261                         free(tbm);
    262                         return ENOMEM;
    263                 }
    264         } else {
    265                 tbm->alloc = *alloc;
    266         }
    267 
    268         tbm->tgc = tgc;
    269         tgc->bm_created = true;
    270         tgc->bm_params = *params;
    271         tgc->bm_pixels = tbm->alloc.pixels;
    272         *rbm = (void *)tbm;
    273         return EOK;
    274 }
    275 
    276 static errno_t testgc_bitmap_destroy(void *bm)
    277 {
    278         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    279         if (tbm->myalloc)
    280                 free(tbm->alloc.pixels);
    281         tbm->tgc->bm_destroyed = true;
    282         free(tbm);
    283         return EOK;
    284 }
    285 
    286 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    287     gfx_coord2_t *offs)
    288 {
    289         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    290         tbm->tgc->bm_rendered = true;
    291         tbm->tgc->bm_srect = *srect;
    292         tbm->tgc->bm_offs = *offs;
    293         return EOK;
    294 }
    295 
    296 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    297 {
    298         testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
    299         *alloc = tbm->alloc;
    300         tbm->tgc->bm_got_alloc = true;
    301         return EOK;
     171        ui_window_destroy(window);
     172        ui_destroy(ui);
    302173}
    303174
Note: See TracChangeset for help on using the changeset viewer.