comparison libui/ui/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 1008a796a9e7
children e05a792f6910
comparison
equal deleted inserted replaced
152:1008a796a9e7 153:aa6e70e330a1
39 assert(t); 39 assert(t);
40 assert(label); 40 assert(label);
41 41
42 struct font *font; 42 struct font *font;
43 struct texture tex; 43 struct texture tex;
44 int x, y, bx, by;
45 unsigned int tw, th, bw, bh;
46 44
47 /* Compute real box size according to padding. */
48 bx = label->x + t->padding;
49 by = label->y + t->padding;
50 bw = label->w - (t->padding * 2);
51 bh = label->h - (t->padding * 2);
52
53 /* Make a shallow copy of the interface font. */
54 font = t->fonts[THEME_FONT_INTERFACE]; 45 font = t->fonts[THEME_FONT_INTERFACE];
55
56 /* Compute text size. */
57 if (!font_box(font, label->text, &tw, &th))
58 panic();
59
60 /* Align if needed. */
61 x = label->x;
62 y = label->y;
63
64 align(label->align, &x, &y, tw, th, bx, by, bw, bh);
65 46
66 /* Shadow text, only if enabled. */ 47 /* Shadow text, only if enabled. */
67 if (label->flags & LABEL_FLAGS_SHADOW) { 48 if (label->flags & LABEL_FLAGS_SHADOW) {
68 font->color = t->colors[THEME_COLOR_SHADOW]; 49 font->color = t->colors[THEME_COLOR_SHADOW];
69 50
70 if (!font_render(font, &tex, label->text)) 51 if (!font_render(font, &tex, label->text))
71 panic(); 52 panic();
72 53
73 texture_draw(&tex, x + 1, y + 1); 54 texture_draw(&tex, label->x + 1, label->y + 1);
74 texture_finish(&tex); 55 texture_finish(&tex);
75 } 56 }
76 57
77 /* Normal text. */ 58 /* Normal text. */
78 font->color = t->colors[THEME_COLOR_NORMAL]; 59 font->color = t->colors[THEME_COLOR_NORMAL];
79 60
80 if (!font_render(font, &tex, label->text)) 61 if (!font_render(font, &tex, label->text))
81 panic(); 62 panic();
82 63
83 texture_draw(&tex, x, y); 64 texture_draw(&tex, label->x, label->y);
84 texture_finish(&tex); 65 texture_finish(&tex);
66 }
67
68 void
69 label_query(struct label *label)
70 {
71 assert(label);
72 assert(label->text);
73
74 struct theme *t = label->theme ? label->theme : theme_default();
75
76 if (!font_box(t->fonts[THEME_FONT_INTERFACE], label->text, &label->w, &label->h))
77 panic();
85 } 78 }
86 79
87 void 80 void
88 label_draw(const struct label *label) 81 label_draw(const struct label *label)
89 { 82 {