Changeset db3895d in mainline for uspace/lib/ui
- Timestamp:
- 2021-06-10T17:10:11Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- af5d62eb
- Parents:
- 90f1f19
- Location:
- uspace/lib/ui
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/types/ui/cursor.h
r90f1f19 rdb3895d 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 47 47 ui_curs_size_uldr, 48 48 /** Double arrow pointing up-right nad down-left */ 49 ui_curs_size_urdl 49 ui_curs_size_urdl, 50 /** I-beam (suggests editable text) */ 51 ui_curs_ibeam 50 52 } ui_stock_cursor_t; 51 53 -
uspace/lib/ui/include/ui/entry.h
r90f1f19 rdb3895d 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 42 42 #include <types/ui/control.h> 43 43 #include <types/ui/entry.h> 44 #include <types/ui/ resource.h>44 #include <types/ui/window.h> 45 45 46 extern errno_t ui_entry_create(ui_ resource_t *, const char *,46 extern errno_t ui_entry_create(ui_window_t *, const char *, 47 47 ui_entry_t **); 48 48 extern void ui_entry_destroy(ui_entry_t *); -
uspace/lib/ui/include/ui/window.h
r90f1f19 rdb3895d 60 60 extern errno_t ui_window_get_app_gc(ui_window_t *, gfx_context_t **); 61 61 extern void ui_window_get_app_rect(ui_window_t *, gfx_rect_t *); 62 extern void ui_window_set_ctl_cursor(ui_window_t *, ui_stock_cursor_t); 62 63 extern errno_t ui_window_paint(ui_window_t *); 63 64 extern errno_t ui_window_def_paint(ui_window_t *); -
uspace/lib/ui/private/entry.h
r90f1f19 rdb3895d 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 48 48 /** Base control object */ 49 49 struct ui_control *control; 50 /** UI resource*/51 struct ui_ resource *res;50 /** UI window */ 51 struct ui_window *window; 52 52 /** Entry rectangle */ 53 53 gfx_rect_t rect; … … 56 56 /** Text */ 57 57 char *text; 58 /** Pointer is currently inside */ 59 bool pointer_inside; 58 60 }; 59 61 -
uspace/lib/ui/private/window.h
r90f1f19 rdb3895d 92 92 }; 93 93 94 extern display_stock_cursor_t wnd_dcursor_from_cursor(ui_stock_cursor_t); 94 95 extern void ui_window_send_close(ui_window_t *); 95 96 extern void ui_window_send_focus(ui_window_t *); -
uspace/lib/ui/src/entry.c
r90f1f19 rdb3895d 47 47 #include <ui/entry.h> 48 48 #include <ui/ui.h> 49 #include <ui/window.h> 49 50 #include "../private/entry.h" 50 51 #include "../private/resource.h" … … 70 71 /** Create new text entry. 71 72 * 72 * @param resource UI resource73 * @param window UI window 73 74 * @param text Text 74 75 * @param rentry Place to store pointer to new text entry 75 76 * @return EOK on success, ENOMEM if out of memory 76 77 */ 77 errno_t ui_entry_create(ui_ resource_t *resource, const char *text,78 errno_t ui_entry_create(ui_window_t *window, const char *text, 78 79 ui_entry_t **rentry) 79 80 { … … 98 99 } 99 100 100 entry-> res = resource;101 entry->window = window; 101 102 entry->halign = gfx_halign_left; 102 103 *rentry = entry; … … 174 175 errno_t ui_entry_paint(ui_entry_t *entry) 175 176 { 177 ui_resource_t *res; 176 178 gfx_text_fmt_t fmt; 177 179 gfx_coord2_t pos; … … 181 183 errno_t rc; 182 184 183 if (entry->res->textmode) { 185 res = ui_window_get_res(entry->window); 186 187 if (res->textmode) { 184 188 hpad = ui_entry_hpad_text; 185 189 vpad = ui_entry_vpad_text; … … 189 193 } 190 194 191 if ( entry->res->textmode == false) {195 if (res->textmode == false) { 192 196 /* Paint inset frame */ 193 rc = ui_paint_inset_frame( entry->res, &entry->rect, &inside);197 rc = ui_paint_inset_frame(res, &entry->rect, &inside); 194 198 if (rc != EOK) 195 199 goto error; … … 200 204 /* Paint entry background */ 201 205 202 rc = gfx_set_color( entry->res->gc, entry->res->entry_bg_color);206 rc = gfx_set_color(res->gc, res->entry_bg_color); 203 207 if (rc != EOK) 204 208 goto error; 205 209 206 rc = gfx_fill_rect( entry->res->gc, &inside);210 rc = gfx_fill_rect(res->gc, &inside); 207 211 if (rc != EOK) 208 212 goto error; … … 224 228 225 229 gfx_text_fmt_init(&fmt); 226 fmt.color = entry->res->entry_fg_color;230 fmt.color = res->entry_fg_color; 227 231 fmt.halign = entry->halign; 228 232 fmt.valign = gfx_valign_top; 229 233 230 rc = gfx_puttext( entry->res->font, &pos, &fmt, entry->text);234 rc = gfx_puttext(res->font, &pos, &fmt, entry->text); 231 235 if (rc != EOK) 232 236 goto error; 233 237 234 rc = gfx_update( entry->res->gc);238 rc = gfx_update(res->gc); 235 239 if (rc != EOK) 236 240 goto error; … … 273 277 { 274 278 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 277 300 return ui_unclaimed; 278 301 } -
uspace/lib/ui/src/window.c
r90f1f19 rdb3895d 646 646 } 647 647 648 /** Set cursor when pointer is hovering over a control. 649 * 650 * @param window Window 651 * @param cursor Cursor 652 */ 653 void 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 648 663 /** Paint window 649 664 * … … 770 785 } 771 786 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 */ 792 display_stock_cursor_t wnd_dcursor_from_cursor(ui_stock_cursor_t cursor) 793 { 782 794 display_stock_cursor_t dcursor; 783 784 if (cursor == window->cursor)785 return;786 795 787 796 dcursor = dcurs_arrow; … … 803 812 dcursor = dcurs_size_urdl; 804 813 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 */ 828 static 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); 806 838 807 839 if (window->dwindow != NULL) 808 840 (void) display_window_set_cursor(window->dwindow, dcursor); 841 809 842 window->cursor = cursor; 810 843 } -
uspace/lib/ui/test/entry.c
r90f1f19 rdb3895d 35 35 #include <ui/entry.h> 36 36 #include <ui/resource.h> 37 #include <ui/ui.h> 38 #include <ui/window.h> 37 39 #include "../private/entry.h" 38 40 … … 40 42 41 43 PCUT_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_alloc62 };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;84 44 85 45 /** Create and destroy text entry */ … … 187 147 { 188 148 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; 192 152 ui_entry_t *entry; 193 153 194 memset(&tgc, 0, sizeof(tgc)); 195 rc = gfx_context_new(&ops, &tgc, &gc); 154 rc = ui_create_disp(NULL, &ui); 196 155 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 197 156 198 rc = ui_resource_create(gc, false, &resource); 157 ui_wnd_params_init(¶ms); 158 params.caption = "Hello"; 159 160 rc = ui_window_create(ui, ¶ms, &window); 199 161 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 200 PCUT_ASSERT_NOT_NULL( resource);162 PCUT_ASSERT_NOT_NULL(window); 201 163 202 rc = ui_entry_create( resource, "Hello", &entry);164 rc = ui_entry_create(window, "Hello", &entry); 203 165 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 204 166 … … 207 169 208 170 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); 302 173 } 303 174 -
uspace/lib/ui/test/window.c
r90f1f19 rdb3895d 291 291 } 292 292 293 /** ui_window_set_ctl_cursor() */ 294 PCUT_TEST(set_ctl_cursor) 295 { 296 errno_t rc; 297 ui_t *ui = NULL; 298 ui_wnd_params_t params; 299 ui_window_t *window = NULL; 300 301 rc = ui_create_disp(NULL, &ui); 302 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 303 304 ui_wnd_params_init(¶ms); 305 params.caption = "Hello"; 306 307 rc = ui_window_create(ui, ¶ms, &window); 308 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 309 PCUT_ASSERT_NOT_NULL(window); 310 311 ui_window_set_ctl_cursor(window, ui_curs_ibeam); 312 313 ui_window_destroy(window); 314 ui_destroy(ui); 315 } 316 293 317 /** ui_window_get_app_gc() return valid GC */ 294 318 PCUT_TEST(get_app_gc)
Note:
See TracChangeset
for help on using the changeset viewer.