Changeset 0e5ed803 in mainline
- Timestamp:
- 2021-10-04T20:39:24Z (3 years ago)
- Children:
- 3b67e95
- Parents:
- 68b9e540
- Location:
- uspace/app/nav
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/nav.c
r68b9e540 r0e5ed803 45 45 #include "menu.h" 46 46 #include "nav.h" 47 #include "panel.h" 47 48 48 49 static void wnd_close(ui_window_t *, void *); … … 75 76 navigator_t *navigator; 76 77 ui_wnd_params_t params; 78 gfx_rect_t rect; 79 unsigned i; 77 80 errno_t rc; 78 81 … … 118 121 } 119 122 123 for (i = 0; i < 2; i++) { 124 rc = panel_create(navigator->window, &navigator->panel[i]); 125 if (rc != EOK) 126 goto error; 127 128 rect.p0.x = 40 * i; 129 rect.p0.y = 1; 130 rect.p1.x = 40 * (i + 1); 131 rect.p1.y = 24; 132 panel_set_rect(navigator->panel[i], &rect); 133 134 rc = ui_fixed_add(navigator->fixed, 135 panel_ctl(navigator->panel[i])); 136 if (rc != EOK) { 137 printf("Error adding control to layout.\n"); 138 return rc; 139 } 140 } 141 120 142 rc = ui_window_paint(navigator->window); 121 143 if (rc != EOK) { … … 133 155 void navigator_destroy(navigator_t *navigator) 134 156 { 157 unsigned i; 158 159 for (i = 0; i < 2; i++) { 160 ui_fixed_remove(navigator->fixed, 161 panel_ctl(navigator->panel[i])); 162 panel_destroy(navigator->panel[i]); 163 } 164 135 165 ui_fixed_remove(navigator->fixed, nav_menu_ctl(navigator->menu)); 136 166 -
uspace/app/nav/nav.h
r68b9e540 r0e5ed803 53 53 /** Menu */ 54 54 struct nav_menu *menu; 55 /** Panels */ 56 struct panel *panel[2]; 55 57 } navigator_t; 56 58 … … 59 61 extern errno_t navigator_run(const char *); 60 62 61 62 63 #endif 63 64 -
uspace/app/nav/panel.c
r68b9e540 r0e5ed803 36 36 37 37 #include <errno.h> 38 #include <gfx/render.h> 38 39 #include <stdlib.h> 40 #include <ui/control.h> 41 #include <ui/paint.h> 39 42 #include "panel.h" 40 43 #include "nav.h" 41 44 45 static void panel_ctl_destroy(void *); 46 static errno_t panel_ctl_paint(void *); 47 static ui_evclaim_t panel_ctl_pos_event(void *, pos_event_t *); 48 49 /** Panel control ops */ 50 ui_control_ops_t panel_ctl_ops = { 51 .destroy = panel_ctl_destroy, 52 .paint = panel_ctl_paint, 53 .pos_event = panel_ctl_pos_event 54 }; 55 42 56 /** Create panel. 43 57 * 58 * @param window Containing window 44 59 * @param rpanel Place to store pointer to new panel 45 60 * @return EOK on success or an error code 46 61 */ 47 errno_t panel_create( panel_t **rpanel)62 errno_t panel_create(ui_window_t *window, panel_t **rpanel) 48 63 { 49 64 panel_t *panel; 65 errno_t rc; 50 66 51 67 panel = calloc(1, sizeof(panel_t)); … … 53 69 return ENOMEM; 54 70 71 rc = ui_control_new(&panel_ctl_ops, (void *)panel, 72 &panel->control); 73 if (rc != EOK) { 74 free(panel); 75 return rc; 76 } 77 78 rc = gfx_color_new_ega(0x07, &panel->color); 79 if (rc != EOK) 80 goto error; 81 82 panel->window = window; 55 83 *rpanel = panel; 56 84 return EOK; 85 error: 86 ui_control_delete(panel->control); 87 free(panel); 88 return rc; 57 89 } 58 90 … … 63 95 void panel_destroy(panel_t *panel) 64 96 { 97 ui_control_delete(panel->control); 65 98 free(panel); 66 99 } 67 100 101 /** Paint panel. 102 * 103 * @param panel Panel 104 */ 105 errno_t panel_paint(panel_t *panel) 106 { 107 gfx_context_t *gc = ui_window_get_gc(panel->window); 108 ui_resource_t *res = ui_window_get_res(panel->window); 109 errno_t rc; 110 111 rc = gfx_set_color(gc, panel->color); 112 if (rc != EOK) 113 return rc; 114 115 rc = gfx_fill_rect(gc, &panel->rect); 116 if (rc != EOK) 117 return rc; 118 119 rc = ui_paint_text_box(res, &panel->rect, ui_box_single, 120 panel->color); 121 if (rc != EOK) 122 return rc; 123 124 rc = gfx_update(gc); 125 if (rc != EOK) 126 return rc; 127 128 return EOK; 129 } 130 131 /** Handle panel position event. 132 * 133 * @param panel Panel 134 * @param event Position event 135 * @return ui_claimed iff event was claimed 136 */ 137 ui_evclaim_t panel_pos_event(panel_t *panel, pos_event_t *event) 138 { 139 return ui_unclaimed; 140 } 141 142 /** Get base control for panel. 143 * 144 * @param panel Panel 145 * @return Base UI control 146 */ 147 ui_control_t *panel_ctl(panel_t *panel) 148 { 149 return panel->control; 150 } 151 152 /** Set panel rectangle. 153 * 154 * @param panel Panel 155 * @param rect Rectangle 156 */ 157 void panel_set_rect(panel_t *panel, gfx_rect_t *rect) 158 { 159 panel->rect = *rect; 160 } 161 162 /** Destroy panel control. 163 * 164 * @param arg Argument (panel_t *) 165 */ 166 void panel_ctl_destroy(void *arg) 167 { 168 panel_t *panel = (panel_t *) arg; 169 170 panel_destroy(panel); 171 } 172 173 /** Paint panel control. 174 * 175 * @param arg Argument (panel_t *) 176 * @return EOK on success or an error code 177 */ 178 errno_t panel_ctl_paint(void *arg) 179 { 180 panel_t *panel = (panel_t *) arg; 181 182 return panel_paint(panel); 183 } 184 185 /** Handle panel control position event. 186 * 187 * @param arg Argument (panel_t *) 188 * @param pos_event Position event 189 * @return @c ui_claimed iff the event is claimed 190 */ 191 ui_evclaim_t panel_ctl_pos_event(void *arg, pos_event_t *event) 192 { 193 panel_t *panel = (panel_t *) arg; 194 195 return panel_pos_event(panel, event); 196 } 197 198 68 199 /** @} 69 200 */ -
uspace/app/nav/panel.h
r68b9e540 r0e5ed803 40 40 #include <gfx/color.h> 41 41 #include <gfx/coord.h> 42 #include <io/pos_event.h> 42 43 #include <ui/control.h> 44 #include <ui/window.h> 43 45 #include "nav.h" 44 46 #include "panel.h" … … 48 50 * This is a custom UI control. 49 51 */ 50 typedef struct {52 typedef struct panel { 51 53 /** Base control object */ 52 54 struct ui_control *control; 55 56 /** Containing window */ 57 ui_window_t *window; 53 58 54 59 /** Panel rectangle */ … … 59 64 } panel_t; 60 65 61 extern errno_t panel_create( panel_t **);66 extern errno_t panel_create(ui_window_t *, panel_t **); 62 67 extern void panel_destroy(panel_t *); 68 extern errno_t panel_paint(panel_t *); 69 extern ui_evclaim_t panel_pos_event(panel_t *, pos_event_t *); 70 extern ui_control_t *panel_ctl(panel_t *); 71 extern void panel_set_rect(panel_t *, gfx_rect_t *); 63 72 64 73 #endif -
uspace/app/nav/test/menu.c
r68b9e540 r0e5ed803 57 57 58 58 nav_menu_destroy(menu); 59 ui_window_destroy(window); 60 ui_destroy(ui); 59 61 } 60 62 -
uspace/app/nav/test/panel.c
r68b9e540 r0e5ed803 41 41 errno_t rc; 42 42 43 rc = panel_create( &panel);43 rc = panel_create(NULL, &panel); 44 44 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 45 45 … … 47 47 } 48 48 49 50 /** Test panel_paint() */ 51 PCUT_TEST(paint) 52 { 53 ui_t *ui; 54 ui_window_t *window; 55 ui_wnd_params_t params; 56 panel_t *panel; 57 errno_t rc; 58 59 rc = ui_create_disp(NULL, &ui); 60 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 61 62 ui_wnd_params_init(¶ms); 63 params.caption = "Test"; 64 65 rc = ui_window_create(ui, ¶ms, &window); 66 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 67 68 rc = panel_create(window, &panel); 69 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 70 71 rc = panel_paint(panel); 72 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 73 74 panel_destroy(panel); 75 ui_window_destroy(window); 76 ui_destroy(ui); 77 } 78 79 /** panel_ctl() returns a valid UI control */ 80 PCUT_TEST(ctl) 81 { 82 panel_t *panel; 83 ui_control_t *control; 84 errno_t rc; 85 86 rc = panel_create(NULL, &panel); 87 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 88 89 control = panel_ctl(panel); 90 PCUT_ASSERT_NOT_NULL(control); 91 92 panel_destroy(panel); 93 } 94 95 /** Test panel_pos_event() */ 96 PCUT_TEST(pos_event) 97 { 98 panel_t *panel; 99 ui_control_t *control; 100 ui_evclaim_t claimed; 101 pos_event_t event; 102 errno_t rc; 103 104 rc = panel_create(NULL, &panel); 105 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 106 107 control = panel_ctl(panel); 108 PCUT_ASSERT_NOT_NULL(control); 109 110 claimed = panel_pos_event(panel, &event); 111 PCUT_ASSERT_EQUALS(ui_unclaimed, claimed); 112 113 panel_destroy(panel); 114 } 115 116 /** panel_set_rect() sets internal field */ 117 PCUT_TEST(set_rect) 118 { 119 panel_t *panel; 120 ui_control_t *control; 121 gfx_rect_t rect; 122 errno_t rc; 123 124 rc = panel_create(NULL, &panel); 125 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 126 127 control = panel_ctl(panel); 128 PCUT_ASSERT_NOT_NULL(control); 129 130 rect.p0.x = 1; 131 rect.p0.y = 2; 132 rect.p1.x = 3; 133 rect.p1.y = 4; 134 135 panel_set_rect(panel, &rect); 136 PCUT_ASSERT_INT_EQUALS(rect.p0.x, panel->rect.p0.x); 137 PCUT_ASSERT_INT_EQUALS(rect.p0.y, panel->rect.p0.y); 138 PCUT_ASSERT_INT_EQUALS(rect.p1.x, panel->rect.p1.x); 139 PCUT_ASSERT_INT_EQUALS(rect.p1.y, panel->rect.p1.y); 140 141 panel_destroy(panel); 142 } 143 49 144 PCUT_EXPORT(panel);
Note:
See TracChangeset
for help on using the changeset viewer.