Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/filedialog.c

    rb979ffb r12dd36c  
    11/*
    2  * Copyright (c) 2026 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4848#include "../private/filedialog.h"
    4949
    50 static void ui_file_dialog_wnd_resize(ui_window_t *, void *);
    5150static void ui_file_dialog_wnd_close(ui_window_t *, void *);
    5251static void ui_file_dialog_wnd_kbd(ui_window_t *, void *, kbd_event_t *);
    5352
    5453ui_window_cb_t ui_file_dialog_wnd_cb = {
    55         .resize = ui_file_dialog_wnd_resize,
    5654        .close = ui_file_dialog_wnd_close,
    5755        .kbd = ui_file_dialog_wnd_kbd
     
    8987        memset(params, 0, sizeof(ui_file_dialog_params_t));
    9088        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  */
    99 static 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         }
    18389}
    18490
     
    203109        ui_pbutton_t *bok = NULL;
    204110        ui_pbutton_t *bcancel = NULL;
    205         ui_file_dialog_geom_t geom;
    206         gfx_rect_t arect;
     111        gfx_rect_t rect;
    207112        ui_resource_t *ui_res;
    208113
     
    215120        ui_wnd_params_init(&wparams);
    216121        wparams.caption = params->caption;
    217         wparams.style |= ui_wds_maximize_btn | ui_wds_resizable;
    218122
    219123        /* FIXME: Auto layout */
     
    223127                wparams.rect.p1.x = 40;
    224128                wparams.rect.p1.y = 20;
    225 
    226                 wparams.min_size.x = 30;
    227                 wparams.min_size.y = 10;
    228129        } else {
    229130                wparams.rect.p0.x = 0;
     
    231132                wparams.rect.p1.x = 300;
    232133                wparams.rect.p1.y = 335;
    233 
    234                 wparams.min_size.x = 240;
    235                 wparams.min_size.y = 260;
    236134        }
    237135
     
    242140        ui_window_set_cb(window, &ui_file_dialog_wnd_cb, dialog);
    243141
    244         ui_window_get_app_rect(window, &arect);
    245142        ui_res = ui_window_get_res(window);
    246143
    247         /* Compute geometry. */
    248         ui_file_dialog_get_geom(ui, &arect, &geom);
    249 
    250144        rc = ui_fixed_create(&fixed);
    251145        if (rc != EOK)
     
    256150                goto error;
    257151
    258         ui_label_set_rect(label, &geom.fname_label_rect);
     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);
    259166
    260167        rc = ui_fixed_add(fixed, ui_label_ctl(label));
     
    268175                goto error;
    269176
    270         ui_entry_set_rect(entry, &geom.entry_rect);
     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);
    271191
    272192        rc = ui_fixed_add(fixed, ui_entry_ctl(entry));
     
    288208                goto error;
    289209
    290         ui_label_set_rect(label, &geom.files_label_rect);
     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);
    291224
    292225        rc = ui_fixed_add(fixed, ui_label_ctl(label));
     
    302235                goto error;
    303236
    304         ui_file_list_set_rect(flist, &geom.flist_rect);
     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);
    305251        ui_file_list_set_cb(flist, &ui_file_dialog_flist_cb, dialog);
    306252
     
    323269
    324270        ui_pbutton_set_cb(bok, &ui_file_dialog_bok_cb, dialog);
    325         ui_pbutton_set_rect(bok, &geom.bok_rect);
     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
    326287        ui_pbutton_set_default(bok, true);
    327288
     
    340301
    341302        ui_pbutton_set_cb(bcancel, &ui_file_dialog_bcancel_cb, dialog);
    342         ui_pbutton_set_rect(bcancel, &geom.bcancel_rect);
     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);
    343318
    344319        rc = ui_fixed_add(fixed, ui_pbutton_ctl(bcancel));
     
    405380}
    406381
    407 /** File dialog window resize handler.
    408  *
    409  * @param window Window
    410  * @param arg Argument (ui_file_dialog_t *)
    411  */
    412 static 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 
    432382/** File dialog window close handler.
    433383 *
Note: See TracChangeset for help on using the changeset viewer.