From a9110cc93688a411ed66dc75eda66f86c9f02fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 1 Jan 2019 20:50:49 +0100 Subject: [PATCH] config: allow simple lists without actually declaring a list node That is, instead of writing: content: list: items: - string: .. - string: .. It is now possible to write: content: - string: ... - string: ... Obviously, this means it's not possible to assign spacing, margin or on-click handlers to such a list. --- config.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/config.c b/config.c index 832553f..dc6e983 100644 --- a/config.c +++ b/config.c @@ -334,9 +334,32 @@ particle_progress_bar_from_config(const struct yml_node *node, left_margin, right_margin, on_click_template); } +static struct particle * +particle_simple_list_from_config(const struct yml_node *node, + const struct font *parent_font) +{ + assert(yml_is_list(node)); + + size_t count = yml_list_length(node); + struct particle *parts[count]; + + size_t idx = 0; + for (struct yml_list_iter it = yml_list_iter(node); + it.node != NULL; + yml_list_next(&it), idx++) + { + parts[idx] = particle_from_config(it.node, parent_font); + } + + return particle_list_new(parts, count, 0, 0, 0, 0, NULL); +} + static struct particle * particle_from_config(const struct yml_node *node, const struct font *parent_font) { + if (yml_is_list(node)) + return particle_simple_list_from_config(node, parent_font); + assert(yml_is_dict(node)); assert(yml_dict_length(node) == 1);