Changeset 9c7dc8e in mainline for uspace/lib


Ignore:
Timestamp:
2021-03-01T10:50:25Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cd74fa8
Parents:
77ffa01
git-author:
Jiri Svoboda <jiri@…> (2021-02-28 10:50:05)
git-committer:
Jiri Svoboda <jiri@…> (2021-03-01 10:50:25)
Message:

Print text as text in textmode UI. Make calculator smaller in text mode.

Location:
uspace/lib/ui
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/include/ui/resource.h

    r77ffa01 r9c7dc8e  
    3939#include <errno.h>
    4040#include <gfx/context.h>
     41#include <stdbool.h>
    4142#include <types/ui/resource.h>
    4243
    43 extern errno_t ui_resource_create(gfx_context_t *, ui_resource_t **);
     44extern errno_t ui_resource_create(gfx_context_t *, bool, ui_resource_t **);
    4445extern void ui_resource_destroy(ui_resource_t *);
    4546
  • uspace/lib/ui/include/ui/ui.h

    r77ffa01 r9c7dc8e  
    4040#include <errno.h>
    4141#include <io/console.h>
     42#include <stdbool.h>
    4243#include <types/ui/ui.h>
    4344
     
    4849extern void ui_quit(ui_t *);
    4950extern void ui_run(ui_t *);
     51extern bool ui_is_textmode(ui_t *);
    5052
    5153#endif
  • uspace/lib/ui/private/resource.h

    r77ffa01 r9c7dc8e  
    4242#include <gfx/font.h>
    4343#include <gfx/typeface.h>
     44#include <stdbool.h>
    4445
    4546/** Actual structure of UI resources.
     
    5455        /** Font */
    5556        gfx_font_t *font;
     57        /** Text mode */
     58        bool textmode;
    5659
    5760        /** Button frame color */
  • uspace/lib/ui/src/entry.c

    r77ffa01 r9c7dc8e  
    4646#include <ui/paint.h>
    4747#include <ui/entry.h>
     48#include <ui/ui.h>
    4849#include "../private/entry.h"
    4950#include "../private/resource.h"
     
    5556enum {
    5657        ui_entry_hpad = 4,
    57         ui_entry_vpad = 4
     58        ui_entry_vpad = 4,
     59        ui_entry_hpad_text = 1,
     60        ui_entry_vpad_text = 0
    5861};
    5962
     
    173176        gfx_text_fmt_t fmt;
    174177        gfx_coord2_t pos;
     178        gfx_coord_t hpad;
     179        gfx_coord_t vpad;
    175180        gfx_rect_t inside;
    176181        errno_t rc;
     182
     183        if (entry->res->textmode) {
     184                hpad = ui_entry_hpad_text;
     185                vpad = ui_entry_vpad_text;
     186        } else {
     187                hpad = ui_entry_hpad;
     188                vpad = ui_entry_vpad;
     189        }
    177190
    178191        /* Paint inset frame */
     
    195208        case gfx_halign_left:
    196209        case gfx_halign_justify:
    197                 pos.x = inside.p0.x + ui_entry_hpad;
     210                pos.x = inside.p0.x + hpad;
    198211                break;
    199212        case gfx_halign_center:
     
    201214                break;
    202215        case gfx_halign_right:
    203                 pos.x = inside.p1.x - ui_entry_hpad;
     216                pos.x = inside.p1.x - hpad;
    204217                break;
    205218        }
    206219
    207         pos.y = inside.p0.y + ui_entry_vpad;
     220        pos.y = inside.p0.y + vpad;
    208221
    209222        gfx_text_fmt_init(&fmt);
  • uspace/lib/ui/src/resource.c

    r77ffa01 r9c7dc8e  
    5050 *
    5151 * @param gc Graphic context
     52 * @param textmode @c true if running in text mode
    5253 * @param rresource Place to store pointer to new UI resource
    5354 * @return EOK on success, ENOMEM if out of memory
    5455 */
    55 errno_t ui_resource_create(gfx_context_t *gc, ui_resource_t **rresource)
     56errno_t ui_resource_create(gfx_context_t *gc, bool textmode,
     57    ui_resource_t **rresource)
    5658{
    5759        ui_resource_t *resource;
     
    8385                return ENOMEM;
    8486
    85         rc = gfx_typeface_open(gc, ui_typeface_path, &tface);
    86         if (rc != EOK)
    87                 goto error;
    88 
    89         finfo = gfx_typeface_first_font(tface);
    90         if (finfo == NULL) {
    91                 rc = EIO;
    92                 goto error;
     87        if (textmode) {
     88                /* Create dummy font for text mode */
     89                rc = gfx_typeface_create(gc, &tface);
     90                if (rc != EOK)
     91                        goto error;
     92
     93                rc = gfx_font_create_textmode(tface, &font);
     94                if (rc != EOK)
     95                        goto error;
     96        } else {
     97                rc = gfx_typeface_open(gc, ui_typeface_path, &tface);
     98                if (rc != EOK)
     99                        goto error;
     100
     101                finfo = gfx_typeface_first_font(tface);
     102                if (finfo == NULL) {
     103                        rc = EIO;
     104                        goto error;
     105                }
     106
     107                rc = gfx_font_open(finfo, &font);
     108                if (rc != EOK)
     109                        goto error;
    93110        }
    94 
    95         rc = gfx_font_open(finfo, &font);
    96         if (rc != EOK)
    97                 goto error;
    98111
    99112        rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_frame_color);
     
    177190        resource->tface = tface;
    178191        resource->font = font;
     192        resource->textmode = textmode;
    179193
    180194        resource->btn_frame_color = btn_frame_color;
  • uspace/lib/ui/src/ui.c

    r77ffa01 r9c7dc8e  
    254254}
    255255
     256/** Determine if we are running in text mode.
     257 *
     258 * @param ui User interface
     259 * @return @c true iff we are running in text mode
     260 */
     261bool ui_is_textmode(ui_t *ui)
     262{
     263        /*
     264         * XXX Currently console is always text and display is always
     265         * graphics, but this need not always be true.
     266         */
     267        return (ui->console != NULL);
     268}
     269
    256270/** @}
    257271 */
  • uspace/lib/ui/src/window.c

    r77ffa01 r9c7dc8e  
    4747#include <ui/control.h>
    4848#include <ui/resource.h>
     49#include <ui/ui.h>
    4950#include <ui/wdecor.h>
    5051#include <ui/window.h>
     
    255256        window->gc = gc;
    256257#endif
    257         rc = ui_resource_create(window->gc, &res);
     258        rc = ui_resource_create(window->gc, ui_is_textmode(ui), &res);
    258259        if (rc != EOK)
    259260                goto error;
  • uspace/lib/ui/test/checkbox.c

    r77ffa01 r9c7dc8e  
    160160        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    161161
    162         rc = ui_resource_create(gc, &resource);
     162        rc = ui_resource_create(gc, false, &resource);
    163163        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    164164        PCUT_ASSERT_NOT_NULL(resource);
     
    217217        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    218218
    219         rc = ui_resource_create(gc, &resource);
     219        rc = ui_resource_create(gc, false, &resource);
    220220        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    221221        PCUT_ASSERT_NOT_NULL(resource);
     
    264264        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    265265
    266         rc = ui_resource_create(gc, &resource);
     266        rc = ui_resource_create(gc, false, &resource);
    267267        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    268268        PCUT_ASSERT_NOT_NULL(resource);
     
    316316        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    317317
    318         rc = ui_resource_create(gc, &resource);
     318        rc = ui_resource_create(gc, false, &resource);
    319319        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    320320        PCUT_ASSERT_NOT_NULL(resource);
     
    377377        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    378378
    379         rc = ui_resource_create(gc, &resource);
     379        rc = ui_resource_create(gc, false, &resource);
    380380        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    381381        PCUT_ASSERT_NOT_NULL(resource);
     
    438438        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    439439
    440         rc = ui_resource_create(gc, &resource);
     440        rc = ui_resource_create(gc, false, &resource);
    441441        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    442442        PCUT_ASSERT_NOT_NULL(resource);
  • uspace/lib/ui/test/entry.c

    r77ffa01 r9c7dc8e  
    192192        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    193193
    194         rc = ui_resource_create(gc, &resource);
     194        rc = ui_resource_create(gc, false, &resource);
    195195        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    196196        PCUT_ASSERT_NOT_NULL(resource);
  • uspace/lib/ui/test/label.c

    r77ffa01 r9c7dc8e  
    192192        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    193193
    194         rc = ui_resource_create(gc, &resource);
     194        rc = ui_resource_create(gc, false, &resource);
    195195        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    196196        PCUT_ASSERT_NOT_NULL(resource);
  • uspace/lib/ui/test/paint.c

    r77ffa01 r9c7dc8e  
    122122        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    123123
    124         rc = ui_resource_create(gc, &resource);
     124        rc = ui_resource_create(gc, false, &resource);
    125125        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    126126        PCUT_ASSERT_NOT_NULL(resource);
  • uspace/lib/ui/test/pbutton.c

    r77ffa01 r9c7dc8e  
    178178        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    179179
    180         rc = ui_resource_create(gc, &resource);
     180        rc = ui_resource_create(gc, false, &resource);
    181181        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    182182        PCUT_ASSERT_NOT_NULL(resource);
     
    235235        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    236236
    237         rc = ui_resource_create(gc, &resource);
     237        rc = ui_resource_create(gc, false, &resource);
    238238        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    239239        PCUT_ASSERT_NOT_NULL(resource);
     
    279279        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    280280
    281         rc = ui_resource_create(gc, &resource);
     281        rc = ui_resource_create(gc, false, &resource);
    282282        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    283283        PCUT_ASSERT_NOT_NULL(resource);
     
    328328        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    329329
    330         rc = ui_resource_create(gc, &resource);
     330        rc = ui_resource_create(gc, false, &resource);
    331331        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    332332        PCUT_ASSERT_NOT_NULL(resource);
     
    384384        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    385385
    386         rc = ui_resource_create(gc, &resource);
     386        rc = ui_resource_create(gc, false, &resource);
    387387        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    388388        PCUT_ASSERT_NOT_NULL(resource);
     
    445445        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    446446
    447         rc = ui_resource_create(gc, &resource);
     447        rc = ui_resource_create(gc, false, &resource);
    448448        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    449449        PCUT_ASSERT_NOT_NULL(resource);
  • uspace/lib/ui/test/rbutton.c

    r77ffa01 r9c7dc8e  
    176176        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    177177
    178         rc = ui_resource_create(gc, &resource);
     178        rc = ui_resource_create(gc, false, &resource);
    179179        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    180180        PCUT_ASSERT_NOT_NULL(resource);
     
    244244        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    245245
    246         rc = ui_resource_create(gc, &resource);
     246        rc = ui_resource_create(gc, false, &resource);
    247247        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    248248        PCUT_ASSERT_NOT_NULL(resource);
     
    303303        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    304304
    305         rc = ui_resource_create(gc, &resource);
     305        rc = ui_resource_create(gc, false, &resource);
    306306        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    307307        PCUT_ASSERT_NOT_NULL(resource);
     
    368368        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    369369
    370         rc = ui_resource_create(gc, &resource);
     370        rc = ui_resource_create(gc, false, &resource);
    371371        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    372372        PCUT_ASSERT_NOT_NULL(resource);
     
    440440        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    441441
    442         rc = ui_resource_create(gc, &resource);
     442        rc = ui_resource_create(gc, false, &resource);
    443443        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    444444        PCUT_ASSERT_NOT_NULL(resource);
     
    506506        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    507507
    508         rc = ui_resource_create(gc, &resource);
     508        rc = ui_resource_create(gc, false, &resource);
    509509        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    510510        PCUT_ASSERT_NOT_NULL(resource);
  • uspace/lib/ui/test/resource.c

    r77ffa01 r9c7dc8e  
    8080        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    8181
    82         rc = ui_resource_create(gc, &resource);
     82        rc = ui_resource_create(gc, false, &resource);
    8383        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    8484        PCUT_ASSERT_NOT_NULL(resource);
  • uspace/lib/ui/test/slider.c

    r77ffa01 r9c7dc8e  
    161161        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    162162
    163         rc = ui_resource_create(gc, &resource);
     163        rc = ui_resource_create(gc, false, &resource);
    164164        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    165165        PCUT_ASSERT_NOT_NULL(resource);
     
    222222        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    223223
    224         rc = ui_resource_create(gc, &resource);
     224        rc = ui_resource_create(gc, false, &resource);
    225225        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    226226        PCUT_ASSERT_NOT_NULL(resource);
     
    278278        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    279279
    280         rc = ui_resource_create(gc, &resource);
     280        rc = ui_resource_create(gc, false, &resource);
    281281        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    282282        PCUT_ASSERT_NOT_NULL(resource);
     
    342342        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    343343
    344         rc = ui_resource_create(gc, &resource);
     344        rc = ui_resource_create(gc, false, &resource);
    345345        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    346346        PCUT_ASSERT_NOT_NULL(resource);
     
    403403        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    404404
    405         rc = ui_resource_create(gc, &resource);
     405        rc = ui_resource_create(gc, false, &resource);
    406406        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    407407        PCUT_ASSERT_NOT_NULL(resource);
  • uspace/lib/ui/test/wdecor.c

    r77ffa01 r9c7dc8e  
    177177        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    178178
    179         rc = ui_resource_create(gc, &resource);
     179        rc = ui_resource_create(gc, false, &resource);
    180180        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    181181        PCUT_ASSERT_NOT_NULL(resource);
Note: See TracChangeset for help on using the changeset viewer.