Changeset 58a67050 in mainline


Ignore:
Timestamp:
2020-10-21T22:26:33Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
08a79303
Parents:
a2f173b
Message:

Support different label text alignment

Location:
uspace
Files:
5 edited

Legend:

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

    ra2f173b r58a67050  
    259259        rect.p1.y = 50;
    260260        ui_label_set_rect(demo.label, &rect);
     261        ui_label_set_halign(demo.label, gfx_halign_center);
    261262
    262263        rc = ui_pbutton_create(ui_res, "Confirm", &demo.pb1);
  • uspace/lib/ui/include/ui/label.h

    ra2f173b r58a67050  
    3939#include <errno.h>
    4040#include <gfx/coord.h>
     41#include <gfx/text.h>
    4142#include <types/ui/label.h>
    4243#include <types/ui/resource.h>
     
    4647extern void ui_label_destroy(ui_label_t *);
    4748extern void ui_label_set_rect(ui_label_t *, gfx_rect_t *);
     49extern void ui_label_set_halign(ui_label_t *, gfx_halign_t);
    4850extern errno_t ui_label_set_text(ui_label_t *, const char *);
    4951extern errno_t ui_label_paint(ui_label_t *);
  • uspace/lib/ui/private/label.h

    ra2f173b r58a67050  
    3939
    4040#include <gfx/coord.h>
     41#include <gfx/text.h>
    4142
    4243/** Actual structure of label.
     
    4950        /** Label rectangle */
    5051        gfx_rect_t rect;
     52        /** Horizontal alignment */
     53        gfx_halign_t halign;
    5154        /** Text */
    5255        char *text;
  • uspace/lib/ui/src/label.c

    ra2f173b r58a67050  
    6868
    6969        label->res = resource;
     70        label->halign = gfx_halign_left;
    7071        *rlabel = label;
    7172        return EOK;
     
    9293{
    9394        label->rect = *rect;
     95}
     96
     97/** Set label horizontal text alignment.
     98 *
     99 * @param label Label
     100 * @param halign Horizontal alignment
     101 */
     102void ui_label_set_halign(ui_label_t *label, gfx_halign_t halign)
     103{
     104        label->halign = halign;
    94105}
    95106
     
    135146                goto error;
    136147
    137         pos = label->rect.p0;
     148        switch (label->halign) {
     149        case gfx_halign_left:
     150        case gfx_halign_justify:
     151                pos.x = label->rect.p0.x;
     152                break;
     153        case gfx_halign_center:
     154                pos.x = (label->rect.p0.x + label->rect.p1.x) / 2;
     155                break;
     156        case gfx_halign_right:
     157                pos.y = label->rect.p1.x;
     158                break;
     159        }
     160
     161        pos.y = label->rect.p0.y;
    138162
    139163        gfx_text_fmt_init(&fmt);
    140         fmt.halign = gfx_halign_left;
     164        fmt.halign = label->halign;
    141165        fmt.valign = gfx_valign_top;
    142166
  • uspace/lib/ui/test/label.c

    ra2f173b r58a67050  
    121121}
    122122
     123/** Set button text horizontal alignment sets internal field */
     124PCUT_TEST(set_halign)
     125{
     126        ui_label_t *label;
     127        errno_t rc;
     128
     129        rc = ui_label_create(NULL, "Hello", &label);
     130        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     131
     132        ui_label_set_halign(label, gfx_halign_left);
     133        PCUT_ASSERT_EQUALS(gfx_halign_left, label->halign);
     134        ui_label_set_halign(label, gfx_halign_center);
     135        PCUT_ASSERT_EQUALS(gfx_halign_center, label->halign);
     136
     137        ui_label_destroy(label);
     138}
     139
    123140/** Set button rectangle sets internal field */
    124141PCUT_TEST(set_text)
Note: See TracChangeset for help on using the changeset viewer.