# HG changeset patch # User David Demelier # Date 1602692458 -7200 # Node ID 7d7ea7a9cf50e4f65272dbc51f32cba261d6cefa # Parent 7f1af54bb35a912eecac940384a3b15c3cfd4131 core: add theme_shallow function diff -r 7f1af54bb35a -r 7d7ea7a9cf50 libcore/core/message.c --- 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]) diff -r 7f1af54bb35a -r 7d7ea7a9cf50 libcore/core/theme.c --- 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 #include +#include #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); diff -r 7f1af54bb35a -r 7d7ea7a9cf50 libcore/core/theme.h --- 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)