Changeset d70dc1c4 in mainline


Ignore:
Timestamp:
2021-01-06T10:06:42Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7020d1f
Parents:
e037cf37
git-author:
Jiri Svoboda <jiri@…> (2021-01-05 18:06:37)
git-committer:
Jiri Svoboda <jiri@…> (2021-01-06 10:06:42)
Message:

Check box

Location:
uspace
Files:
5 added
10 edited

Legend:

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

    re037cf37 rd70dc1c4  
    6262};
    6363
     64static void checkbox_switched(ui_checkbox_t *, void *, bool);
     65
     66static ui_checkbox_cb_t checkbox_cb = {
     67        .switched = checkbox_switched
     68};
     69
    6470/** Window close button was clicked.
    6571 *
     
    9197        } else {
    9298                rc = ui_entry_set_text(demo->entry, "Cancel pressed");
     99                if (rc != EOK)
     100                        printf("Error changing entry text.\n");
     101                (void) ui_entry_paint(demo->entry);
     102        }
     103}
     104
     105/** Check box was switched.
     106 *
     107 * @param checkbox Check box
     108 * @param arg Argument (demo)
     109 */
     110static void checkbox_switched(ui_checkbox_t *checkbox, void *arg, bool enable)
     111{
     112        ui_demo_t *demo = (ui_demo_t *) arg;
     113        errno_t rc;
     114
     115        if (enable) {
     116                rc = ui_entry_set_text(demo->entry, "Checked");
     117                if (rc != EOK)
     118                        printf("Error changing entry text.\n");
     119                (void) ui_entry_paint(demo->entry);
     120        } else {
     121                rc = ui_entry_set_text(demo->entry, "Unchecked");
    93122                if (rc != EOK)
    94123                        printf("Error changing entry text.\n");
     
    124153        params.rect.p0.y = 0;
    125154        params.rect.p1.x = 220;
    126         params.rect.p1.y = 180;
     155        params.rect.p1.y = 220;
    127156
    128157        memset((void *) &demo, 0, sizeof(demo));
     
    258287
    259288        rc = ui_fixed_add(demo.fixed, ui_image_ctl(demo.image));
     289        if (rc != EOK) {
     290                printf("Error adding control to layout.\n");
     291                return rc;
     292        }
     293
     294        rc = ui_checkbox_create(ui_res, "Check me", &demo.checkbox);
     295        if (rc != EOK) {
     296                printf("Error creating check box.\n");
     297                return rc;
     298        }
     299
     300        ui_checkbox_set_cb(demo.checkbox, &checkbox_cb, (void *) &demo);
     301
     302        rect.p0.x = 15;
     303        rect.p0.y = 180;
     304        rect.p1.x = 140;
     305        rect.p1.y = 200;
     306        ui_checkbox_set_rect(demo.checkbox, &rect);
     307
     308        rc = ui_fixed_add(demo.fixed, ui_checkbox_ctl(demo.checkbox));
    260309        if (rc != EOK) {
    261310                printf("Error adding control to layout.\n");
  • uspace/app/uidemo/uidemo.h

    re037cf37 rd70dc1c4  
    3838
    3939#include <display.h>
     40#include <ui/checkbox.h>
    4041#include <ui/entry.h>
    4142#include <ui/fixed.h>
     
    5556        ui_pbutton_t *pb1;
    5657        ui_pbutton_t *pb2;
     58        ui_checkbox_t *checkbox;
    5759} ui_demo_t;
    5860
  • uspace/lib/ui/include/ui/paint.h

    re037cf37 rd70dc1c4  
    4040#include <gfx/color.h>
    4141#include <gfx/coord.h>
     42#include <types/ui/resource.h>
    4243
    4344errno_t ui_paint_bevel(gfx_context_t *, gfx_rect_t *, gfx_color_t *,
    4445    gfx_color_t *, gfx_coord_t, gfx_rect_t *);
     46errno_t ui_paint_inset_frame(ui_resource_t *, gfx_rect_t *, gfx_rect_t *);
    4547
    4648#endif
  • uspace/lib/ui/meson.build

    re037cf37 rd70dc1c4  
    2929deps = [ 'gfx', 'gfxfont', 'memgfx', 'display' ]
    3030src = files(
     31        'src/checkbox.c',
    3132        'src/control.c',
    3233        'src/dummygc.c',
     
    4445
    4546test_src = files(
     47        'test/checkbox.c',
    4648        'test/control.c',
    4749        'test/entry.c',
  • uspace/lib/ui/private/resource.h

    re037cf37 rd70dc1c4  
    9292        /** Entry (text entry, checkbox, raido button) background color */
    9393        gfx_color_t *entry_bg_color;
     94        /** Entry (text entry, checkbox, raido button) active background color */
     95        gfx_color_t *entry_act_bg_color;
    9496};
    9597
  • uspace/lib/ui/src/entry.c

    re037cf37 rd70dc1c4  
    173173        gfx_text_fmt_t fmt;
    174174        gfx_coord2_t pos;
    175         gfx_rect_t frame;
    176175        gfx_rect_t inside;
    177176        errno_t rc;
     
    179178        /* Paint inset frame */
    180179
    181         rc = ui_paint_bevel(entry->res->gc, &entry->rect,
    182             entry->res->wnd_shadow_color, entry->res->wnd_highlight_color,
    183             1, &frame);
    184         if (rc != EOK)
    185                 goto error;
    186 
    187         rc = ui_paint_bevel(entry->res->gc, &frame,
    188             entry->res->wnd_frame_sh_color, entry->res->wnd_frame_hi_color,
    189             1, &inside);
     180        rc = ui_paint_inset_frame(entry->res, &entry->rect, &inside);
    190181        if (rc != EOK)
    191182                goto error;
  • uspace/lib/ui/src/paint.c

    re037cf37 rd70dc1c4  
    3939#include <gfx/render.h>
    4040#include <ui/paint.h>
     41#include "../private/resource.h"
    4142
    4243/** Paint bevel.
     
    118119}
    119120
     121/** Paint inset frame.
     122 *
     123 * @param resource UI resource
     124 * @param rect Rectangle to paint onto
     125 * @param inside Place to store inside rectangle or @c NULL
     126 * @return EOK on success or an error code
     127 */
     128errno_t ui_paint_inset_frame(ui_resource_t *resource, gfx_rect_t *rect,
     129    gfx_rect_t *inside)
     130{
     131        gfx_rect_t frame;
     132        errno_t rc;
     133
     134        rc = ui_paint_bevel(resource->gc, rect,
     135            resource->wnd_shadow_color, resource->wnd_highlight_color,
     136            1, &frame);
     137        if (rc != EOK)
     138                goto error;
     139
     140        rc = ui_paint_bevel(resource->gc, &frame,
     141            resource->wnd_frame_sh_color, resource->wnd_frame_hi_color,
     142            1, inside);
     143        if (rc != EOK)
     144                goto error;
     145
     146        return EOK;
     147error:
     148        return rc;
     149}
     150
    120151/** @}
    121152 */
  • uspace/lib/ui/src/resource.c

    re037cf37 rd70dc1c4  
    7676        gfx_color_t *entry_fg_color = NULL;
    7777        gfx_color_t *entry_bg_color = NULL;
     78        gfx_color_t *entry_act_bg_color = NULL;
    7879        errno_t rc;
    7980
     
    166167
    167168        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &entry_bg_color);
     169        if (rc != EOK)
     170                goto error;
     171
     172        rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &entry_act_bg_color);
    168173        if (rc != EOK)
    169174                goto error;
     
    193198        resource->entry_fg_color = entry_fg_color;
    194199        resource->entry_bg_color = entry_bg_color;
     200        resource->entry_act_bg_color = entry_act_bg_color;
    195201
    196202        *rresource = resource;
     
    234240        if (entry_bg_color != NULL)
    235241                gfx_color_delete(entry_bg_color);
     242        if (entry_act_bg_color != NULL)
     243                gfx_color_delete(entry_act_bg_color);
    236244
    237245        if (tface != NULL)
     
    270278        gfx_color_delete(resource->entry_fg_color);
    271279        gfx_color_delete(resource->entry_bg_color);
     280        gfx_color_delete(resource->entry_act_bg_color);
    272281
    273282        gfx_font_close(resource->font);
  • uspace/lib/ui/test/main.c

    re037cf37 rd70dc1c4  
    3232
    3333PCUT_IMPORT(control);
     34PCUT_IMPORT(checkbox);
    3435PCUT_IMPORT(entry);
    3536PCUT_IMPORT(fixed);
  • uspace/lib/ui/test/paint.c

    re037cf37 rd70dc1c4  
    3333#include <stdbool.h>
    3434#include <ui/paint.h>
     35#include <ui/resource.h>
    3536
    3637PCUT_INIT;
     
    103104        gfx_color_delete(color2);
    104105        gfx_color_delete(color1);
     106        rc = gfx_context_delete(gc);
     107        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     108}
     109
     110/** Paint inset frame */
     111PCUT_TEST(inset_frame)
     112{
     113        errno_t rc;
     114        gfx_context_t *gc = NULL;
     115        ui_resource_t *resource = NULL;
     116        test_gc_t tgc;
     117        gfx_rect_t rect;
     118        gfx_rect_t inside;
     119
     120        memset(&tgc, 0, sizeof(tgc));
     121        rc = gfx_context_new(&ops, &tgc, &gc);
     122        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     123
     124        rc = ui_resource_create(gc, &resource);
     125        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     126        PCUT_ASSERT_NOT_NULL(resource);
     127
     128        /* Paint inset frame with NULL 'inside' output parameter */
     129        rc = ui_paint_inset_frame(resource, &rect, NULL);
     130        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     131
     132        /* Paint inset frame with valid 'inside' output parameter */
     133        rc = ui_paint_inset_frame(resource, &rect, &inside);
     134        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     135
    105136        rc = gfx_context_delete(gc);
    106137        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
Note: See TracChangeset for help on using the changeset viewer.