Ignore:
File:
1 edited

Legend:

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

    r307d4d2 r806d761  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5252        checkbox_box_h = 16,
    5353        checkbox_label_margin = 8,
     54        checkbox_cross_n = 5,
     55        checkbox_cross_w = 2,
     56        checkbox_cross_h = 2
    5457};
    5558
     
    136139}
    137140
    138 /** Set button rectangle.
    139  *
    140  * @param checkbox Button
    141  * @param rect New button rectangle
     141/** Set check box rectangle.
     142 *
     143 * @param checkbox Check box
     144 * @param rect New check box rectangle
    142145 */
    143146void ui_checkbox_set_rect(ui_checkbox_t *checkbox, gfx_rect_t *rect)
    144147{
    145148        checkbox->rect = *rect;
     149}
     150
     151/** Return if check box is checked.
     152 *
     153 * @param checkbox Check box
     154 * @return @c true iff check box is checked
     155 */
     156bool ui_checkbox_get_checked(ui_checkbox_t *checkbox)
     157{
     158        return checkbox->checked;
     159}
     160
     161/** Set check box checked state.
     162 *
     163 * @param checkbox Check box
     164 * @param checked @c true iff checkbox should be checked
     165 */
     166void ui_checkbox_set_checked(ui_checkbox_t *checkbox, bool checked)
     167{
     168        checkbox->checked = checked;
    146169}
    147170
     
    188211
    189212        if (checkbox->checked) {
    190                 box_center.x = (box_inside.p0.x + box_inside.p1.x) / 2;
    191                 box_center.y = (box_inside.p0.y + box_inside.p1.y) / 2;
    192 
    193                 gfx_text_fmt_init(&fmt);
    194                 fmt.color = checkbox->res->entry_fg_color;
    195                 fmt.halign = gfx_halign_center;
    196                 fmt.valign = gfx_valign_center;
    197 
    198                 rc = gfx_puttext(checkbox->res->font, &box_center, &fmt, "X");
     213                rc = gfx_set_color(checkbox->res->gc,
     214                    checkbox->res->entry_fg_color);
    199215                if (rc != EOK)
    200216                        goto error;
     217
     218                box_center.x = (box_inside.p0.x + box_inside.p1.x) / 2 - 1;
     219                box_center.y = (box_inside.p0.y + box_inside.p1.y) / 2 - 1;
     220
     221                rc = ui_paint_cross(checkbox->res->gc, &box_center,
     222                    checkbox_cross_n, checkbox_cross_w, checkbox_cross_h);
     223                if (rc != EOK)
     224                        goto error;
    201225        }
    202226
     
    207231
    208232        gfx_text_fmt_init(&fmt);
     233        fmt.font = checkbox->res->font;
    209234        fmt.color = checkbox->res->wnd_text_color;
    210235        fmt.halign = gfx_halign_left;
    211236        fmt.valign = gfx_valign_center;
    212237
    213         rc = gfx_puttext(checkbox->res->font, &pos, &fmt, checkbox->caption);
     238        rc = gfx_puttext(&pos, &fmt, checkbox->caption);
    214239        if (rc != EOK)
    215240                goto error;
     
    244269
    245270        gfx_text_fmt_init(&fmt);
     271        fmt.font = checkbox->res->font;
    246272        fmt.color = depressed ? checkbox->res->entry_act_bg_color :
    247273            checkbox->res->wnd_text_color;
     
    249275        fmt.valign = gfx_valign_top;
    250276
    251         rc = gfx_puttext(checkbox->res->font, &pos, &fmt,
    252             checkbox->checked ? "[X]" : "[ ]");
     277        rc = gfx_puttext(&pos, &fmt, checkbox->checked ? "[X]" : "[ ]");
    253278        if (rc != EOK)
    254279                goto error;
     
    259284        fmt.color = checkbox->res->wnd_text_color;
    260285
    261         rc = gfx_puttext(checkbox->res->font, &pos, &fmt, checkbox->caption);
     286        rc = gfx_puttext(&pos, &fmt, checkbox->caption);
    262287        if (rc != EOK)
    263288                goto error;
     
    397422                }
    398423                break;
     424        case POS_DCLICK:
     425                break;
    399426        }
    400427
Note: See TracChangeset for help on using the changeset viewer.