Changeset fe5c7a1 in mainline


Ignore:
Timestamp:
2021-10-14T10:41:07Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Children:
03c4b23
Parents:
b9d689b
git-author:
Jiri Svoboda <jiri@…> (2021-10-13 18:40:48)
git-committer:
Jiri Svoboda <jiri@…> (2021-10-14 10:41:07)
Message:

Panel activation

Active panel can be switched using the Tab key. Mouse activation is
not implemented.

Location:
uspace/app/nav
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/nav.c

    rb9d689b rfe5c7a1  
    8181            ((event->mods & KM_SHIFT) == 0) &&
    8282            (event->mods & KM_CTRL) != 0) {
    83                 if (event->key == KC_Q)
     83                switch (event->key) {
     84                case KC_Q:
    8485                        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                }
    85101        }
    86102
     
    145161
    146162        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]);
    148165                if (rc != EOK)
    149166                        goto error;
     
    219236}
    220237
     238/** Get the currently active navigator panel.
     239 *
     240 * @param navigator Navigator
     241 * @return Currently active panel
     242 */
     243panel_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 */
     263void 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
    221274/** @}
    222275 */
  • uspace/app/nav/nav.h

    rb9d689b rfe5c7a1  
    3939#include <errno.h>
    4040#include "types/nav.h"
     41#include "types/panel.h"
    4142
    4243extern errno_t navigator_create(const char *, navigator_t **);
    4344extern void navigator_destroy(navigator_t *);
    4445extern errno_t navigator_run(const char *);
     46extern panel_t *navigator_get_active_panel(navigator_t *);
     47extern void navigator_switch_panel(navigator_t *);
    4548
    4649#endif
  • uspace/app/nav/panel.c

    rb9d689b rfe5c7a1  
    6363 *
    6464 * @param window Containing window
     65 * @param active @c true iff panel should be active
    6566 * @param rpanel Place to store pointer to new panel
    6667 * @return EOK on success or an error code
    6768 */
    68 errno_t panel_create(ui_window_t *window, panel_t **rpanel)
     69errno_t panel_create(ui_window_t *window, bool active, panel_t **rpanel)
    6970{
    7071        panel_t *panel;
     
    9091                goto error;
    9192
     93        rc = gfx_color_new_ega(0x0f, &panel->act_border_color);
     94        if (rc != EOK)
     95                goto error;
     96
    9297        panel->window = window;
    9398        list_initialize(&panel->entries);
    9499        panel->entries_cnt = 0;
     100        panel->active = active;
    95101        *rpanel = panel;
    96102        return EOK;
     
    113119        gfx_color_delete(panel->color);
    114120        gfx_color_delete(panel->curs_color);
     121        gfx_color_delete(panel->act_border_color);
    115122        panel_clear_entries(panel);
    116123        ui_control_delete(panel->control);
     
    147154        pos.y = panel->rect.p0.y + 1 + entry_idx - panel->page_idx;
    148155
    149         if (entry == panel->cursor)
     156        if (entry == panel->cursor && panel->active)
    150157                fmt.color = panel->curs_color;
    151158        else
     
    182189        gfx_text_fmt_t fmt;
    183190        panel_entry_t *entry;
     191        ui_box_style_t bstyle;
     192        gfx_color_t *bcolor;
    184193        int i, lines;
    185194        errno_t rc;
     
    195204                return rc;
    196205
    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);
    199215        if (rc != EOK)
    200216                return rc;
     
    228244ui_evclaim_t panel_kbd_event(panel_t *panel, kbd_event_t *event)
    229245{
     246        if (!panel->active)
     247                return ui_unclaimed;
     248
    230249        if (event->type == KEY_PRESS) {
    231250                if ((event->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
     
    255274        }
    256275
    257         return ui_unclaimed;
     276        return ui_claimed;
    258277}
    259278
     
    297316{
    298317        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 */
     325bool panel_is_active(panel_t *panel)
     326{
     327        return panel->active;
     328}
     329
     330/** Activate panel.
     331 *
     332 * @param panel Panel
     333 */
     334void 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 */
     344void panel_deactivate(panel_t *panel)
     345{
     346        panel->active = false;
     347        (void) panel_paint(panel);
    299348}
    300349
  • uspace/app/nav/panel.h

    rb9d689b rfe5c7a1  
    4343#include <ui/control.h>
    4444#include <ui/window.h>
     45#include <stdbool.h>
    4546#include "types/panel.h"
    4647
    47 extern errno_t panel_create(ui_window_t *, panel_t **);
     48extern errno_t panel_create(ui_window_t *, bool, panel_t **);
    4849extern void panel_destroy(panel_t *);
    4950extern errno_t panel_entry_paint(panel_entry_t *, size_t);
     
    5455extern void panel_set_rect(panel_t *, gfx_rect_t *);
    5556extern unsigned panel_page_size(panel_t *);
     57extern bool panel_is_active(panel_t *);
     58extern void panel_activate(panel_t *);
     59extern void panel_deactivate(panel_t *);
    5660extern errno_t panel_entry_append(panel_t *, const char *, uint64_t);
    5761extern void panel_entry_delete(panel_entry_t *);
  • uspace/app/nav/test/nav.c

    rb9d689b rfe5c7a1  
    4747}
    4848
     49/** navigator_get_active_panel() returns the active panel */
     50PCUT_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 */
     67PCUT_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
    4995PCUT_EXPORT(nav);
  • uspace/app/nav/test/panel.c

    rb9d689b rfe5c7a1  
    4646        errno_t rc;
    4747
    48         rc = panel_create(NULL, &panel);
     48        rc = panel_create(NULL, true, &panel);
    4949        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    5050
     
    7070        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    7171
    72         rc = panel_create(window, &panel);
     72        rc = panel_create(window, true, &panel);
    7373        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    7474
     
    102102        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    103103
    104         rc = panel_create(window, &panel);
     104        rc = panel_create(window, true, &panel);
    105105        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    106106
     
    120120        errno_t rc;
    121121
    122         rc = panel_create(NULL, &panel);
     122        rc = panel_create(NULL, true, &panel);
    123123        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    124124
     
    133133{
    134134        panel_t *panel;
    135         ui_control_t *control;
    136135        ui_evclaim_t claimed;
    137136        kbd_event_t event;
    138137        errno_t rc;
    139138
    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);
    145143
    146144        event.type = KEY_PRESS;
     
    150148
    151149        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);
    152165        PCUT_ASSERT_EQUALS(ui_unclaimed, claimed);
    153166
     
    159172{
    160173        panel_t *panel;
    161         ui_control_t *control;
    162174        ui_evclaim_t claimed;
    163175        pos_event_t event;
    164176        errno_t rc;
    165177
    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);
    171180
    172181        event.pos_id = 0;
     
    186195{
    187196        panel_t *panel;
    188         ui_control_t *control;
    189197        gfx_rect_t rect;
    190198        errno_t rc;
    191199
    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);
    197202
    198203        rect.p0.x = 1;
     
    214219{
    215220        panel_t *panel;
    216         ui_control_t *control;
    217221        gfx_rect_t rect;
    218222        errno_t rc;
    219223
    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);
    225226
    226227        rect.p0.x = 10;
     
    237238}
    238239
     240/** panel_is_active() returns panel activity state */
     241PCUT_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 */
     258PCUT_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(&params);
     270        params.caption = "Test";
     271
     272        rc = ui_window_create(ui, &params, &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 */
     288PCUT_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(&params);
     300        params.caption = "Test";
     301
     302        rc = ui_window_create(ui, &params, &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
    239317/** panel_entry_append() appends new entry */
    240318PCUT_TEST(entry_append)
     
    243321        errno_t rc;
    244322
    245         rc = panel_create(NULL, &panel);
     323        rc = panel_create(NULL, true, &panel);
    246324        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    247325
     
    266344        errno_t rc;
    267345
    268         rc = panel_create(NULL, &panel);
     346        rc = panel_create(NULL, true, &panel);
    269347        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    270348
     
    296374        errno_t rc;
    297375
    298         rc = panel_create(NULL, &panel);
     376        rc = panel_create(NULL, true, &panel);
    299377        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    300378
     
    345423        PCUT_ASSERT_INT_EQUALS(0, rv);
    346424
    347         rc = panel_create(NULL, &panel);
     425        rc = panel_create(NULL, true, &panel);
    348426        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    349427
     
    375453        errno_t rc;
    376454
    377         rc = panel_create(NULL, &panel);
     455        rc = panel_create(NULL, true, &panel);
    378456        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    379457
     
    411489        errno_t rc;
    412490
    413         rc = panel_create(NULL, &panel);
     491        rc = panel_create(NULL, true, &panel);
    414492        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    415493
     
    447525        errno_t rc;
    448526
    449         rc = panel_create(NULL, &panel);
     527        rc = panel_create(NULL, true, &panel);
    450528        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    451529
     
    484562        errno_t rc;
    485563
    486         rc = panel_create(NULL, &panel);
     564        rc = panel_create(NULL, true, &panel);
    487565        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    488566
     
    538616        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    539617
    540         rc = panel_create(window, &panel);
     618        rc = panel_create(window, true, &panel);
    541619        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    542620
     
    619697        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    620698
    621         rc = panel_create(window, &panel);
     699        rc = panel_create(window, true, &panel);
    622700        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    623701
     
    702780        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    703781
    704         rc = panel_create(window, &panel);
     782        rc = panel_create(window, true, &panel);
    705783        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    706784
     
    763841        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    764842
    765         rc = panel_create(window, &panel);
     843        rc = panel_create(window, true, &panel);
    766844        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    767845
     
    825903        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    826904
    827         rc = panel_create(window, &panel);
     905        rc = panel_create(window, true, &panel);
    828906        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    829907
     
    913991        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    914992
    915         rc = panel_create(window, &panel);
     993        rc = panel_create(window, true, &panel);
    916994        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    917995
  • uspace/app/nav/types/nav.h

    rb9d689b rfe5c7a1  
    4141#include <ui/window.h>
    4242
     43enum {
     44        navigator_panels = 2
     45};
     46
    4347/** Navigator */
    4448typedef struct navigator {
     
    5256        struct nav_menu *menu;
    5357        /** Panels */
    54         struct panel *panel[2];
     58        struct panel *panel[navigator_panels];
    5559} navigator_t;
    5660
  • uspace/app/nav/types/panel.h

    rb9d689b rfe5c7a1  
    7575        gfx_color_t *curs_color;
    7676
     77        /** Active border color */
     78        gfx_color_t *act_border_color;
     79
    7780        /** Panel entries (list of panel_entry_t) */
    7881        list_t entries;
     
    9295        /** Index of entry under cursor */
    9396        size_t cursor_idx;
     97
     98        /** @c true iff the panel is active */
     99        bool active;
    94100} panel_t;
    95101
Note: See TracChangeset for help on using the changeset viewer.