Changeset d68239a1 in mainline for uspace/lib/ui/src/pbutton.c


Ignore:
Timestamp:
2022-04-04T14:48:41Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
86fff971
Parents:
0d1d0ea
git-author:
Jiri Svoboda <jiri@…> (2022-04-03 17:48:17)
git-committer:
Jiri Svoboda <jiri@…> (2022-04-04 14:48:41)
Message:

Scrollbar needs custom button decorations

Push button now allows setting a 'custom decoration' which means
instead of painting the button text a callback function is invoked
to paint the decoration.

File:
1 edited

Legend:

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

    r0d1d0ea rd68239a1  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3232/**
    3333 * @file Push button
     34 *
     35 * Push button either uses text as decoration, or it can use a caller-provided
     36 * function to paint the decoration.
    3437 */
    3538
     
    136139}
    137140
     141/** Set push button decoration ops.
     142 *
     143 * @param pbutton Push button
     144 * @param ops Push button decoration callbacks
     145 * @param arg Decoration ops argument
     146 */
     147void ui_pbutton_set_decor_ops(ui_pbutton_t *pbutton,
     148    ui_pbutton_decor_ops_t *ops, void *arg)
     149{
     150        pbutton->decor_ops = ops;
     151        pbutton->decor_arg = arg;
     152}
     153
    138154/** Set button rectangle.
    139155 *
     
    306322        }
    307323
    308         gfx_text_fmt_init(&fmt);
    309         fmt.font = pbutton->res->font;
    310         fmt.color = pbutton->res->btn_text_color;
    311         fmt.halign = gfx_halign_center;
    312         fmt.valign = gfx_valign_center;
    313 
    314         rc = gfx_puttext(&pos, &fmt, pbutton->caption);
    315         if (rc != EOK)
    316                 goto error;
     324        if (pbutton->decor_ops != NULL && pbutton->decor_ops->paint != NULL) {
     325                /* Custom decoration */
     326                rc = pbutton->decor_ops->paint(pbutton, pbutton->decor_arg,
     327                    &pos);
     328                if (rc != EOK)
     329                        goto error;
     330        } else {
     331                /* Text decoration */
     332                gfx_text_fmt_init(&fmt);
     333                fmt.font = pbutton->res->font;
     334                fmt.color = pbutton->res->btn_text_color;
     335                fmt.halign = gfx_halign_center;
     336                fmt.valign = gfx_valign_center;
     337
     338                rc = gfx_puttext(&pos, &fmt, pbutton->caption);
     339                if (rc != EOK)
     340                        goto error;
     341        }
    317342
    318343        rc = ui_pbutton_paint_frame(pbutton);
Note: See TracChangeset for help on using the changeset viewer.