Ignore:
File:
1 edited

Legend:

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

    r806d761 rb433f68  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2021 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
    5754};
    5855
     
    139136}
    140137
    141 /** Set check box rectangle.
    142  *
    143  * @param checkbox Check box
    144  * @param rect New check box rectangle
     138/** Set button rectangle.
     139 *
     140 * @param checkbox Button
     141 * @param rect New button rectangle
    145142 */
    146143void ui_checkbox_set_rect(ui_checkbox_t *checkbox, gfx_rect_t *rect)
     
    149146}
    150147
    151 /** Return if check box is checked.
    152  *
    153  * @param checkbox Check box
    154  * @return @c true iff check box is checked
    155  */
    156 bool 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  */
    166 void ui_checkbox_set_checked(ui_checkbox_t *checkbox, bool checked)
    167 {
    168         checkbox->checked = checked;
    169 }
    170 
    171 /** Paint check box in graphics mode.
     148/** Paint check box.
    172149 *
    173150 * @param checkbox Check box
    174151 * @return EOK on success or an error code
    175152 */
    176 errno_t ui_checkbox_paint_gfx(ui_checkbox_t *checkbox)
     153errno_t ui_checkbox_paint(ui_checkbox_t *checkbox)
    177154{
    178155        gfx_coord2_t pos;
     
    211188
    212189        if (checkbox->checked) {
    213                 rc = gfx_set_color(checkbox->res->gc,
    214                     checkbox->res->entry_fg_color);
     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");
    215199                if (rc != EOK)
    216200                        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;
    225201        }
    226202
     
    231207
    232208        gfx_text_fmt_init(&fmt);
    233         fmt.font = checkbox->res->font;
    234209        fmt.color = checkbox->res->wnd_text_color;
    235210        fmt.halign = gfx_halign_left;
    236211        fmt.valign = gfx_valign_center;
    237212
    238         rc = gfx_puttext(&pos, &fmt, checkbox->caption);
     213        rc = gfx_puttext(checkbox->res->font, &pos, &fmt, checkbox->caption);
    239214        if (rc != EOK)
    240215                goto error;
     
    247222error:
    248223        return rc;
    249 }
    250 
    251 /** Paint check box in text mode.
    252  *
    253  * @param checkbox Check box
    254  * @return EOK on success or an error code
    255  */
    256 errno_t ui_checkbox_paint_text(ui_checkbox_t *checkbox)
    257 {
    258         gfx_coord2_t pos;
    259         gfx_text_fmt_t fmt;
    260         bool depressed;
    261         errno_t rc;
    262 
    263         /* Paint checkbox */
    264 
    265         depressed = checkbox->held && checkbox->inside;
    266 
    267         pos.x = checkbox->rect.p0.x;
    268         pos.y = checkbox->rect.p0.y;
    269 
    270         gfx_text_fmt_init(&fmt);
    271         fmt.font = checkbox->res->font;
    272         fmt.color = depressed ? checkbox->res->entry_act_bg_color :
    273             checkbox->res->wnd_text_color;
    274         fmt.halign = gfx_halign_left;
    275         fmt.valign = gfx_valign_top;
    276 
    277         rc = gfx_puttext(&pos, &fmt, checkbox->checked ? "[X]" : "[ ]");
    278         if (rc != EOK)
    279                 goto error;
    280 
    281         /* Paint checkbox label */
    282 
    283         pos.x += 4;
    284         fmt.color = checkbox->res->wnd_text_color;
    285 
    286         rc = gfx_puttext(&pos, &fmt, checkbox->caption);
    287         if (rc != EOK)
    288                 goto error;
    289 
    290         rc = gfx_update(checkbox->res->gc);
    291         if (rc != EOK)
    292                 goto error;
    293 
    294         return EOK;
    295 error:
    296         return rc;
    297 }
    298 
    299 /** Paint check box.
    300  *
    301  * @param checkbox Check box
    302  * @return EOK on success or an error code
    303  */
    304 errno_t ui_checkbox_paint(ui_checkbox_t *checkbox)
    305 {
    306         if (checkbox->res->textmode)
    307                 return ui_checkbox_paint_text(checkbox);
    308         else
    309                 return ui_checkbox_paint_gfx(checkbox);
    310224}
    311225
     
    422336                }
    423337                break;
    424         case POS_DCLICK:
    425                 break;
    426338        }
    427339
Note: See TracChangeset for help on using the changeset viewer.