Changeset 8009dc27 in mainline
- Timestamp:
- 2020-10-31T01:03:26Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4df6607
- Parents:
- f03d1308
- Location:
- uspace
- Files:
-
- 10 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rf03d1308 r8009dc27 40 40 #include <str.h> 41 41 #include <task.h> 42 #include <ui/fixed.h> 42 43 #include <ui/label.h> 43 44 #include <ui/pbutton.h> … … 84 85 85 86 /* Make sure we don't process events until fully initialized */ 86 if (demo-> pb1 == NULL || demo->pb2== NULL)87 if (demo->fixed == NULL) 87 88 return; 88 89 89 ui_pbutton_pos_event(demo->pb1, event); 90 ui_pbutton_pos_event(demo->pb2, event); 90 ui_fixed_pos_event(demo->fixed, event); 91 91 } 92 92 … … 159 159 ui_window_get_app_rect(window, &app_rect); 160 160 161 rc = ui_fixed_create(&demo.fixed); 162 if (rc != EOK) { 163 printf("Error creating fixed layout.\n"); 164 return rc; 165 } 166 161 167 rc = ui_label_create(ui_res, "Hello there!", &demo.label); 162 168 if (rc != EOK) { … … 172 178 ui_label_set_halign(demo.label, gfx_halign_center); 173 179 180 rc = ui_fixed_add(demo.fixed, ui_label_ctl(demo.label)); 181 if (rc != EOK) { 182 printf("Error adding control to layout.\n"); 183 return rc; 184 } 185 174 186 rc = ui_pbutton_create(ui_res, "Confirm", &demo.pb1); 175 187 if (rc != EOK) { … … 188 200 ui_pbutton_set_default(demo.pb1, true); 189 201 202 rc = ui_fixed_add(demo.fixed, ui_pbutton_ctl(demo.pb1)); 203 if (rc != EOK) { 204 printf("Error adding control to layout.\n"); 205 return rc; 206 } 207 190 208 rc = ui_pbutton_create(ui_res, "Cancel", &demo.pb2); 191 209 if (rc != EOK) { … … 202 220 ui_pbutton_set_rect(demo.pb2, &rect); 203 221 222 rc = ui_fixed_add(demo.fixed, ui_pbutton_ctl(demo.pb2)); 223 if (rc != EOK) { 224 printf("Error adding control to layout.\n"); 225 return rc; 226 } 227 204 228 rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &color); 205 229 if (rc != EOK) { … … 239 263 240 264 ui_run(ui); 265 266 ui_fixed_remove(demo.fixed, ui_label_ctl(demo.label)); 267 ui_fixed_remove(demo.fixed, ui_pbutton_ctl(demo.pb1)); 268 ui_fixed_remove(demo.fixed, ui_pbutton_ctl(demo.pb2)); 241 269 242 270 ui_pbutton_destroy(demo.pb1); -
uspace/app/uidemo/uidemo.h
rf03d1308 r8009dc27 38 38 39 39 #include <display.h> 40 #include <ui/fixed.h> 40 41 #include <ui/label.h> 41 42 #include <ui/pbutton.h> … … 47 48 ui_t *ui; 48 49 ui_window_t *window; 50 ui_fixed_t *fixed; 49 51 ui_label_t *label; 50 52 ui_pbutton_t *pb1; -
uspace/lib/ui/include/ui/label.h
rf03d1308 r8009dc27 40 40 #include <gfx/coord.h> 41 41 #include <gfx/text.h> 42 #include <types/ui/control.h> 42 43 #include <types/ui/label.h> 43 44 #include <types/ui/resource.h> … … 46 47 ui_label_t **); 47 48 extern void ui_label_destroy(ui_label_t *); 49 extern ui_control_t *ui_label_ctl(ui_label_t *); 48 50 extern void ui_label_set_rect(ui_label_t *, gfx_rect_t *); 49 51 extern void ui_label_set_halign(ui_label_t *, gfx_halign_t); -
uspace/lib/ui/include/ui/pbutton.h
rf03d1308 r8009dc27 40 40 #include <gfx/coord.h> 41 41 #include <io/pos_event.h> 42 #include <types/ui/control.h> 42 43 #include <types/ui/event.h> 43 44 #include <types/ui/pbutton.h> … … 48 49 ui_pbutton_t **); 49 50 extern void ui_pbutton_destroy(ui_pbutton_t *); 51 extern ui_control_t *ui_pbutton_ctl(ui_pbutton_t *); 50 52 extern void ui_pbutton_set_cb(ui_pbutton_t *, ui_pbutton_cb_t *, void *); 51 53 extern void ui_pbutton_set_rect(ui_pbutton_t *, gfx_rect_t *); -
uspace/lib/ui/meson.build
rf03d1308 r8009dc27 29 29 deps = [ 'gfx', 'gfxfont', 'display' ] 30 30 src = files( 31 'src/control.c', 31 32 'src/dummygc.c', 33 'src/fixed.c', 32 34 'src/label.c', 33 35 'src/paint.c', … … 40 42 41 43 test_src = files( 44 'test/control.c', 45 'test/fixed.c', 42 46 'test/label.c', 43 47 'test/main.c', -
uspace/lib/ui/private/label.h
rf03d1308 r8009dc27 46 46 */ 47 47 struct ui_label { 48 /** Base control object */ 49 struct ui_control *control; 48 50 /** UI resource */ 49 51 struct ui_resource *res; -
uspace/lib/ui/private/pbutton.h
rf03d1308 r8009dc27 46 46 */ 47 47 struct ui_pbutton { 48 /** Base control object */ 49 struct ui_control *control; 48 50 /** UI resource */ 49 51 struct ui_resource *res; -
uspace/lib/ui/src/label.c
rf03d1308 r8009dc27 40 40 #include <stdlib.h> 41 41 #include <str.h> 42 #include <ui/control.h> 42 43 #include <ui/paint.h> 43 44 #include <ui/label.h> … … 45 46 #include "../private/resource.h" 46 47 48 static ui_evclaim_t ui_label_ctl_pos_event(void *, pos_event_t *); 49 50 /** Label control ops */ 51 ui_control_ops_t ui_label_ops = { 52 .pos_event = ui_label_ctl_pos_event 53 }; 54 47 55 /** Create new label. 48 56 * … … 56 64 { 57 65 ui_label_t *label; 66 errno_t rc; 58 67 59 68 label = calloc(1, sizeof(ui_label_t)); … … 61 70 return ENOMEM; 62 71 72 rc = ui_control_new(&ui_label_ops, (void *) label, &label->control); 73 if (rc != EOK) { 74 free(label); 75 return rc; 76 } 77 63 78 label->text = str_dup(text); 64 79 if (label->text == NULL) { 80 ui_control_delete(label->control); 65 81 free(label); 66 82 return ENOMEM; … … 82 98 return; 83 99 100 ui_control_delete(label->control); 84 101 free(label); 102 } 103 104 /** Get base control from label. 105 * 106 * @param label Label 107 * @return Control 108 */ 109 ui_control_t *ui_label_ctl(ui_label_t *label) 110 { 111 return label->control; 85 112 } 86 113 … … 178 205 } 179 206 207 /** Handle label control position event. 208 * 209 * @param arg Argument (ui_label_t *) 210 * @param pos_event Position event 211 * @return @c ui_claimed iff the event is claimed 212 */ 213 ui_evclaim_t ui_label_ctl_pos_event(void *arg, pos_event_t *event) 214 { 215 ui_label_t *label = (ui_label_t *) arg; 216 217 (void) label; 218 return ui_unclaimed; 219 } 220 180 221 /** @} 181 222 */ -
uspace/lib/ui/src/pbutton.c
rf03d1308 r8009dc27 42 42 #include <stdlib.h> 43 43 #include <str.h> 44 #include <ui/control.h> 44 45 #include <ui/paint.h> 45 46 #include <ui/pbutton.h> … … 53 54 }; 54 55 56 static ui_evclaim_t ui_pbutton_ctl_pos_event(void *, pos_event_t *); 57 58 /** Push button control ops */ 59 ui_control_ops_t ui_pbutton_ops = { 60 .pos_event = ui_pbutton_ctl_pos_event 61 }; 62 55 63 /** Create new push button. 56 64 * … … 64 72 { 65 73 ui_pbutton_t *pbutton; 74 errno_t rc; 66 75 67 76 pbutton = calloc(1, sizeof(ui_pbutton_t)); … … 69 78 return ENOMEM; 70 79 80 rc = ui_control_new(&ui_pbutton_ops, (void *) pbutton, 81 &pbutton->control); 82 if (rc != EOK) { 83 free(pbutton); 84 return rc; 85 } 86 71 87 pbutton->caption = str_dup(caption); 72 88 if (pbutton->caption == NULL) { 89 ui_control_delete(pbutton->control); 73 90 free(pbutton); 74 91 return ENOMEM; … … 89 106 return; 90 107 108 ui_control_delete(pbutton->control); 91 109 free(pbutton); 110 } 111 112 /** Get base control from push button. 113 * 114 * @param pbutton Push button 115 * @return Control 116 */ 117 ui_control_t *ui_pbutton_ctl(ui_pbutton_t *pbutton) 118 { 119 return pbutton->control; 92 120 } 93 121 … … 388 416 } 389 417 418 /** Handle push button control position event. 419 * 420 * @param arg Argument (ui_pbutton_t *) 421 * @param pos_event Position event 422 * @return @c ui_claimed iff the event is claimed 423 */ 424 ui_evclaim_t ui_pbutton_ctl_pos_event(void *arg, pos_event_t *event) 425 { 426 ui_pbutton_t *pbutton = (ui_pbutton_t *) arg; 427 428 return ui_pbutton_pos_event(pbutton, event); 429 } 430 390 431 /** @} 391 432 */ -
uspace/lib/ui/test/main.c
rf03d1308 r8009dc27 31 31 PCUT_INIT; 32 32 33 PCUT_IMPORT(control); 34 PCUT_IMPORT(fixed); 33 35 PCUT_IMPORT(label); 34 36 PCUT_IMPORT(paint);
Note:
See TracChangeset
for help on using the changeset viewer.