Mercurial > molko
diff examples/example-label.c @ 153:aa6e70e330a1
ui: make label less smart
It should not contain alignment because it should be handled by the user
tself.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 15 Oct 2020 18:45:27 +0200 |
parents | 9733d379be89 |
children | c3a40062acc2 |
line wrap: on
line diff
--- a/examples/example-label.c Thu Oct 15 18:09:45 2020 +0200 +++ b/examples/example-label.c Thu Oct 15 18:45:27 2020 +0200 @@ -24,12 +24,74 @@ #include <core/util.h> #include <core/window.h> +#include <ui/align.h> #include <ui/label.h> #include <ui/theme.h> #define W (1280) #define H (720) +struct { + enum align align; + struct label label; +} table[] = { + { + .align = ALIGN_TOP_LEFT, + .label = { + .text = "Top left" + } + }, + { + .align = ALIGN_TOP, + .label = { + .text = "Top", + } + }, + { + .align = ALIGN_TOP_RIGHT, + .label = { + .text = "Top right", + } + }, + { + .align = ALIGN_RIGHT, + .label = { + .text = "Right", + } + }, + { + .align = ALIGN_BOTTOM_RIGHT, + .label = { + .text = "Bottom right", + } + }, + { + .align = ALIGN_BOTTOM, + .label = { + .text = "Bottom", + } + }, + { + .align = ALIGN_BOTTOM_LEFT, + .label = { + .text = "Bottom left", + } + }, + { + .align = ALIGN_LEFT, + .label = { + .text = "Left", + } + }, + { + .align = ALIGN_CENTER, + .label = { + .text = "The world is Malikania.", + .flags = LABEL_FLAGS_SHADOW + } + } +}; + static void init(void) { @@ -37,6 +99,13 @@ !window_init("Example - Label", W, H) || !theme_init()) panic(); + + for (size_t i = 0; i < NELEM(table); ++i) { + struct label *l = &table[i].label; + + label_query(l); + align(table[i].align, &l->x, &l->y, l->w, l->h, 0, 0, W, H); + } } static void @@ -51,81 +120,6 @@ run(void) { struct clock clock = {0}; - struct label labels[] = { - { - .x = 0, - .y = 0, - .w = W, - .h = H, - .text = "Top left", - .align = ALIGN_TOP_LEFT - }, - { - .x = 0, - .y = 0, - .w = W, - .h = H, - .text = "Top", - .align = ALIGN_TOP - }, - { - .x = 0, - .y = 0, - .w = W, - .h = H, - .text = "Top right", - .align = ALIGN_TOP_RIGHT - }, - { - .x = 0, - .y = 0, - .w = W, - .h = H, - .text = "Right", - .align = ALIGN_RIGHT - }, - { - .x = 0, - .y = 0, - .w = W, - .h = H, - .text = "Bottom right", - .align = ALIGN_BOTTOM_RIGHT - }, - { - .x = 0, - .y = 0, - .w = W, - .h = H, - .text = "Bottom", - .align = ALIGN_BOTTOM - }, - { - .x = 0, - .y = 0, - .w = W, - .h = H, - .text = "Bottom left", - .align = ALIGN_BOTTOM_LEFT - }, - { - .x = 0, - .y = 0, - .w = W, - .h = H, - .text = "Left", - .align = ALIGN_LEFT - }, - { - .x = 0, - .y = 0, - .w = W, - .h = H, - .text = "The world is Malikania.", - .flags = LABEL_FLAGS_SHADOW, - .align = ALIGN_CENTER - }, - }; struct label mlabel = { .text = "This one follows your mouse and is not aligned." }; @@ -154,8 +148,8 @@ painter_set_color(0x4f8fbaff); painter_clear(); - for (size_t i = 0; i < NELEM(labels); ++i) - label_draw(&labels[i]); + for (size_t i = 0; i < NELEM(table); ++i) + label_draw(&table[i].label); label_draw(&mlabel); painter_present();