Changeset 3c22438a in mainline for uspace/app


Ignore:
Timestamp:
2026-03-09T07:37:31Z (9 days ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
b979ffb
Parents:
13277e3
git-author:
Jiri Svoboda <jiri@…> (2026-03-09 19:37:18)
git-committer:
Jiri Svoboda <jiri@…> (2026-03-09 07:37:31)
Message:

Handle screen resize in text editor.

File:
1 edited

Legend:

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

    r13277e3 r3c22438a  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2026 Jiri Svoboda
    33 * Copyright (c) 2012 Martin Sucha
    44 * All rights reserved.
     
    240240static void edit_ui_destroy(edit_t *);
    241241
     242static void edit_wnd_resize(ui_window_t *, void *);
    242243static void edit_wnd_close(ui_window_t *, void *);
    243244static void edit_wnd_focus(ui_window_t *, void *, unsigned);
     
    246247
    247248static ui_window_cb_t edit_window_cb = {
     249        .resize = edit_wnd_resize,
    248250        .close = edit_wnd_close,
    249251        .focus = edit_wnd_focus,
     
    363365        edit_ui_destroy(&edit);
    364366        return 0;
     367}
     368
     369/** Set menu bar rectangle.
     370 *
     371 * Set the menu bar rectangle based on editor window dimensions.
     372 * Used when window is created or resized.
     373 *
     374 * @param edit Editor
     375 */
     376static void edit_menubar_set_rect(edit_t *edit)
     377{
     378        gfx_rect_t arect;
     379        gfx_rect_t rect;
     380
     381        ui_window_get_app_rect(edit->window, &arect);
     382
     383        rect.p0 = arect.p0;
     384        rect.p1.x = arect.p1.x;
     385        rect.p1.y = arect.p0.y + 1;
     386        ui_menu_bar_set_rect(edit->menubar, &rect);
     387}
     388
     389/** Set status bar rectangle.
     390 *
     391 * Set the status bar rectangle based on editor window dimensions.
     392 * Used when window is created or resized.
     393 *
     394 * @param edit Editor
     395 */
     396static void edit_status_set_rect(edit_t *edit)
     397{
     398        gfx_rect_t arect;
     399        gfx_rect_t rect;
     400
     401        ui_window_get_app_rect(edit->window, &arect);
     402        rect.p0.x = arect.p0.x;
     403        rect.p0.y = arect.p1.y - 1;
     404        rect.p1 = arect.p1;
     405        ui_label_set_rect(edit->status, &rect);
    365406}
    366407
     
    395436        ui_menu_entry_t *mssep = NULL;
    396437        ui_menu_entry_t *mgoto = NULL;
    397         gfx_rect_t arect;
    398         gfx_rect_t rect;
    399438
    400439        rc = ui_create(UI_CONSOLE_DEFAULT, &edit->ui);
     
    582621        ui_menu_entry_set_cb(mgoto, edit_search_go_to_line, (void *) edit);
    583622
    584         ui_window_get_app_rect(edit->window, &arect);
    585 
    586         rect.p0 = arect.p0;
    587         rect.p1.x = arect.p1.x;
    588         rect.p1.y = arect.p0.y + 1;
    589         ui_menu_bar_set_rect(edit->menubar, &rect);
     623        edit_menubar_set_rect(edit);
    590624
    591625        rc = ui_fixed_add(fixed, ui_menu_bar_ctl(edit->menubar));
     
    613647        }
    614648
    615         rect.p0.x = arect.p0.x;
    616         rect.p0.y = arect.p1.y - 1;
    617         rect.p1 = arect.p1;
    618         ui_label_set_rect(edit->status, &rect);
     649        edit_status_set_rect(edit);
    619650
    620651        rc = ui_fixed_add(fixed, ui_label_ctl(edit->status));
     
    12021233}
    12031234
    1204 /** Initialize pane.
    1205  *
    1206  * TODO: Replace with pane_create() that allocates the pane.
    1207  *
    1208  * @param window Editor window
    1209  * @param pane Pane
    1210  * @return EOK on success or an error code
    1211  */
    1212 static errno_t pane_init(ui_window_t *window, pane_t *pane)
    1213 {
    1214         errno_t rc;
     1235static void pane_set_rect(pane_t *pane)
     1236{
    12151237        gfx_rect_t arect;
    12161238
    1217         pane->control = NULL;
    1218         pane->color = NULL;
    1219         pane->sel_color = NULL;
    1220 
    1221         rc = ui_control_new(&pane_ctl_ops, (void *) pane, &pane->control);
    1222         if (rc != EOK)
    1223                 goto error;
    1224 
    1225         rc = gfx_color_new_ega(0x07, &pane->color);
    1226         if (rc != EOK)
    1227                 goto error;
    1228 
    1229         rc = gfx_color_new_ega(0x1e, &pane->sel_color);
    1230         if (rc != EOK)
    1231                 goto error;
    1232 
    1233         pane->res = ui_window_get_res(window);
    1234         pane->window = window;
    1235 
    1236         ui_window_get_app_rect(window, &arect);
     1239        ui_window_get_app_rect(pane->window, &arect);
    12371240        pane->rect.p0.x = arect.p0.x;
    12381241        pane->rect.p0.y = arect.p0.y + 1;
     
    12421245        pane->columns = pane->rect.p1.x - pane->rect.p0.x;
    12431246        pane->rows = pane->rect.p1.y - pane->rect.p0.y;
    1244 
     1247}
     1248
     1249/** Initialize pane.
     1250 *
     1251 * TODO: Replace with pane_create() that allocates the pane.
     1252 *
     1253 * @param window Editor window
     1254 * @param pane Pane
     1255 * @return EOK on success or an error code
     1256 */
     1257static errno_t pane_init(ui_window_t *window, pane_t *pane)
     1258{
     1259        errno_t rc;
     1260
     1261        pane->control = NULL;
     1262        pane->color = NULL;
     1263        pane->sel_color = NULL;
     1264
     1265        rc = ui_control_new(&pane_ctl_ops, (void *) pane, &pane->control);
     1266        if (rc != EOK)
     1267                goto error;
     1268
     1269        rc = gfx_color_new_ega(0x07, &pane->color);
     1270        if (rc != EOK)
     1271                goto error;
     1272
     1273        rc = gfx_color_new_ega(0x1e, &pane->sel_color);
     1274        if (rc != EOK)
     1275                goto error;
     1276
     1277        pane->res = ui_window_get_res(window);
     1278        pane->window = window;
     1279
     1280        pane_set_rect(pane);
    12451281        return EOK;
    12461282error:
     
    12561292
    12571293        return rc;
     1294}
     1295
     1296static void pane_resize(pane_t *pane)
     1297{
     1298        pane_set_rect(pane);
     1299
     1300        /* Scroll in case cursor is now outside of the editor pane. */
     1301        caret_move_relative(0, 0, dir_before, true);
     1302
     1303        pane_caret_display(pane);
    12581304}
    12591305
     
    23502396}
    23512397
     2398/** Window was resized.
     2399 *
     2400 * @param window Window
     2401 * @param arg Argument (edit_t *)
     2402 */
     2403static void edit_wnd_resize(ui_window_t *window, void *arg)
     2404{
     2405        edit_t *edit = (edit_t *) arg;
     2406
     2407        edit_menubar_set_rect(edit);
     2408        edit_status_set_rect(edit);
     2409        pane_resize(&pane);
     2410}
     2411
    23522412/** Window close request
    23532413 *
Note: See TracChangeset for help on using the changeset viewer.