Changeset 692c7f40 in mainline
- Timestamp:
- 2021-10-25T00:32:45Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1eb0fafe
- Parents:
- 2fb49522
- git-author:
- Jiri Svoboda <jiri@…> (2021-10-13 18:40:48)
- git-committer:
- jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
- Location:
- uspace/app/nav
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/nav.c
r2fb49522 r692c7f40 81 81 ((event->mods & KM_SHIFT) == 0) && 82 82 (event->mods & KM_CTRL) != 0) { 83 if (event->key == KC_Q) 83 switch (event->key) { 84 case KC_Q: 84 85 ui_quit(navigator->ui); 86 break; 87 default: 88 break; 89 } 90 } 91 92 if (event->type == KEY_PRESS && 93 ((event->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0)) { 94 switch (event->key) { 95 case KC_TAB: 96 navigator_switch_panel(navigator); 97 break; 98 default: 99 break; 100 } 85 101 } 86 102 … … 145 161 146 162 for (i = 0; i < 2; i++) { 147 rc = panel_create(navigator->window, &navigator->panel[i]); 163 rc = panel_create(navigator->window, i == 0, 164 &navigator->panel[i]); 148 165 if (rc != EOK) 149 166 goto error; … … 219 236 } 220 237 238 /** Get the currently active navigator panel. 239 * 240 * @param navigator Navigator 241 * @return Currently active panel 242 */ 243 panel_t *navigator_get_active_panel(navigator_t *navigator) 244 { 245 int i; 246 247 for (i = 0; i < navigator_panels; i++) { 248 if (panel_is_active(navigator->panel[i])) 249 return navigator->panel[i]; 250 } 251 252 /* This should not happen */ 253 assert(false); 254 return NULL; 255 } 256 257 /** Switch to another navigator panel. 258 * 259 * Changes the currently active navigator panel to the next panel. 260 * 261 * @param navigator Navigator 262 */ 263 void navigator_switch_panel(navigator_t *navigator) 264 { 265 if (panel_is_active(navigator->panel[0])) { 266 panel_deactivate(navigator->panel[0]); 267 panel_activate(navigator->panel[1]); 268 } else { 269 panel_deactivate(navigator->panel[1]); 270 panel_activate(navigator->panel[0]); 271 } 272 } 273 221 274 /** @} 222 275 */ -
uspace/app/nav/nav.h
r2fb49522 r692c7f40 39 39 #include <errno.h> 40 40 #include "types/nav.h" 41 #include "types/panel.h" 41 42 42 43 extern errno_t navigator_create(const char *, navigator_t **); 43 44 extern void navigator_destroy(navigator_t *); 44 45 extern errno_t navigator_run(const char *); 46 extern panel_t *navigator_get_active_panel(navigator_t *); 47 extern void navigator_switch_panel(navigator_t *); 45 48 46 49 #endif -
uspace/app/nav/panel.c
r2fb49522 r692c7f40 63 63 * 64 64 * @param window Containing window 65 * @param active @c true iff panel should be active 65 66 * @param rpanel Place to store pointer to new panel 66 67 * @return EOK on success or an error code 67 68 */ 68 errno_t panel_create(ui_window_t *window, panel_t **rpanel)69 errno_t panel_create(ui_window_t *window, bool active, panel_t **rpanel) 69 70 { 70 71 panel_t *panel; … … 90 91 goto error; 91 92 93 rc = gfx_color_new_ega(0x0f, &panel->act_border_color); 94 if (rc != EOK) 95 goto error; 96 92 97 panel->window = window; 93 98 list_initialize(&panel->entries); 94 99 panel->entries_cnt = 0; 100 panel->active = active; 95 101 *rpanel = panel; 96 102 return EOK; … … 113 119 gfx_color_delete(panel->color); 114 120 gfx_color_delete(panel->curs_color); 121 gfx_color_delete(panel->act_border_color); 115 122 panel_clear_entries(panel); 116 123 ui_control_delete(panel->control); … … 147 154 pos.y = panel->rect.p0.y + 1 + entry_idx - panel->page_idx; 148 155 149 if (entry == panel->cursor )156 if (entry == panel->cursor && panel->active) 150 157 fmt.color = panel->curs_color; 151 158 else … … 182 189 gfx_text_fmt_t fmt; 183 190 panel_entry_t *entry; 191 ui_box_style_t bstyle; 192 gfx_color_t *bcolor; 184 193 int i, lines; 185 194 errno_t rc; … … 195 204 return rc; 196 205 197 rc = ui_paint_text_box(res, &panel->rect, ui_box_single, 198 panel->color); 206 if (panel->active) { 207 bstyle = ui_box_double; 208 bcolor = panel->act_border_color; 209 } else { 210 bstyle = ui_box_single; 211 bcolor = panel->color; 212 } 213 214 rc = ui_paint_text_box(res, &panel->rect, bstyle, bcolor); 199 215 if (rc != EOK) 200 216 return rc; … … 228 244 ui_evclaim_t panel_kbd_event(panel_t *panel, kbd_event_t *event) 229 245 { 246 if (!panel->active) 247 return ui_unclaimed; 248 230 249 if (event->type == KEY_PRESS) { 231 250 if ((event->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) { … … 255 274 } 256 275 257 return ui_ unclaimed;276 return ui_claimed; 258 277 } 259 278 … … 297 316 { 298 317 return panel->rect.p1.y - panel->rect.p0.y - 2; 318 } 319 320 /** Determine if panel is active. 321 * 322 * @param panel Panel 323 * @return @c true iff panel is active 324 */ 325 bool panel_is_active(panel_t *panel) 326 { 327 return panel->active; 328 } 329 330 /** Activate panel. 331 * 332 * @param panel Panel 333 */ 334 void panel_activate(panel_t *panel) 335 { 336 panel->active = true; 337 (void) panel_paint(panel); 338 } 339 340 /** Deactivate panel. 341 * 342 * @param panel Panel 343 */ 344 void panel_deactivate(panel_t *panel) 345 { 346 panel->active = false; 347 (void) panel_paint(panel); 299 348 } 300 349 -
uspace/app/nav/panel.h
r2fb49522 r692c7f40 43 43 #include <ui/control.h> 44 44 #include <ui/window.h> 45 #include <stdbool.h> 45 46 #include "types/panel.h" 46 47 47 extern errno_t panel_create(ui_window_t *, panel_t **);48 extern errno_t panel_create(ui_window_t *, bool, panel_t **); 48 49 extern void panel_destroy(panel_t *); 49 50 extern errno_t panel_entry_paint(panel_entry_t *, size_t); … … 54 55 extern void panel_set_rect(panel_t *, gfx_rect_t *); 55 56 extern unsigned panel_page_size(panel_t *); 57 extern bool panel_is_active(panel_t *); 58 extern void panel_activate(panel_t *); 59 extern void panel_deactivate(panel_t *); 56 60 extern errno_t panel_entry_append(panel_t *, const char *, uint64_t); 57 61 extern void panel_entry_delete(panel_entry_t *); -
uspace/app/nav/test/nav.c
r2fb49522 r692c7f40 47 47 } 48 48 49 /** navigator_get_active_panel() returns the active panel */ 50 PCUT_TEST(get_active_panel) 51 { 52 navigator_t *nav; 53 panel_t *panel; 54 errno_t rc; 55 56 rc = navigator_create(UI_DISPLAY_NULL, &nav); 57 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 58 59 /* First panel should be active at the beginning */ 60 panel = navigator_get_active_panel(nav); 61 PCUT_ASSERT_EQUALS(nav->panel[0], panel); 62 63 navigator_destroy(nav); 64 } 65 66 /** navigator_switch_panel() switches to a different panel */ 67 PCUT_TEST(switch_panel) 68 { 69 navigator_t *nav; 70 panel_t *panel; 71 errno_t rc; 72 73 rc = navigator_create(UI_DISPLAY_NULL, &nav); 74 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 75 76 /* First panel should be active at the beginning */ 77 panel = navigator_get_active_panel(nav); 78 PCUT_ASSERT_EQUALS(nav->panel[0], panel); 79 80 navigator_switch_panel(nav); 81 82 /* Second panel should be active now */ 83 panel = navigator_get_active_panel(nav); 84 PCUT_ASSERT_EQUALS(nav->panel[1], panel); 85 86 navigator_switch_panel(nav); 87 88 /* First panel should be active again */ 89 panel = navigator_get_active_panel(nav); 90 PCUT_ASSERT_EQUALS(nav->panel[0], panel); 91 92 navigator_destroy(nav); 93 } 94 49 95 PCUT_EXPORT(nav); -
uspace/app/nav/test/panel.c
r2fb49522 r692c7f40 46 46 errno_t rc; 47 47 48 rc = panel_create(NULL, &panel);48 rc = panel_create(NULL, true, &panel); 49 49 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 50 50 … … 70 70 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 71 71 72 rc = panel_create(window, &panel);72 rc = panel_create(window, true, &panel); 73 73 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 74 74 … … 102 102 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 103 103 104 rc = panel_create(window, &panel);104 rc = panel_create(window, true, &panel); 105 105 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 106 106 … … 120 120 errno_t rc; 121 121 122 rc = panel_create(NULL, &panel);122 rc = panel_create(NULL, true, &panel); 123 123 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 124 124 … … 133 133 { 134 134 panel_t *panel; 135 ui_control_t *control;136 135 ui_evclaim_t claimed; 137 136 kbd_event_t event; 138 137 errno_t rc; 139 138 140 rc = panel_create(NULL, &panel); 141 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 142 143 control = panel_ctl(panel); 144 PCUT_ASSERT_NOT_NULL(control); 139 /* Active panel should claim events */ 140 141 rc = panel_create(NULL, true, &panel); 142 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 143 146 144 event.type = KEY_PRESS; … … 150 148 151 149 claimed = panel_kbd_event(panel, &event); 150 PCUT_ASSERT_EQUALS(ui_claimed, claimed); 151 152 panel_destroy(panel); 153 154 /* Inactive panel should not claim events */ 155 156 rc = panel_create(NULL, false, &panel); 157 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 158 159 event.type = KEY_PRESS; 160 event.key = KC_ENTER; 161 event.mods = 0; 162 event.c = '\0'; 163 164 claimed = panel_kbd_event(panel, &event); 152 165 PCUT_ASSERT_EQUALS(ui_unclaimed, claimed); 153 166 … … 159 172 { 160 173 panel_t *panel; 161 ui_control_t *control;162 174 ui_evclaim_t claimed; 163 175 pos_event_t event; 164 176 errno_t rc; 165 177 166 rc = panel_create(NULL, &panel); 167 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 168 169 control = panel_ctl(panel); 170 PCUT_ASSERT_NOT_NULL(control); 178 rc = panel_create(NULL, true, &panel); 179 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 171 180 172 181 event.pos_id = 0; … … 186 195 { 187 196 panel_t *panel; 188 ui_control_t *control;189 197 gfx_rect_t rect; 190 198 errno_t rc; 191 199 192 rc = panel_create(NULL, &panel); 193 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 194 195 control = panel_ctl(panel); 196 PCUT_ASSERT_NOT_NULL(control); 200 rc = panel_create(NULL, true, &panel); 201 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 197 202 198 203 rect.p0.x = 1; … … 214 219 { 215 220 panel_t *panel; 216 ui_control_t *control;217 221 gfx_rect_t rect; 218 222 errno_t rc; 219 223 220 rc = panel_create(NULL, &panel); 221 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 222 223 control = panel_ctl(panel); 224 PCUT_ASSERT_NOT_NULL(control); 224 rc = panel_create(NULL, true, &panel); 225 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 225 226 226 227 rect.p0.x = 10; … … 237 238 } 238 239 240 /** panel_is_active() returns panel activity state */ 241 PCUT_TEST(is_active) 242 { 243 panel_t *panel; 244 errno_t rc; 245 246 rc = panel_create(NULL, true, &panel); 247 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 248 PCUT_ASSERT_TRUE(panel_is_active(panel)); 249 panel_destroy(panel); 250 251 rc = panel_create(NULL, false, &panel); 252 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 253 PCUT_ASSERT_FALSE(panel_is_active(panel)); 254 panel_destroy(panel); 255 } 256 257 /** panel_activate() activates panel */ 258 PCUT_TEST(activate) 259 { 260 ui_t *ui; 261 ui_window_t *window; 262 ui_wnd_params_t params; 263 panel_t *panel; 264 errno_t rc; 265 266 rc = ui_create_disp(NULL, &ui); 267 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 268 269 ui_wnd_params_init(¶ms); 270 params.caption = "Test"; 271 272 rc = ui_window_create(ui, ¶ms, &window); 273 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 274 275 rc = panel_create(window, false, &panel); 276 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 277 278 PCUT_ASSERT_FALSE(panel_is_active(panel)); 279 panel_activate(panel); 280 PCUT_ASSERT_TRUE(panel_is_active(panel)); 281 282 panel_destroy(panel); 283 ui_window_destroy(window); 284 ui_destroy(ui); 285 } 286 287 /** panel_deactivate() deactivates panel */ 288 PCUT_TEST(deactivate) 289 { 290 ui_t *ui; 291 ui_window_t *window; 292 ui_wnd_params_t params; 293 panel_t *panel; 294 errno_t rc; 295 296 rc = ui_create_disp(NULL, &ui); 297 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 298 299 ui_wnd_params_init(¶ms); 300 params.caption = "Test"; 301 302 rc = ui_window_create(ui, ¶ms, &window); 303 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 304 305 rc = panel_create(window, true, &panel); 306 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 307 308 PCUT_ASSERT_TRUE(panel_is_active(panel)); 309 panel_deactivate(panel); 310 PCUT_ASSERT_FALSE(panel_is_active(panel)); 311 312 panel_destroy(panel); 313 ui_window_destroy(window); 314 ui_destroy(ui); 315 } 316 239 317 /** panel_entry_append() appends new entry */ 240 318 PCUT_TEST(entry_append) … … 243 321 errno_t rc; 244 322 245 rc = panel_create(NULL, &panel);323 rc = panel_create(NULL, true, &panel); 246 324 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 247 325 … … 266 344 errno_t rc; 267 345 268 rc = panel_create(NULL, &panel);346 rc = panel_create(NULL, true, &panel); 269 347 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 270 348 … … 296 374 errno_t rc; 297 375 298 rc = panel_create(NULL, &panel);376 rc = panel_create(NULL, true, &panel); 299 377 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 300 378 … … 345 423 PCUT_ASSERT_INT_EQUALS(0, rv); 346 424 347 rc = panel_create(NULL, &panel);425 rc = panel_create(NULL, true, &panel); 348 426 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 349 427 … … 375 453 errno_t rc; 376 454 377 rc = panel_create(NULL, &panel);455 rc = panel_create(NULL, true, &panel); 378 456 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 379 457 … … 411 489 errno_t rc; 412 490 413 rc = panel_create(NULL, &panel);491 rc = panel_create(NULL, true, &panel); 414 492 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 415 493 … … 447 525 errno_t rc; 448 526 449 rc = panel_create(NULL, &panel);527 rc = panel_create(NULL, true, &panel); 450 528 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 451 529 … … 484 562 errno_t rc; 485 563 486 rc = panel_create(NULL, &panel);564 rc = panel_create(NULL, true, &panel); 487 565 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 488 566 … … 538 616 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 539 617 540 rc = panel_create(window, &panel);618 rc = panel_create(window, true, &panel); 541 619 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 542 620 … … 619 697 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 620 698 621 rc = panel_create(window, &panel);699 rc = panel_create(window, true, &panel); 622 700 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 623 701 … … 702 780 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 703 781 704 rc = panel_create(window, &panel);782 rc = panel_create(window, true, &panel); 705 783 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 706 784 … … 763 841 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 764 842 765 rc = panel_create(window, &panel);843 rc = panel_create(window, true, &panel); 766 844 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 767 845 … … 825 903 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 826 904 827 rc = panel_create(window, &panel);905 rc = panel_create(window, true, &panel); 828 906 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 829 907 … … 913 991 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 914 992 915 rc = panel_create(window, &panel);993 rc = panel_create(window, true, &panel); 916 994 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 917 995 -
uspace/app/nav/types/nav.h
r2fb49522 r692c7f40 41 41 #include <ui/window.h> 42 42 43 enum { 44 navigator_panels = 2 45 }; 46 43 47 /** Navigator */ 44 48 typedef struct navigator { … … 52 56 struct nav_menu *menu; 53 57 /** Panels */ 54 struct panel *panel[ 2];58 struct panel *panel[navigator_panels]; 55 59 } navigator_t; 56 60 -
uspace/app/nav/types/panel.h
r2fb49522 r692c7f40 75 75 gfx_color_t *curs_color; 76 76 77 /** Active border color */ 78 gfx_color_t *act_border_color; 79 77 80 /** Panel entries (list of panel_entry_t) */ 78 81 list_t entries; … … 92 95 /** Index of entry under cursor */ 93 96 size_t cursor_idx; 97 98 /** @c true iff the panel is active */ 99 bool active; 94 100 } panel_t; 95 101
Note:
See TracChangeset
for help on using the changeset viewer.