mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-25 05:15:41 +02:00
particle: all particles now take margin arguments
Ramp and map however, doesn't allow any values other than 0 (yet).
This commit is contained in:
parent
bd251cbf9f
commit
3135f1d36d
5 changed files with 56 additions and 52 deletions
85
config.c
85
config.c
|
@ -168,31 +168,22 @@ deco_from_config(const struct yml_node *node)
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
particle_empty_from_config(const struct yml_node *node,
|
particle_empty_from_config(const struct yml_node *node,
|
||||||
const struct font *parent_font)
|
const struct font *parent_font,
|
||||||
|
int left_margin, int right_margin)
|
||||||
{
|
{
|
||||||
const struct yml_node *left_margin = yml_get_value(node, "left_margin");
|
return particle_empty_new(left_margin, right_margin);
|
||||||
const struct yml_node *right_margin = yml_get_value(node, "right_margin");
|
|
||||||
|
|
||||||
assert(left_margin == NULL || yml_is_scalar(left_margin));
|
|
||||||
assert(right_margin == NULL || yml_is_scalar(right_margin));
|
|
||||||
|
|
||||||
return particle_empty_new(
|
|
||||||
left_margin != NULL ? yml_value_as_int(left_margin) : 0,
|
|
||||||
right_margin != NULL ? yml_value_as_int(right_margin) : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
particle_string_from_config(const struct yml_node *node,
|
particle_string_from_config(const struct yml_node *node,
|
||||||
const struct font *parent_font)
|
const struct font *parent_font,
|
||||||
|
int left_margin, int right_margin)
|
||||||
{
|
{
|
||||||
assert(yml_is_dict(node));
|
assert(yml_is_dict(node));
|
||||||
|
|
||||||
const struct yml_node *text = yml_get_value(node, "text");
|
const struct yml_node *text = yml_get_value(node, "text");
|
||||||
const struct yml_node *font = yml_get_value(node, "font");
|
const struct yml_node *font = yml_get_value(node, "font");
|
||||||
const struct yml_node *foreground = yml_get_value(node, "foreground");
|
const struct yml_node *foreground = yml_get_value(node, "foreground");
|
||||||
const struct yml_node *margin = yml_get_value(node, "margin");
|
|
||||||
const struct yml_node *left_margin = yml_get_value(node, "left_margin");
|
|
||||||
const struct yml_node *right_margin = yml_get_value(node, "right_margin");
|
|
||||||
const struct yml_node *on_click = yml_get_value(node, "on_click");
|
const struct yml_node *on_click = yml_get_value(node, "on_click");
|
||||||
|
|
||||||
assert(text != NULL && yml_is_scalar(text));
|
assert(text != NULL && yml_is_scalar(text));
|
||||||
|
@ -201,15 +192,10 @@ particle_string_from_config(const struct yml_node *node,
|
||||||
? color_from_hexstr(yml_value_as_string(foreground)) :
|
? color_from_hexstr(yml_value_as_string(foreground)) :
|
||||||
(struct rgba){1.0, 1.0, 1.0, 1.0};
|
(struct rgba){1.0, 1.0, 1.0, 1.0};
|
||||||
|
|
||||||
int left = margin != NULL ? yml_value_as_int(margin) :
|
|
||||||
left_margin != NULL ? yml_value_as_int(left_margin) : 0;
|
|
||||||
int right = margin != NULL ? yml_value_as_int(margin) :
|
|
||||||
right_margin != NULL ? yml_value_as_int(right_margin) : 0;
|
|
||||||
|
|
||||||
return particle_string_new(
|
return particle_string_new(
|
||||||
yml_value_as_string(text),
|
yml_value_as_string(text),
|
||||||
font != NULL ? font_from_config(font) : font_clone(parent_font),
|
font != NULL ? font_from_config(font) : font_clone(parent_font),
|
||||||
fg_color, left, right,
|
fg_color, left_margin, right_margin,
|
||||||
on_click != NULL ? yml_value_as_string(on_click) : NULL);
|
on_click != NULL ? yml_value_as_string(on_click) : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,24 +204,17 @@ static struct particle * particle_from_config(
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
particle_list_from_config(const struct yml_node *node,
|
particle_list_from_config(const struct yml_node *node,
|
||||||
const struct font *parent_font)
|
const struct font *parent_font,
|
||||||
|
int left_margin, int right_margin)
|
||||||
{
|
{
|
||||||
const struct yml_node *items = yml_get_value(node, "items");
|
const struct yml_node *items = yml_get_value(node, "items");
|
||||||
|
|
||||||
const struct yml_node *margin = yml_get_value(node, "margin");
|
|
||||||
const struct yml_node *_left_margin = yml_get_value(node, "left_margin");
|
|
||||||
const struct yml_node *_right_margin = yml_get_value(node, "right_margin");
|
|
||||||
|
|
||||||
const struct yml_node *spacing = yml_get_value(node, "spacing");
|
const struct yml_node *spacing = yml_get_value(node, "spacing");
|
||||||
const struct yml_node *_left_spacing = yml_get_value(node, "left_spacing");
|
const struct yml_node *_left_spacing = yml_get_value(node, "left_spacing");
|
||||||
const struct yml_node *_right_spacing = yml_get_value(node, "right_spacing");
|
const struct yml_node *_right_spacing = yml_get_value(node, "right_spacing");
|
||||||
|
|
||||||
const struct yml_node *on_click = yml_get_value(node, "on_click");
|
const struct yml_node *on_click = yml_get_value(node, "on_click");
|
||||||
|
|
||||||
int left_margin = margin != NULL ? yml_value_as_int(margin) :
|
|
||||||
_left_margin != NULL ? yml_value_as_int(_left_margin) : 0;
|
|
||||||
int right_margin = margin != NULL ? yml_value_as_int(margin) :
|
|
||||||
_right_margin != NULL ? yml_value_as_int(_right_margin) : 0;
|
|
||||||
int left_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
int left_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
||||||
_left_spacing != NULL ? yml_value_as_int(_left_spacing) : 0;
|
_left_spacing != NULL ? yml_value_as_int(_left_spacing) : 0;
|
||||||
int right_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
int right_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
||||||
|
@ -258,7 +237,9 @@ particle_list_from_config(const struct yml_node *node,
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
particle_map_from_config(const struct yml_node *node, const struct font *parent_font)
|
particle_map_from_config(const struct yml_node *node,
|
||||||
|
const struct font *parent_font,
|
||||||
|
int left_margin, int right_margin)
|
||||||
{
|
{
|
||||||
const struct yml_node *tag = yml_get_value(node, "tag");
|
const struct yml_node *tag = yml_get_value(node, "tag");
|
||||||
const struct yml_node *values = yml_get_value(node, "values");
|
const struct yml_node *values = yml_get_value(node, "values");
|
||||||
|
@ -285,11 +266,13 @@ particle_map_from_config(const struct yml_node *node, const struct font *parent_
|
||||||
|
|
||||||
return particle_map_new(
|
return particle_map_new(
|
||||||
yml_value_as_string(tag), particle_map, yml_dict_length(values),
|
yml_value_as_string(tag), particle_map, yml_dict_length(values),
|
||||||
default_particle);
|
default_particle, left_margin, right_margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
particle_ramp_from_config(const struct yml_node *node, const struct font *parent_font)
|
particle_ramp_from_config(const struct yml_node *node,
|
||||||
|
const struct font *parent_font,
|
||||||
|
int left_margin, int right_margin)
|
||||||
{
|
{
|
||||||
const struct yml_node *tag = yml_get_value(node, "tag");
|
const struct yml_node *tag = yml_get_value(node, "tag");
|
||||||
const struct yml_node *items = yml_get_value(node, "items");
|
const struct yml_node *items = yml_get_value(node, "items");
|
||||||
|
@ -308,12 +291,14 @@ particle_ramp_from_config(const struct yml_node *node, const struct font *parent
|
||||||
parts[idx] = particle_from_config(it.node, parent_font);
|
parts[idx] = particle_from_config(it.node, parent_font);
|
||||||
}
|
}
|
||||||
|
|
||||||
return particle_ramp_new(yml_value_as_string(tag), parts, count);
|
return particle_ramp_new(
|
||||||
|
yml_value_as_string(tag), parts, count, left_margin, right_margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
particle_progress_bar_from_config(const struct yml_node *node,
|
particle_progress_bar_from_config(const struct yml_node *node,
|
||||||
const struct font *parent_font)
|
const struct font *parent_font,
|
||||||
|
int left_margin, int right_margin)
|
||||||
{
|
{
|
||||||
const struct yml_node *tag = yml_get_value(node, "tag");
|
const struct yml_node *tag = yml_get_value(node, "tag");
|
||||||
const struct yml_node *length = yml_get_value(node, "length");
|
const struct yml_node *length = yml_get_value(node, "length");
|
||||||
|
@ -322,8 +307,6 @@ particle_progress_bar_from_config(const struct yml_node *node,
|
||||||
const struct yml_node *fill = yml_get_value(node, "fill");
|
const struct yml_node *fill = yml_get_value(node, "fill");
|
||||||
const struct yml_node *empty = yml_get_value(node, "empty");
|
const struct yml_node *empty = yml_get_value(node, "empty");
|
||||||
const struct yml_node *indicator = yml_get_value(node, "indicator");
|
const struct yml_node *indicator = yml_get_value(node, "indicator");
|
||||||
const struct yml_node *left_margin = yml_get_value(node, "left_margin");
|
|
||||||
const struct yml_node *right_margin = yml_get_value(node, "right_margin");
|
|
||||||
const struct yml_node *on_click = yml_get_value(node, "on_click");
|
const struct yml_node *on_click = yml_get_value(node, "on_click");
|
||||||
|
|
||||||
assert(tag != NULL && yml_is_scalar(tag));
|
assert(tag != NULL && yml_is_scalar(tag));
|
||||||
|
@ -333,8 +316,6 @@ particle_progress_bar_from_config(const struct yml_node *node,
|
||||||
assert(fill != NULL);
|
assert(fill != NULL);
|
||||||
assert(empty != NULL);
|
assert(empty != NULL);
|
||||||
assert(indicator != NULL);
|
assert(indicator != NULL);
|
||||||
assert(left_margin == NULL || yml_is_scalar(left_margin));
|
|
||||||
assert(right_margin == NULL || yml_is_scalar(right_margin));
|
|
||||||
assert(on_click == NULL || yml_is_scalar(on_click));
|
assert(on_click == NULL || yml_is_scalar(on_click));
|
||||||
|
|
||||||
return particle_progress_bar_new(
|
return particle_progress_bar_new(
|
||||||
|
@ -345,8 +326,7 @@ particle_progress_bar_from_config(const struct yml_node *node,
|
||||||
particle_from_config(fill, parent_font),
|
particle_from_config(fill, parent_font),
|
||||||
particle_from_config(empty, parent_font),
|
particle_from_config(empty, parent_font),
|
||||||
particle_from_config(indicator, parent_font),
|
particle_from_config(indicator, parent_font),
|
||||||
left_margin != NULL ? yml_value_as_int(left_margin) : 0,
|
left_margin, right_margin,
|
||||||
right_margin != NULL ? yml_value_as_int(right_margin) : 0,
|
|
||||||
on_click != NULL ? yml_value_as_string(on_click) : NULL);
|
on_click != NULL ? yml_value_as_string(on_click) : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,19 +339,32 @@ particle_from_config(const struct yml_node *node, const struct font *parent_font
|
||||||
struct yml_dict_iter pair = yml_dict_iter(node);
|
struct yml_dict_iter pair = yml_dict_iter(node);
|
||||||
const char *type = yml_value_as_string(pair.key);
|
const char *type = yml_value_as_string(pair.key);
|
||||||
|
|
||||||
|
const struct yml_node *margin = yml_get_value(pair.value, "margin");
|
||||||
|
const struct yml_node *left_margin = yml_get_value(pair.value, "left_margin");
|
||||||
|
const struct yml_node *right_margin = yml_get_value(pair.value, "right_margin");
|
||||||
|
|
||||||
|
assert(margin == NULL || yml_is_scalar(margin));
|
||||||
|
assert(left_margin == NULL || yml_is_scalar(left_margin));
|
||||||
|
assert(right_margin == NULL || yml_is_scalar(right_margin));
|
||||||
|
|
||||||
|
int left = margin != NULL ? yml_value_as_int(margin) :
|
||||||
|
left_margin != NULL ? yml_value_as_int(left_margin) : 0;
|
||||||
|
int right = margin != NULL ? yml_value_as_int(margin) :
|
||||||
|
right_margin != NULL ? yml_value_as_int(right_margin) : 0;
|
||||||
|
|
||||||
struct particle *ret = NULL;
|
struct particle *ret = NULL;
|
||||||
if (strcmp(type, "empty") == 0)
|
if (strcmp(type, "empty") == 0)
|
||||||
ret = particle_empty_from_config(pair.value, parent_font);
|
ret = particle_empty_from_config(pair.value, parent_font, left, right);
|
||||||
else if (strcmp(type, "string") == 0)
|
else if (strcmp(type, "string") == 0)
|
||||||
ret = particle_string_from_config(pair.value, parent_font);
|
ret = particle_string_from_config(pair.value, parent_font, left, right);
|
||||||
else if (strcmp(type, "list") == 0)
|
else if (strcmp(type, "list") == 0)
|
||||||
ret = particle_list_from_config(pair.value, parent_font);
|
ret = particle_list_from_config(pair.value, parent_font, left, right);
|
||||||
else if (strcmp(type, "map") == 0)
|
else if (strcmp(type, "map") == 0)
|
||||||
ret = particle_map_from_config(pair.value, parent_font);
|
ret = particle_map_from_config(pair.value, parent_font, left, right);
|
||||||
else if (strcmp(type, "ramp") == 0)
|
else if (strcmp(type, "ramp") == 0)
|
||||||
ret = particle_ramp_from_config(pair.value, parent_font);
|
ret = particle_ramp_from_config(pair.value, parent_font, left, right);
|
||||||
else if (strcmp(type, "progress_bar") == 0)
|
else if (strcmp(type, "progress_bar") == 0)
|
||||||
ret = particle_progress_bar_from_config(pair.value, parent_font);
|
ret = particle_progress_bar_from_config(pair.value, parent_font, left, right);
|
||||||
else
|
else
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,14 @@ particle_destroy(struct particle *particle)
|
||||||
|
|
||||||
struct particle *
|
struct particle *
|
||||||
particle_map_new(const char *tag, const struct particle_map *particle_map,
|
particle_map_new(const char *tag, const struct particle_map *particle_map,
|
||||||
size_t count, struct particle *default_particle)
|
size_t count, struct particle *default_particle,
|
||||||
|
int left_margin, int right_margin)
|
||||||
{
|
{
|
||||||
struct particle *particle = particle_common_new(0, 0, NULL);
|
assert(left_margin == 0 && right_margin == 0
|
||||||
|
&& "map: margins not implemented");
|
||||||
|
|
||||||
|
struct particle *particle = particle_common_new(
|
||||||
|
left_margin, right_margin, NULL);
|
||||||
particle->destroy = &particle_destroy;
|
particle->destroy = &particle_destroy;
|
||||||
particle->instantiate = &instantiate;
|
particle->instantiate = &instantiate;
|
||||||
|
|
||||||
|
|
|
@ -8,4 +8,4 @@ struct particle_map {
|
||||||
|
|
||||||
struct particle *particle_map_new(
|
struct particle *particle_map_new(
|
||||||
const char *tag, const struct particle_map *particle_map, size_t count,
|
const char *tag, const struct particle_map *particle_map, size_t count,
|
||||||
struct particle *default_particle);
|
struct particle *default_particle, int left_margin, int right_margin);
|
||||||
|
|
|
@ -59,9 +59,14 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct particle *
|
struct particle *
|
||||||
particle_ramp_new(const char *tag, struct particle *particles[], size_t count)
|
particle_ramp_new(const char *tag, struct particle *particles[], size_t count,
|
||||||
|
int left_margin, int right_margin)
|
||||||
{
|
{
|
||||||
struct particle *particle = particle_common_new(0, 0, NULL);
|
assert(left_margin == 0 && right_margin == 0
|
||||||
|
&& "ramp: margins not implemented");
|
||||||
|
|
||||||
|
struct particle *particle = particle_common_new(
|
||||||
|
left_margin, right_margin, NULL);
|
||||||
particle->destroy = &particle_destroy;
|
particle->destroy = &particle_destroy;
|
||||||
particle->instantiate = &instantiate;
|
particle->instantiate = &instantiate;
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,5 @@
|
||||||
#include "../particle.h"
|
#include "../particle.h"
|
||||||
|
|
||||||
struct particle *particle_ramp_new(
|
struct particle *particle_ramp_new(
|
||||||
const char *tag, struct particle *particles[], size_t count);
|
const char *tag, struct particle *particles[], size_t count,
|
||||||
|
int left_margin, int right_margin);
|
||||||
|
|
Loading…
Add table
Reference in a new issue