Changeset cde067e in mainline


Ignore:
Timestamp:
2024-08-22T16:52:45Z (3 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
ca95ccd
Parents:
69d4aba
Message:

Add UI window callback that is called when window is resized.

Location:
uspace/lib/ui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/include/types/ui/window.h

    r69d4aba rcde067e  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    100100        void (*maximize)(ui_window_t *, void *);
    101101        void (*unmaximize)(ui_window_t *, void *);
     102        void (*resize)(ui_window_t *, void *);
    102103        void (*close)(ui_window_t *, void *);
    103104        void (*focus)(ui_window_t *, void *, unsigned);
  • uspace/lib/ui/include/ui/window.h

    r69d4aba rcde067e  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7474extern void ui_window_def_pos(ui_window_t *, pos_event_t *);
    7575extern void ui_window_def_unfocus(ui_window_t *, unsigned);
     76extern void ui_window_def_resize(ui_window_t *);
    7677
    7778#endif
  • uspace/lib/ui/private/window.h

    r69d4aba rcde067e  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    133133extern void ui_window_send_pos(ui_window_t *, pos_event_t *);
    134134extern void ui_window_send_unfocus(ui_window_t *, unsigned);
     135extern void ui_window_send_resize(ui_window_t *);
    135136extern errno_t ui_window_size_change(ui_window_t *, gfx_rect_t *,
    136137    ui_wnd_sc_op_t);
  • uspace/lib/ui/src/window.c

    r69d4aba rcde067e  
    10471047        ui_lock(ui);
    10481048        (void) ui_window_resize(window, rect);
    1049         (void) ui_window_paint(window);
     1049        ui_window_send_resize(window);
    10501050        ui_unlock(ui);
    10511051}
     
    13951395}
    13961396
     1397/** Send window resize event.
     1398 *
     1399 * @param window Window
     1400 */
     1401void ui_window_send_resize(ui_window_t *window)
     1402{
     1403        if (window->cb != NULL && window->cb->resize != NULL)
     1404                window->cb->resize(window, window->arg);
     1405        else
     1406                return ui_window_def_resize(window);
     1407}
     1408
    13971409/** Default window sysmenu routine.
    13981410 *
     
    15731585        if (window->control != NULL)
    15741586                ui_control_unfocus(window->control, nfocus);
     1587}
     1588
     1589/** Default window resize routine.
     1590 *
     1591 * @param window Window
     1592 * @return EOK on success or an error code
     1593 */
     1594void ui_window_def_resize(ui_window_t *window)
     1595{
     1596        ui_window_paint(window);
    15751597}
    15761598
  • uspace/lib/ui/test/window.c

    r69d4aba rcde067e  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5555static void test_window_pos(ui_window_t *, void *, pos_event_t *);
    5656static void test_window_unfocus(ui_window_t *, void *, unsigned);
     57static void test_window_resize(ui_window_t *, void *);
    5758
    5859static ui_window_cb_t test_window_cb = {
     
    6667        .paint = test_window_paint,
    6768        .pos = test_window_pos,
    68         .unfocus = test_window_unfocus
     69        .unfocus = test_window_unfocus,
     70        .resize = test_window_resize
    6971};
    7072
     
    99101        bool unfocus;
    100102        unsigned unfocus_nfocus;
     103        bool resize;
    101104} test_cb_resp_t;
    102105
     
    936939}
    937940
     941/** ui_window_send_resize() calls resize callback set via ui_window_set_cb() */
     942PCUT_TEST(send_resize)
     943{
     944        errno_t rc;
     945        ui_t *ui = NULL;
     946        ui_wnd_params_t params;
     947        ui_window_t *window = NULL;
     948        test_cb_resp_t resp;
     949
     950        rc = ui_create_disp(NULL, &ui);
     951        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     952
     953        ui_wnd_params_init(&params);
     954        params.caption = "Hello";
     955
     956        rc = ui_window_create(ui, &params, &window);
     957        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     958        PCUT_ASSERT_NOT_NULL(window);
     959
     960        /* Resize callback with no callbacks set */
     961        ui_window_send_resize(window);
     962
     963        /* Resize callback with resize callback not implemented */
     964        ui_window_set_cb(window, &dummy_window_cb, NULL);
     965        ui_window_send_resize(window);
     966
     967        /* Resize callback with real callback set */
     968        resp.close = false;
     969        ui_window_set_cb(window, &test_window_cb, &resp);
     970        ui_window_send_resize(window);
     971        PCUT_ASSERT_TRUE(resp.resize);
     972
     973        ui_window_destroy(window);
     974        ui_destroy(ui);
     975}
     976
    938977static void test_window_sysmenu(ui_window_t *window, void *arg, sysarg_t idev_id)
    939978{
     
    10141053}
    10151054
     1055static void test_window_resize(ui_window_t *window, void *arg)
     1056{
     1057        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
     1058
     1059        resp->resize = true;
     1060}
     1061
    10161062static errno_t test_ctl_paint(void *arg)
    10171063{
Note: See TracChangeset for help on using the changeset viewer.