Changeset b979ffb in mainline for uspace/lib/ui


Ignore:
Timestamp:
2026-03-10T09:41:42Z (7 days ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
52148ef, 66da893, 79ec0a0, 9b534a4, bc969a1, d811fe5, d8120c5, db6ead8b, e474d61, eede1c5
Parents:
3c22438a
git-author:
Jiri Svoboda <jiri@…> (2026-03-09 20:41:23)
git-committer:
Jiri Svoboda <jiri@…> (2026-03-10 09:41:42)
Message:

Make file dialog resizable.

Location:
uspace/lib/ui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/private/filedialog.h

    r3c22438a rb979ffb  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2026 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838#define _UI_PRIVATE_FILEDIALOG_H
    3939
     40#include <gfx/coord.h>
     41
    4042/** Actual structure of file dialog.
    4143 *
     
    5961};
    6062
     63/** File dialog geometry.
     64 *
     65 * Computed geometry of file dialog.
     66 */
     67typedef struct {
     68        /** File name label rectangle */
     69        gfx_rect_t fname_label_rect;
     70        /** File name entry rectangle */
     71        gfx_rect_t entry_rect;
     72        /** Files label rectangle */
     73        gfx_rect_t files_label_rect;
     74        /** File list rectangle */
     75        gfx_rect_t flist_rect;
     76        /** File list rectangle */
     77        gfx_rect_t bok_rect;
     78        /** File list rectangle */
     79        gfx_rect_t bcancel_rect;
     80} ui_file_dialog_geom_t;
     81
    6182#endif
    6283
  • uspace/lib/ui/src/filedialog.c

    r3c22438a rb979ffb  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2026 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4848#include "../private/filedialog.h"
    4949
     50static void ui_file_dialog_wnd_resize(ui_window_t *, void *);
    5051static void ui_file_dialog_wnd_close(ui_window_t *, void *);
    5152static void ui_file_dialog_wnd_kbd(ui_window_t *, void *, kbd_event_t *);
    5253
    5354ui_window_cb_t ui_file_dialog_wnd_cb = {
     55        .resize = ui_file_dialog_wnd_resize,
    5456        .close = ui_file_dialog_wnd_close,
    5557        .kbd = ui_file_dialog_wnd_kbd
     
    8789        memset(params, 0, sizeof(ui_file_dialog_params_t));
    8890        params->ifname = "";
     91}
     92
     93/** Compute file dialog geometry.
     94 *
     95 * @param ui User interface
     96 * @param wrect Window interior rectangle
     97 * @param geom Place to store geometry
     98 */
     99static void ui_file_dialog_get_geom(ui_t *ui, gfx_rect_t *wrect,
     100    ui_file_dialog_geom_t *geom)
     101{
     102        gfx_coord_t cx;
     103
     104        /* FIXME: Auto layout */
     105        if (ui_is_textmode(ui)) {
     106                geom->fname_label_rect.p0.x = 3;
     107                geom->fname_label_rect.p0.y = 2;
     108                geom->fname_label_rect.p1.x = 17;
     109                geom->fname_label_rect.p1.y = 3;
     110        } else {
     111                geom->fname_label_rect.p0.x = 10;
     112                geom->fname_label_rect.p0.y = 35;
     113                geom->fname_label_rect.p1.x = 190;
     114                geom->fname_label_rect.p1.y = 50;
     115        }
     116
     117        /* FIXME: Auto layout */
     118        if (ui_is_textmode(ui)) {
     119                geom->entry_rect.p0.x = 3;
     120                geom->entry_rect.p0.y = 3;
     121                geom->entry_rect.p1.x = wrect->p1.x - 3;
     122                geom->entry_rect.p1.y = 4;
     123        } else {
     124                geom->entry_rect.p0.x = 10;
     125                geom->entry_rect.p0.y = 55;
     126                geom->entry_rect.p1.x = wrect->p1.x - 10;
     127                geom->entry_rect.p1.y = 80;
     128        }
     129
     130        /* FIXME: Auto layout */
     131        if (ui_is_textmode(ui)) {
     132                geom->files_label_rect.p0.x = 3;
     133                geom->files_label_rect.p0.y = 5;
     134                geom->files_label_rect.p1.x = 17;
     135                geom->files_label_rect.p1.y = 6;
     136        } else {
     137                geom->files_label_rect.p0.x = 10;
     138                geom->files_label_rect.p0.y = 90;
     139                geom->files_label_rect.p1.x = 190;
     140                geom->files_label_rect.p1.y = 105;
     141        }
     142
     143        /* FIXME: Auto layout */
     144        if (ui_is_textmode(ui)) {
     145                geom->flist_rect.p0.x = 3;
     146                geom->flist_rect.p0.y = 6;
     147                geom->flist_rect.p1.x = wrect->p1.x - 3;
     148                geom->flist_rect.p1.y = wrect->p1.y - 4;
     149        } else {
     150                geom->flist_rect.p0.x = 10;
     151                geom->flist_rect.p0.y = 110;
     152                geom->flist_rect.p1.x = wrect->p1.x - 10;
     153                geom->flist_rect.p1.y = wrect->p1.y - 55;
     154        }
     155
     156        cx = (wrect->p0.x + wrect->p1.x) / 2;
     157
     158        /* FIXME: Auto layout */
     159        if (ui_is_textmode(ui)) {
     160                geom->bok_rect.p0.x = cx - 10;
     161                geom->bok_rect.p0.y = wrect->p1.y - 3;
     162                geom->bok_rect.p1.x = cx;
     163                geom->bok_rect.p1.y = wrect->p1.y - 2;
     164        } else {
     165                geom->bok_rect.p0.x = cx - 95;
     166                geom->bok_rect.p0.y = wrect->p1.y - 45;
     167                geom->bok_rect.p1.x = cx - 5;
     168                geom->bok_rect.p1.y = wrect->p1.y - 17;
     169        }
     170
     171        /* FIXME: Auto layout */
     172        if (ui_is_textmode(ui)) {
     173                geom->bcancel_rect.p0.x = cx + 2;
     174                geom->bcancel_rect.p0.y = wrect->p1.y - 3;
     175                geom->bcancel_rect.p1.x = cx + 12;
     176                geom->bcancel_rect.p1.y = wrect->p1.y - 2;
     177        } else {
     178                geom->bcancel_rect.p0.x = cx + 5;
     179                geom->bcancel_rect.p0.y = wrect->p1.y - 45;
     180                geom->bcancel_rect.p1.x = cx + 95;
     181                geom->bcancel_rect.p1.y = wrect->p1.y - 17;
     182        }
    89183}
    90184
     
    109203        ui_pbutton_t *bok = NULL;
    110204        ui_pbutton_t *bcancel = NULL;
    111         gfx_rect_t rect;
     205        ui_file_dialog_geom_t geom;
     206        gfx_rect_t arect;
    112207        ui_resource_t *ui_res;
    113208
     
    120215        ui_wnd_params_init(&wparams);
    121216        wparams.caption = params->caption;
     217        wparams.style |= ui_wds_maximize_btn | ui_wds_resizable;
    122218
    123219        /* FIXME: Auto layout */
     
    127223                wparams.rect.p1.x = 40;
    128224                wparams.rect.p1.y = 20;
     225
     226                wparams.min_size.x = 30;
     227                wparams.min_size.y = 10;
    129228        } else {
    130229                wparams.rect.p0.x = 0;
     
    132231                wparams.rect.p1.x = 300;
    133232                wparams.rect.p1.y = 335;
     233
     234                wparams.min_size.x = 240;
     235                wparams.min_size.y = 260;
    134236        }
    135237
     
    140242        ui_window_set_cb(window, &ui_file_dialog_wnd_cb, dialog);
    141243
     244        ui_window_get_app_rect(window, &arect);
    142245        ui_res = ui_window_get_res(window);
    143246
     247        /* Compute geometry. */
     248        ui_file_dialog_get_geom(ui, &arect, &geom);
     249
    144250        rc = ui_fixed_create(&fixed);
    145251        if (rc != EOK)
     
    150256                goto error;
    151257
    152         /* FIXME: Auto layout */
    153         if (ui_is_textmode(ui)) {
    154                 rect.p0.x = 3;
    155                 rect.p0.y = 2;
    156                 rect.p1.x = 17;
    157                 rect.p1.y = 3;
    158         } else {
    159                 rect.p0.x = 10;
    160                 rect.p0.y = 35;
    161                 rect.p1.x = 190;
    162                 rect.p1.y = 50;
    163         }
    164 
    165         ui_label_set_rect(label, &rect);
     258        ui_label_set_rect(label, &geom.fname_label_rect);
    166259
    167260        rc = ui_fixed_add(fixed, ui_label_ctl(label));
     
    175268                goto error;
    176269
    177         /* FIXME: Auto layout */
    178         if (ui_is_textmode(ui)) {
    179                 rect.p0.x = 3;
    180                 rect.p0.y = 3;
    181                 rect.p1.x = 37;
    182                 rect.p1.y = 4;
    183         } else {
    184                 rect.p0.x = 10;
    185                 rect.p0.y = 55;
    186                 rect.p1.x = 290;
    187                 rect.p1.y = 80;
    188         }
    189 
    190         ui_entry_set_rect(entry, &rect);
     270        ui_entry_set_rect(entry, &geom.entry_rect);
    191271
    192272        rc = ui_fixed_add(fixed, ui_entry_ctl(entry));
     
    208288                goto error;
    209289
    210         /* FIXME: Auto layout */
    211         if (ui_is_textmode(ui)) {
    212                 rect.p0.x = 3;
    213                 rect.p0.y = 5;
    214                 rect.p1.x = 17;
    215                 rect.p1.y = 6;
    216         } else {
    217                 rect.p0.x = 10;
    218                 rect.p0.y = 90;
    219                 rect.p1.x = 190;
    220                 rect.p1.y = 105;
    221         }
    222 
    223         ui_label_set_rect(label, &rect);
     290        ui_label_set_rect(label, &geom.files_label_rect);
    224291
    225292        rc = ui_fixed_add(fixed, ui_label_ctl(label));
     
    235302                goto error;
    236303
    237         /* FIXME: Auto layout */
    238         if (ui_is_textmode(ui)) {
    239                 rect.p0.x = 3;
    240                 rect.p0.y = 6;
    241                 rect.p1.x = 37;
    242                 rect.p1.y = 16;
    243         } else {
    244                 rect.p0.x = 10;
    245                 rect.p0.y = 110;
    246                 rect.p1.x = 290;
    247                 rect.p1.y = 280;
    248         }
    249 
    250         ui_file_list_set_rect(flist, &rect);
     304        ui_file_list_set_rect(flist, &geom.flist_rect);
    251305        ui_file_list_set_cb(flist, &ui_file_dialog_flist_cb, dialog);
    252306
     
    269323
    270324        ui_pbutton_set_cb(bok, &ui_file_dialog_bok_cb, dialog);
    271 
    272         /* FIXME: Auto layout */
    273         if (ui_is_textmode(ui)) {
    274                 rect.p0.x = 10;
    275                 rect.p0.y = 17;
    276                 rect.p1.x = 20;
    277                 rect.p1.y = 18;
    278         } else {
    279                 rect.p0.x = 55;
    280                 rect.p0.y = 290;
    281                 rect.p1.x = 145;
    282                 rect.p1.y = 318;
    283         }
    284 
    285         ui_pbutton_set_rect(bok, &rect);
    286 
     325        ui_pbutton_set_rect(bok, &geom.bok_rect);
    287326        ui_pbutton_set_default(bok, true);
    288327
     
    301340
    302341        ui_pbutton_set_cb(bcancel, &ui_file_dialog_bcancel_cb, dialog);
    303 
    304         /* FIXME: Auto layout */
    305         if (ui_is_textmode(ui)) {
    306                 rect.p0.x = 22;
    307                 rect.p0.y = 17;
    308                 rect.p1.x = 32;
    309                 rect.p1.y = 18;
    310         } else {
    311                 rect.p0.x = 155;
    312                 rect.p0.y = 290;
    313                 rect.p1.x = 245;
    314                 rect.p1.y = 318;
    315         }
    316 
    317         ui_pbutton_set_rect(bcancel, &rect);
     342        ui_pbutton_set_rect(bcancel, &geom.bcancel_rect);
    318343
    319344        rc = ui_fixed_add(fixed, ui_pbutton_ctl(bcancel));
     
    380405}
    381406
     407/** File dialog window resize handler.
     408 *
     409 * @param window Window
     410 * @param arg Argument (ui_file_dialog_t *)
     411 */
     412static void ui_file_dialog_wnd_resize(ui_window_t *window, void *arg)
     413{
     414        ui_file_dialog_t *dialog = (ui_file_dialog_t *) arg;
     415        gfx_rect_t arect;
     416        ui_file_dialog_geom_t geom;
     417
     418        /* Get new window application rectangle. */
     419        ui_window_get_app_rect(window, &arect);
     420
     421        /* Compute geometry. */
     422        ui_file_dialog_get_geom(ui_window_get_ui(window), &arect, &geom);
     423
     424        ui_entry_set_rect(dialog->ename, &geom.entry_rect);
     425        ui_file_list_set_rect(dialog->flist, &geom.flist_rect);
     426        ui_pbutton_set_rect(dialog->bok, &geom.bok_rect);
     427        ui_pbutton_set_rect(dialog->bcancel, &geom.bcancel_rect);
     428
     429        (void)ui_window_paint(window);
     430}
     431
    382432/** File dialog window close handler.
    383433 *
  • uspace/lib/ui/src/window.c

    r3c22438a rb979ffb  
    840840        }
    841841
    842         /* Need to repaint UI if windows are emulated */
    843         if (ui_is_fullscreen(window->ui))
    844                 (void)ui_paint(window->ui);
    845 
    846842        switch (scop) {
    847843        case ui_wsc_resize:
     
    876872errno_t ui_window_resize(ui_window_t *window, gfx_rect_t *rect)
    877873{
    878         return ui_window_size_change(window, rect, ui_wsc_resize);
     874        errno_t rc;
     875
     876        rc = ui_window_size_change(window, rect, ui_wsc_resize);
     877        if (rc != EOK)
     878                return rc;
     879
     880        /* Need to repaint UI if windows are emulated */
     881        if (ui_is_fullscreen(window->ui))
     882                (void)ui_paint(window->ui);
     883
     884        return EOK;
    879885}
    880886
     
    15781584
    15791585        window->normal_rect = old_rect;
    1580         (void) ui_window_paint(window);
     1586        ui_window_send_resize(window);
     1587
     1588        /* Need to repaint UI if windows are emulated */
     1589        if (ui_is_fullscreen(window->ui))
     1590                (void)ui_paint(window->ui);
     1591
    15811592        return EOK;
    15821593}
     
    16031614        }
    16041615
    1605         (void) ui_window_paint(window);
     1616        ui_window_send_resize(window);
     1617
     1618        /* Need to repaint UI if windows are emulated */
     1619        if (ui_is_fullscreen(window->ui))
     1620                (void)ui_paint(window->ui);
     1621
    16061622        return EOK;
    16071623}
Note: See TracChangeset for help on using the changeset viewer.