Mercurial > molko
changeset 146:7d7ea7a9cf50
core: add theme_shallow function
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 14 Oct 2020 18:20:58 +0200 |
parents | 7f1af54bb35a |
children | b386d25832c8 |
files | libcore/core/message.c libcore/core/theme.c libcore/core/theme.h |
diffstat | 3 files changed, 29 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libcore/core/message.c Wed Oct 14 18:11:38 2020 +0200 +++ b/libcore/core/message.c Wed Oct 14 18:20:58 2020 +0200 @@ -80,14 +80,13 @@ draw_lines(const struct message *msg) { struct theme theme; - struct font *font; unsigned int lineh; /* Shallow copy theme to modify colors. */ - memcpy(&theme, THEME(msg), sizeof (theme)); + theme_shallow(&theme, msg->theme); - font = theme.fonts[THEME_FONT_INTERFACE]; - lineh = font_height(font); + /* Compute text size for list alignment. */ + lineh = font_height(theme.fonts[THEME_FONT_INTERFACE]); for (int i = 0; i < 6; ++i) { if (!msg->text[i])
--- a/libcore/core/theme.c Wed Oct 14 18:11:38 2020 +0200 +++ b/libcore/core/theme.c Wed Oct 14 18:20:58 2020 +0200 @@ -18,6 +18,7 @@ #include <assert.h> #include <stddef.h> +#include <string.h> #include "button.h" #include "checkbox.h" @@ -258,6 +259,14 @@ } void +theme_shallow(struct theme *dst, const struct theme *src) +{ + assert(dst); + + memcpy(dst, src ? src : &default_theme, sizeof (*src)); +} + +void theme_draw_frame(struct theme *t, const struct frame *frame) { assert(frame);
--- a/libcore/core/theme.h Wed Oct 14 18:11:38 2020 +0200 +++ b/libcore/core/theme.h Wed Oct 14 18:20:58 2020 +0200 @@ -121,6 +121,23 @@ theme_default(void); /** + * Convenient shortcut to shallow copy src into dst. + * + * Use this function when you want your own local copy of a theme because you + * want to modify some attributes. + * + * This is a shortcut to `memcpy(dst, src, sizeof (*src))`. + * + * \pre dst != NULL + * \param dst the destination theme + * \param src the source theme (may be NULL) + * \note Resources are not cloned, internal pointers will adress the same + * regions. + */ +void +theme_shallow(struct theme *dst, const struct theme *src); + +/** * Get the desired padding between GUI elements. * * \param t the theme to use (may be NULL)