Mercurial > molko
changeset 396:c9769a77ad8c
ui: avoid copying theme
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 18 Feb 2022 16:14:06 +0100 |
parents | ef2fc4442ed5 |
children | 73eabfd50410 |
files | src/libmlk-ui/ui/gridmenu.c src/libmlk-ui/ui/label.c src/libmlk-ui/ui/label.h |
diffstat | 3 files changed, 13 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/libmlk-ui/ui/gridmenu.c Fri Feb 18 16:02:01 2022 +0100 +++ b/src/libmlk-ui/ui/gridmenu.c Fri Feb 18 16:14:06 2022 +0100 @@ -118,11 +118,9 @@ { size_t pagesz, pagenr, item, c = 0, r = 0; struct label label = {0}; - struct theme theme; + const struct theme *theme = THEME(menu); - /* Copy theme to change color if selected. */ - theme_shallow(&theme, THEME(menu)); - label.theme = &theme; + label.theme = theme; label.flags = LABEL_FLAGS_SHADOW; /* @@ -139,13 +137,13 @@ continue; label.text = menu->items[item]; - label.x = menu->x + theme.padding + (c * menu->eltw) + (c * menu->spacew); - label.y = menu->y + theme.padding + (r * menu->elth) + (r * menu->spaceh); + label.x = menu->x + theme->padding + (c * menu->eltw) + (c * menu->spacew); + label.y = menu->y + theme->padding + (r * menu->elth) + (r * menu->spaceh); if (i == menu->selected % pagesz) - theme.colors[THEME_COLOR_NORMAL] = THEME(menu)->colors[THEME_COLOR_SELECTED]; + label.flags |= LABEL_FLAGS_SELECTED; else - theme.colors[THEME_COLOR_NORMAL] = THEME(menu)->colors[THEME_COLOR_NORMAL]; + label.flags &= ~(LABEL_FLAGS_SELECTED); label_draw(&label);
--- a/src/libmlk-ui/ui/label.c Fri Feb 18 16:02:01 2022 +0100 +++ b/src/libmlk-ui/ui/label.c Fri Feb 18 16:14:06 2022 +0100 @@ -41,10 +41,14 @@ struct font *font; struct texture tex; + unsigned long color; font = label->flags & LABEL_FLAGS_IMPORTANT ? t->fonts[THEME_FONT_IMPORTANT] : t->fonts[THEME_FONT_INTERFACE]; + color = label->flags & LABEL_FLAGS_SELECTED + ? t->colors[THEME_COLOR_SELECTED] + : t->colors[THEME_COLOR_NORMAL]; /* Shadow text, only if enabled. */ if (label->flags & LABEL_FLAGS_SHADOW) { @@ -56,7 +60,7 @@ } /* Normal text. */ - if (font_render(font, &tex, label->text, t->colors[THEME_COLOR_NORMAL]) < 0) + if (font_render(font, &tex, label->text, color) < 0) panic(); texture_draw(&tex, label->x, label->y);
--- a/src/libmlk-ui/ui/label.h Fri Feb 18 16:02:01 2022 +0100 +++ b/src/libmlk-ui/ui/label.h Fri Feb 18 16:14:06 2022 +0100 @@ -27,7 +27,8 @@ enum label_flags { LABEL_FLAGS_NONE, LABEL_FLAGS_SHADOW = (1 << 0), - LABEL_FLAGS_IMPORTANT = (1 << 1) + LABEL_FLAGS_IMPORTANT = (1 << 1), + LABEL_FLAGS_SELECTED = (1 << 2) }; struct label {