Mercurial > molko
comparison libmlk-ui/mlk/ui/label.c @ 505:6100c643dba0
ui: finally ditch theme
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 01 Mar 2023 16:24:07 +0100 |
parents | 52a305833381 |
children | e205625015ba |
comparison
equal
deleted
inserted
replaced
504:52a305833381 | 505:6100c643dba0 |
---|---|
22 #include <mlk/core/font.h> | 22 #include <mlk/core/font.h> |
23 #include <mlk/core/panic.h> | 23 #include <mlk/core/panic.h> |
24 #include <mlk/core/texture.h> | 24 #include <mlk/core/texture.h> |
25 | 25 |
26 #include "label.h" | 26 #include "label.h" |
27 #include "theme.h" | 27 #include "ui.h" |
28 | 28 |
29 #define STYLE_INVOKE(s, f, ...) \ | 29 #define STYLE_INVOKE(s, f, ...) \ |
30 do { \ | 30 do { \ |
31 if (s && s->f) \ | 31 if (s && s->f) \ |
32 s->f(s, __VA_ARGS__); \ | 32 s->f(s, __VA_ARGS__); \ |
38 style_font(struct mlk_label_style *style) | 38 style_font(struct mlk_label_style *style) |
39 { | 39 { |
40 if (style && style->text_font) | 40 if (style && style->text_font) |
41 return style->text_font; | 41 return style->text_font; |
42 | 42 |
43 return mlk_theme.fonts[MLK_THEME_FONT_INTERFACE]; | 43 return mlk_ui_fonts[MLK_UI_FONT_INTERFACE]; |
44 } | 44 } |
45 | 45 |
46 static void | 46 static void |
47 draw(struct mlk_label_style *style, const struct mlk_label *label) | 47 draw(struct mlk_label_style *style, const struct mlk_label *label) |
48 { | 48 { |
50 struct mlk_texture tex; | 50 struct mlk_texture tex; |
51 int err; | 51 int err; |
52 | 52 |
53 font = style_font(style); | 53 font = style_font(style); |
54 | 54 |
55 /* Shadow text, only if enabled. */ | |
56 if (label->flags & MLK_LABEL_FLAGS_SHADOW) { | |
57 if ((err = mlk_font_render(font, &tex, label->text, style->shadow_color)) < 0) | |
58 mlk_panic(err); | |
59 | |
60 mlk_texture_draw(&tex, label->x + 1, label->y + 1); | |
61 mlk_texture_finish(&tex); | |
62 } | |
63 | |
64 /* Normal text. */ | |
65 if ((err = mlk_font_render(font, &tex, label->text, style->text_color)) < 0) | 55 if ((err = mlk_font_render(font, &tex, label->text, style->text_color)) < 0) |
66 mlk_panic(err); | 56 mlk_panic(err); |
67 | 57 |
68 mlk_texture_draw(&tex, label->x, label->y); | 58 mlk_texture_draw(&tex, label->x, label->y); |
69 mlk_texture_finish(&tex); | 59 mlk_texture_finish(&tex); |
70 } | 60 } |
71 | 61 |
72 struct mlk_label_style mlk_label_style = { | 62 struct mlk_label_style mlk_label_style = { |
73 .shadow_color = 0x000000ff, | 63 .text_color = 0x000000ff, |
74 .text_color = 0xffffffff, | |
75 .draw = draw | 64 .draw = draw |
76 }; | 65 }; |
66 | |
67 struct mlk_label_style mlk_label_style_selected = { | |
68 .text_color = 0x7da42dff, | |
69 .draw = draw | |
70 }; | |
71 | |
72 void | |
73 mlk_label_init(struct mlk_label *label) | |
74 { | |
75 assert(mlk_label_ok(label)); | |
76 | |
77 STYLE_INVOKE(label->style, init, label); | |
78 } | |
77 | 79 |
78 int | 80 int |
79 mlk_label_ok(const struct mlk_label *label) | 81 mlk_label_ok(const struct mlk_label *label) |
80 { | 82 { |
81 return label && label->text && strlen(label->text) > 0; | 83 return label && label->text && strlen(label->text) > 0; |