mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
particle/ramp: expose info through the new struct particle_info struct
This commit is contained in:
parent
21e28315e3
commit
9f8000b047
4 changed files with 44 additions and 42 deletions
|
@ -13,6 +13,7 @@
|
|||
#include "particles/list.h"
|
||||
#include "particles/map.h"
|
||||
#include "particles/progress-bar.h"
|
||||
#include "particles/ramp.h"
|
||||
|
||||
const char *
|
||||
conf_err_prefix(const keychain_t *chain, const struct yml_node *node)
|
||||
|
@ -291,12 +292,6 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
|||
{"right-margin", false, &conf_verify_int}, \
|
||||
{"on-click", false, &conf_verify_string},
|
||||
|
||||
static const struct attr_info ramp[] = {
|
||||
{"tag", true, &conf_verify_string},
|
||||
{"items", true, &conf_verify_particle_list_items},
|
||||
COMMON_ATTRS
|
||||
};
|
||||
|
||||
static const struct attr_info string[] = {
|
||||
{"text", true, &conf_verify_string},
|
||||
{"max", false, &conf_verify_int},
|
||||
|
@ -316,6 +311,7 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
|||
{"list", &particle_list},
|
||||
{"map", &particle_map},
|
||||
{"progress-bar", &particle_progress_bar},
|
||||
{"ramp", &particle_ramp},
|
||||
};
|
||||
|
||||
static const struct {
|
||||
|
@ -323,7 +319,6 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
|||
const struct attr_info *attrs;
|
||||
size_t count;
|
||||
} particles[] = {
|
||||
{"ramp", ramp, sizeof(ramp) / sizeof(ramp[0])},
|
||||
{"string", string, sizeof(string) / sizeof(string[0])},
|
||||
};
|
||||
|
||||
|
|
31
config.c
31
config.c
|
@ -161,31 +161,6 @@ particle_string_from_config(const struct yml_node *node,
|
|||
}
|
||||
|
||||
|
||||
static struct particle *
|
||||
particle_ramp_from_config(const struct yml_node *node,
|
||||
const struct font *parent_font,
|
||||
int left_margin, int right_margin,
|
||||
const char *on_click_template)
|
||||
{
|
||||
const struct yml_node *tag = yml_get_value(node, "tag");
|
||||
const struct yml_node *items = yml_get_value(node, "items");
|
||||
|
||||
size_t count = yml_list_length(items);
|
||||
struct particle *parts[count];
|
||||
|
||||
size_t idx = 0;
|
||||
for (struct yml_list_iter it = yml_list_iter(items);
|
||||
it.node != NULL;
|
||||
yml_list_next(&it), idx++)
|
||||
{
|
||||
parts[idx] = conf_to_particle(it.node, parent_font);
|
||||
}
|
||||
|
||||
return particle_ramp_new(
|
||||
yml_value_as_string(tag), parts, count, 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)
|
||||
|
@ -239,13 +214,13 @@ conf_to_particle(const struct yml_node *node, const struct font *parent_font)
|
|||
else if (strcmp(type, "progress-bar") == 0)
|
||||
ret = particle_progress_bar.from_conf(
|
||||
pair.value, parent_font, left, right, on_click_template);
|
||||
else if (strcmp(type, "ramp") == 0)
|
||||
ret = particle_ramp.from_conf(
|
||||
pair.value, parent_font, left, right, on_click_template);
|
||||
|
||||
else if (strcmp(type, "string") == 0)
|
||||
ret = particle_string_from_config(
|
||||
pair.value, parent_font, left, right, on_click_template);
|
||||
else if (strcmp(type, "ramp") == 0)
|
||||
ret = particle_ramp_from_config(
|
||||
pair.value, parent_font, left, right, on_click_template);
|
||||
else
|
||||
assert(false);
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../config.h"
|
||||
|
||||
struct private {
|
||||
char *tag;
|
||||
struct particle **particles;
|
||||
|
@ -132,10 +134,9 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
|||
return exposable;
|
||||
}
|
||||
|
||||
struct particle *
|
||||
particle_ramp_new(const char *tag, struct particle *particles[], size_t count,
|
||||
int left_margin, int right_margin,
|
||||
const char *on_click_template)
|
||||
static struct particle *
|
||||
ramp_new(const char *tag, struct particle *particles[], size_t count,
|
||||
int left_margin, int right_margin, const char *on_click_template)
|
||||
{
|
||||
struct particle *particle = particle_common_new(
|
||||
left_margin, right_margin, on_click_template);
|
||||
|
@ -153,3 +154,36 @@ particle_ramp_new(const char *tag, struct particle *particles[], size_t count,
|
|||
particle->private = priv;
|
||||
return particle;
|
||||
}
|
||||
|
||||
static struct particle *
|
||||
from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||
int left_margin, int right_margin, const char *on_click_template)
|
||||
{
|
||||
const struct yml_node *tag = yml_get_value(node, "tag");
|
||||
const struct yml_node *items = yml_get_value(node, "items");
|
||||
|
||||
size_t count = yml_list_length(items);
|
||||
struct particle *parts[count];
|
||||
|
||||
size_t idx = 0;
|
||||
for (struct yml_list_iter it = yml_list_iter(items);
|
||||
it.node != NULL;
|
||||
yml_list_next(&it), idx++)
|
||||
{
|
||||
parts[idx] = conf_to_particle(it.node, parent_font);
|
||||
}
|
||||
|
||||
return ramp_new(
|
||||
yml_value_as_string(tag), parts, count, left_margin, right_margin,
|
||||
on_click_template);
|
||||
}
|
||||
|
||||
const struct particle_info particle_ramp = {
|
||||
.from_conf = &from_conf,
|
||||
.attr_count = PARTICLE_COMMON_ATTRS_COUNT + 2,
|
||||
.attrs = {
|
||||
{"tag", true, &conf_verify_string},
|
||||
{"items", true, &conf_verify_particle_list_items},
|
||||
PARTICLE_COMMON_ATTRS,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#pragma once
|
||||
#include "../particle.h"
|
||||
|
||||
struct particle *particle_ramp_new(
|
||||
const char *tag, struct particle *particles[], size_t count,
|
||||
int left_margin, int right_margin, const char *on_click_template);
|
||||
extern const struct particle_info particle_ramp;
|
||||
|
|
Loading…
Add table
Reference in a new issue