Changeset 966a27d3 in mainline


Ignore:
Timestamp:
2021-10-22T07:45:13Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Children:
8922b76
Parents:
2651dc5
git-author:
Jiri Svoboda <jiri@…> (2021-10-21 17:44:55)
git-committer:
Jiri Svoboda <jiri@…> (2021-10-22 07:45:13)
Message:

Activating panel using the mouse

Location:
uspace/app/nav
Files:
5 edited

Legend:

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

    r2651dc5 r966a27d3  
    6363};
    6464
     65static void navigator_panel_activate_req(void *, panel_t *);
     66
     67static panel_cb_t navigator_panel_cb = {
     68        .activate_req = navigator_panel_activate_req
     69};
     70
    6571/** Window close button was clicked.
    6672 *
     
    183189                panel_set_rect(navigator->panel[i], &rect);
    184190
     191                panel_set_cb(navigator->panel[i], &navigator_panel_cb,
     192                    navigator);
     193
    185194                rc = ui_fixed_add(navigator->fixed,
    186195                    panel_ctl(navigator->panel[i]));
     
    307316}
    308317
     318/** Panel callback requesting panel activation.
     319 *
     320 * @param arg Argument (navigator_t *)
     321 * @param panel Panel
     322 */
     323void navigator_panel_activate_req(void *arg, panel_t *panel)
     324{
     325        navigator_t *navigator = (navigator_t *)arg;
     326
     327        if (!panel_is_active(panel))
     328                navigator_switch_panel(navigator);
     329}
     330
    309331/** @}
    310332 */
  • uspace/app/nav/panel.c

    r2651dc5 r966a27d3  
    142142        ui_control_delete(panel->control);
    143143        free(panel);
     144}
     145
     146/** Set panel callbacks.
     147 *
     148 * @param panel Panel
     149 * @param cb Callbacks
     150 * @param arg Argument to callback functions
     151 */
     152void panel_set_cb(panel_t *panel, panel_cb_t *cb, void *arg)
     153{
     154        panel->cb = cb;
     155        panel->cb_arg = arg;
    144156}
    145157
     
    311323ui_evclaim_t panel_pos_event(panel_t *panel, pos_event_t *event)
    312324{
    313         return ui_unclaimed;
     325        gfx_coord2_t pos;
     326
     327        pos.x = event->hpos;
     328        pos.y = event->vpos;
     329        if (!gfx_pix_inside_rect(&pos, &panel->rect))
     330                return ui_unclaimed;
     331
     332        if (!panel->active) {
     333                panel_activate_req(panel);
     334        }
     335
     336        return ui_claimed;
    314337}
    315338
     
    11141137}
    11151138
     1139/** Request panel activation.
     1140 *
     1141 * Call back to request panel activation.
     1142 *
     1143 * @param panel Panel
     1144 */
     1145void panel_activate_req(panel_t *panel)
     1146{
     1147        if (panel->cb != NULL && panel->cb->activate_req != NULL)
     1148                panel->cb->activate_req(panel->cb_arg, panel);
     1149}
     1150
    11161151/** @}
    11171152 */
  • uspace/app/nav/panel.h

    r2651dc5 r966a27d3  
    4848extern errno_t panel_create(ui_window_t *, bool, panel_t **);
    4949extern void panel_destroy(panel_t *);
     50extern void panel_set_cb(panel_t *, panel_cb_t *, void *);
    5051extern errno_t panel_entry_paint(panel_entry_t *, size_t);
    5152extern errno_t panel_paint(panel_t *);
     
    7980extern errno_t panel_open_dir(panel_t *, panel_entry_t *);
    8081extern errno_t panel_open_file(panel_t *, panel_entry_t *);
     82extern void panel_activate_req(panel_t *);
     83
    8184
    8285#endif
  • uspace/app/nav/test/panel.c

    r2651dc5 r966a27d3  
    4040PCUT_TEST_SUITE(panel);
    4141
     42/** Test response */
     43typedef struct {
     44        bool activate_req;
     45        panel_t *activate_req_panel;
     46} test_resp_t;
     47
     48static void test_panel_activate_req(void *, panel_t *);
     49
     50static panel_cb_t test_cb = {
     51        .activate_req = test_panel_activate_req
     52};
     53
    4254/** Create and destroy panel. */
    4355PCUT_TEST(create_destroy)
     
    4860        rc = panel_create(NULL, true, &panel);
    4961        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     62
     63        panel_destroy(panel);
     64}
     65
     66/** panel_set_cb() sets callback */
     67PCUT_TEST(set_cb)
     68{
     69        panel_t *panel;
     70        errno_t rc;
     71        test_resp_t resp;
     72
     73        rc = panel_create(NULL, true, &panel);
     74        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     75
     76        panel_set_cb(panel, &test_cb, &resp);
     77        PCUT_ASSERT_EQUALS(&test_cb, panel->cb);
     78        PCUT_ASSERT_EQUALS(&resp, panel->cb_arg);
    5079
    5180        panel_destroy(panel);
     
    14261455}
    14271456
     1457/** panel_activate_req() sends activation request */
     1458PCUT_TEST(activate_req)
     1459{
     1460        panel_t *panel;
     1461        errno_t rc;
     1462        test_resp_t resp;
     1463
     1464        rc = panel_create(NULL, true, &panel);
     1465        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1466
     1467        panel_set_cb(panel, &test_cb, &resp);
     1468
     1469        resp.activate_req = false;
     1470        resp.activate_req_panel = NULL;
     1471
     1472        panel_activate_req(panel);
     1473        PCUT_ASSERT_TRUE(resp.activate_req);
     1474        PCUT_ASSERT_EQUALS(panel, resp.activate_req_panel);
     1475
     1476        panel_destroy(panel);
     1477}
     1478
     1479static void test_panel_activate_req(void *arg, panel_t *panel)
     1480{
     1481        test_resp_t *resp = (test_resp_t *)arg;
     1482
     1483        resp->activate_req = true;
     1484        resp->activate_req_panel = panel;
     1485}
     1486
    14281487PCUT_EXPORT(panel);
  • uspace/app/nav/types/panel.h

    r2651dc5 r966a27d3  
    8383        ui_window_t *window;
    8484
     85        /** Callbacks */
     86        struct panel_cb *cb;
     87
     88        /** Callback argument */
     89        void *cb_arg;
     90
    8591        /** Panel rectangle */
    8692        gfx_rect_t rect;
     
    126132} panel_t;
    127133
     134/** Panel callbacks */
     135typedef struct panel_cb {
     136        /** Request panel activation */
     137        void (*activate_req)(void *, panel_t *);
     138} panel_cb_t;
     139
    128140#endif
    129141
Note: See TracChangeset for help on using the changeset viewer.