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


Ignore:
Timestamp:
2020-10-13T20:06:47Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c9a7adc
Parents:
47728678
Message:

Button press visual feedback

File:
1 edited

Legend:

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

    r47728678 rf6df5a3  
    4444#include "../private/pbutton.h"
    4545#include "../private/resource.h"
     46
     47/** Caption movement when button is pressed down */
     48enum {
     49        ui_pb_press_dx = 2,
     50        ui_pb_press_dy = 2
     51};
    4652
    4753/** Create new push button.
     
    106112        errno_t rc;
    107113
    108         rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &color);
    109         if (rc != EOK)
    110                 goto error;
     114        if (pbutton->held) {
     115                rc = gfx_color_new_rgb_i16(0x8000, 0, 0, &color);
     116                if (rc != EOK)
     117                        goto error;
     118        } else {
     119                rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &color);
     120                if (rc != EOK)
     121                        goto error;
     122        }
    111123
    112124        rc = gfx_set_color(pbutton->res->gc, color);
     
    132144        pos.y = (pbutton->rect.p0.y + pbutton->rect.p1.y) / 2;
    133145
     146        if (pbutton->held) {
     147                pos.x += ui_pb_press_dx;
     148                pos.y += ui_pb_press_dy;
     149        }
     150
    134151        gfx_text_fmt_init(&fmt);
    135152        fmt.halign = gfx_halign_center;
     
    149166}
    150167
     168/** Press down button.
     169 *
     170 * This does not automatically repaint the button.
     171 *
     172 * @param pbutton Push button
     173 */
     174void ui_pbutton_press(ui_pbutton_t *pbutton)
     175{
     176        pbutton->held = true;
     177}
     178
     179/** Release button.
     180 *
     181 * This does not automatically repaint the button.
     182 *
     183 * @param pbutton Push button
     184 */
     185void ui_pbutton_release(ui_pbutton_t *pbutton)
     186{
     187        pbutton->held = false;
     188}
     189
    151190/** @}
    152191 */
Note: See TracChangeset for help on using the changeset viewer.