Changeset c1c7c20 in mainline


Ignore:
Timestamp:
2021-09-25T17:55:56Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
294fc3cc
Parents:
db52892a
Message:

Display status line using a label control

This obviously only works in text mode, ideally we would need a special status
bar control.

File:
1 edited

Legend:

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

    rdb52892a rc1c7c20  
    5656#include <ui/control.h>
    5757#include <ui/fixed.h>
     58#include <ui/label.h>
    5859#include <ui/menu.h>
    5960#include <ui/menubar.h>
     
    137138        /** Menu bar */
    138139        ui_menu_bar_t *menubar;
     140        /** Status bar */
     141        ui_label_t *status;
    139142} edit_t;
    140143
     
    190193static void pane_row_display(void);
    191194static errno_t pane_row_range_display(pane_t *, int r0, int r1);
    192 static void pane_status_display(void);
     195static void pane_status_display(pane_t *);
    193196static void pane_caret_display(pane_t *);
    194197
     
    321324        }
    322325
    323         pane_status_display();
     326        pane_status_display(&pane);
    324327        if (new_file && doc.file_name != NULL)
    325328                status_display("File not found. Starting empty file.");
     
    443446
    444447        rc = ui_fixed_add(fixed, pane_ctl(&pane));
     448        if (rc != EOK) {
     449                printf("Error adding control to layout.\n");
     450                return rc;
     451        }
     452
     453        rc = ui_label_create(edit->ui_res, "", &edit->status);
     454        if (rc != EOK) {
     455                printf("Error creating menu bar.\n");
     456                return rc;
     457        }
     458
     459        rect.p0.x = arect.p0.x;
     460        rect.p0.y = arect.p1.y - 1;
     461        rect.p1 = arect.p1;
     462        ui_label_set_rect(edit->status, &rect);
     463
     464        rc = ui_fixed_add(fixed, ui_label_ctl(edit->status));
    445465        if (rc != EOK) {
    446466                printf("Error adding control to layout.\n");
     
    10161036
    10171037        if (pane->rflags & REDRAW_STATUS)
    1018                 pane_status_display();
     1038                pane_status_display(pane);
    10191039
    10201040        if (pane->rflags & REDRAW_CARET)
     
    12221242}
    12231243
    1224 /** Display pane status in the status line. */
    1225 static void pane_status_display(void)
     1244/** Display pane status in the status line.
     1245 *
     1246 * @param pane Pane
     1247 */
     1248static void pane_status_display(pane_t *pane)
    12261249{
    12271250        spt_t caret_pt;
     
    12321255        char *text;
    12331256        size_t n;
    1234         int pos;
    12351257        size_t nextra;
    12361258        size_t fnw;
    12371259
    1238         tag_get_pt(&pane.caret_pos, &caret_pt);
     1260        tag_get_pt(&pane->caret_pos, &caret_pt);
    12391261        spt_get_coord(&caret_pt, &coord);
    12401262
     
    12551277                return;
    12561278
    1257 //      console_set_pos(con, 0, scr_rows - 1);
    1258 //      console_set_style(con, STYLE_INVERTED);
    1259 
    12601279        /*
    12611280         * Make sure the status fits on the screen. This loop should
     
    12631282         */
    12641283        while (true) {
    1265                 int rc = asprintf(&text, " %d, %d (%d): File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
     1284                int rc = asprintf(&text, "%d, %d (%d): File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
    12661285                    "Ctrl-E Save As", coord.row, coord.column, last_row, fname);
    12671286                if (rc < 0) {
     
    12841303                 * just give up and print a blank status.
    12851304                 */
    1286                 if (nextra > fnw - 2)
     1305                if (nextra > fnw - 2) {
     1306                        text[0] = '\0';
    12871307                        goto finish;
     1308                }
    12881309
    12891310                /* Compute position where we overwrite with '..\0' */
     
    13021323        }
    13031324
    1304         printf("%s", text);
     1325finish:
     1326        (void) ui_label_set_text(edit.status, text);
     1327        (void) ui_label_paint(edit.status);
    13051328        free(text);
    13061329        free(fname);
    1307 finish:
    1308         /* Fill the rest of the line */
    1309         pos = scr_columns - 1 - n;
    1310         printf("%*s", pos, "");
    1311 //      console_flush(con);
    1312 //      console_set_style(con, STYLE_NORMAL);
    1313 
    1314         pane.rflags |= REDRAW_CARET;
    13151330}
    13161331
     
    20412056static void status_display(char const *str)
    20422057{
    2043 //      console_set_pos(con, 0, scr_rows - 1);
    2044 //      console_set_style(con, STYLE_INVERTED);
    2045 
    2046         int pos = -(scr_columns - 3);
    2047         printf(" %*s ", pos, str);
    2048 //      console_flush(con);
    2049 //      console_set_style(con, STYLE_NORMAL);
    2050 
    2051         pane.rflags |= REDRAW_CARET;
     2058        (void) ui_label_set_text(edit.status, str);
     2059        (void) ui_label_paint(edit.status);
    20522060}
    20532061
Note: See TracChangeset for help on using the changeset viewer.