mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-25 13:25:39 +02:00
config: all particles now take a 'on_click_template' argument
This commit is contained in:
parent
3eebdbb5b0
commit
86425fbe48
7 changed files with 56 additions and 35 deletions
61
config.c
61
config.c
|
@ -169,22 +169,23 @@ 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)
|
int left_margin, int right_margin,
|
||||||
|
const char *on_click_template)
|
||||||
{
|
{
|
||||||
return particle_empty_new(left_margin, right_margin);
|
return particle_empty_new(left_margin, right_margin, on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
int left_margin, int right_margin,
|
||||||
|
const char *on_click_template)
|
||||||
{
|
{
|
||||||
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 *on_click = yml_get_value(node, "on_click");
|
|
||||||
|
|
||||||
assert(text != NULL && yml_is_scalar(text));
|
assert(text != NULL && yml_is_scalar(text));
|
||||||
|
|
||||||
|
@ -195,8 +196,7 @@ particle_string_from_config(const struct yml_node *node,
|
||||||
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_margin, right_margin,
|
fg_color, left_margin, right_margin, on_click_template);
|
||||||
on_click != NULL ? yml_value_as_string(on_click) : NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct particle * particle_from_config(
|
static struct particle * particle_from_config(
|
||||||
|
@ -205,7 +205,8 @@ 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)
|
int left_margin, int right_margin,
|
||||||
|
const char *on_click_template)
|
||||||
{
|
{
|
||||||
const struct yml_node *items = yml_get_value(node, "items");
|
const struct yml_node *items = yml_get_value(node, "items");
|
||||||
|
|
||||||
|
@ -213,8 +214,6 @@ particle_list_from_config(const struct yml_node *node,
|
||||||
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");
|
|
||||||
|
|
||||||
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) :
|
||||||
|
@ -233,13 +232,14 @@ particle_list_from_config(const struct yml_node *node,
|
||||||
|
|
||||||
return particle_list_new(
|
return particle_list_new(
|
||||||
parts, count, left_spacing, right_spacing, left_margin, right_margin,
|
parts, count, left_spacing, right_spacing, left_margin, right_margin,
|
||||||
on_click != NULL ? yml_value_as_string(on_click) : NULL);
|
on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
particle_map_from_config(const struct yml_node *node,
|
particle_map_from_config(const struct yml_node *node,
|
||||||
const struct font *parent_font,
|
const struct font *parent_font,
|
||||||
int left_margin, int right_margin)
|
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 *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");
|
||||||
|
@ -266,13 +266,14 @@ particle_map_from_config(const struct yml_node *node,
|
||||||
|
|
||||||
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, left_margin, right_margin);
|
default_particle, left_margin, right_margin, on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
particle_ramp_from_config(const struct yml_node *node,
|
particle_ramp_from_config(const struct yml_node *node,
|
||||||
const struct font *parent_font,
|
const struct font *parent_font,
|
||||||
int left_margin, int right_margin)
|
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 *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");
|
||||||
|
@ -292,13 +293,15 @@ particle_ramp_from_config(const struct yml_node *node,
|
||||||
}
|
}
|
||||||
|
|
||||||
return particle_ramp_new(
|
return particle_ramp_new(
|
||||||
yml_value_as_string(tag), parts, count, left_margin, right_margin);
|
yml_value_as_string(tag), parts, count, left_margin, right_margin,
|
||||||
|
on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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 *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");
|
||||||
|
@ -307,7 +310,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 *on_click = yml_get_value(node, "on_click");
|
|
||||||
|
|
||||||
assert(tag != NULL && yml_is_scalar(tag));
|
assert(tag != NULL && yml_is_scalar(tag));
|
||||||
assert(length != NULL && yml_is_scalar(length));
|
assert(length != NULL && yml_is_scalar(length));
|
||||||
|
@ -316,7 +318,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(on_click == NULL || yml_is_scalar(on_click));
|
|
||||||
|
|
||||||
return particle_progress_bar_new(
|
return particle_progress_bar_new(
|
||||||
yml_value_as_string(tag),
|
yml_value_as_string(tag),
|
||||||
|
@ -326,8 +327,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, right_margin,
|
left_margin, right_margin, on_click_template);
|
||||||
on_click != NULL ? yml_value_as_string(on_click) : NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
|
@ -342,29 +342,40 @@ particle_from_config(const struct yml_node *node, const struct font *parent_font
|
||||||
const struct yml_node *margin = yml_get_value(pair.value, "margin");
|
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 *left_margin = yml_get_value(pair.value, "left_margin");
|
||||||
const struct yml_node *right_margin = yml_get_value(pair.value, "right_margin");
|
const struct yml_node *right_margin = yml_get_value(pair.value, "right_margin");
|
||||||
|
const struct yml_node *on_click = yml_get_value(pair.value, "on_click");
|
||||||
|
|
||||||
assert(margin == NULL || yml_is_scalar(margin));
|
assert(margin == NULL || yml_is_scalar(margin));
|
||||||
assert(left_margin == NULL || yml_is_scalar(left_margin));
|
assert(left_margin == NULL || yml_is_scalar(left_margin));
|
||||||
assert(right_margin == NULL || yml_is_scalar(right_margin));
|
assert(right_margin == NULL || yml_is_scalar(right_margin));
|
||||||
|
assert(on_click == NULL || yml_is_scalar(on_click));
|
||||||
|
|
||||||
int left = margin != NULL ? yml_value_as_int(margin) :
|
int left = margin != NULL ? yml_value_as_int(margin) :
|
||||||
left_margin != NULL ? yml_value_as_int(left_margin) : 0;
|
left_margin != NULL ? yml_value_as_int(left_margin) : 0;
|
||||||
int right = margin != NULL ? yml_value_as_int(margin) :
|
int right = margin != NULL ? yml_value_as_int(margin) :
|
||||||
right_margin != NULL ? yml_value_as_int(right_margin) : 0;
|
right_margin != NULL ? yml_value_as_int(right_margin) : 0;
|
||||||
|
|
||||||
|
const char *on_click_template
|
||||||
|
= on_click != NULL ? yml_value_as_string(on_click) : NULL;
|
||||||
|
|
||||||
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, left, right);
|
ret = particle_empty_from_config(
|
||||||
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
else if (strcmp(type, "string") == 0)
|
else if (strcmp(type, "string") == 0)
|
||||||
ret = particle_string_from_config(pair.value, parent_font, left, right);
|
ret = particle_string_from_config(
|
||||||
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
else if (strcmp(type, "list") == 0)
|
else if (strcmp(type, "list") == 0)
|
||||||
ret = particle_list_from_config(pair.value, parent_font, left, right);
|
ret = particle_list_from_config(
|
||||||
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
else if (strcmp(type, "map") == 0)
|
else if (strcmp(type, "map") == 0)
|
||||||
ret = particle_map_from_config(pair.value, parent_font, left, right);
|
ret = particle_map_from_config(
|
||||||
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
else if (strcmp(type, "ramp") == 0)
|
else if (strcmp(type, "ramp") == 0)
|
||||||
ret = particle_ramp_from_config(pair.value, parent_font, left, right);
|
ret = particle_ramp_from_config(
|
||||||
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
else if (strcmp(type, "progress_bar") == 0)
|
else if (strcmp(type, "progress_bar") == 0)
|
||||||
ret = particle_progress_bar_from_config(pair.value, parent_font, left, right);
|
ret = particle_progress_bar_from_config(
|
||||||
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
else
|
else
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
|
|
|
@ -19,16 +19,22 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
||||||
static struct exposable *
|
static struct exposable *
|
||||||
instantiate(const struct particle *particle, const struct tag_set *tags)
|
instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||||
{
|
{
|
||||||
struct exposable *exposable = exposable_common_new(particle, NULL);
|
char *on_click = tags_expand_template(particle->on_click_template, tags);
|
||||||
|
|
||||||
|
struct exposable *exposable = exposable_common_new(particle, on_click);
|
||||||
exposable->begin_expose = &begin_expose;
|
exposable->begin_expose = &begin_expose;
|
||||||
exposable->expose = &expose;
|
exposable->expose = &expose;
|
||||||
|
|
||||||
|
free(on_click);
|
||||||
return exposable;
|
return exposable;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct particle *
|
struct particle *
|
||||||
particle_empty_new(int left_margin, int right_margin)
|
particle_empty_new(int left_margin, int right_margin,
|
||||||
|
const char *on_click_template)
|
||||||
{
|
{
|
||||||
struct particle *particle = particle_common_new(left_margin, right_margin, NULL);
|
struct particle *particle = particle_common_new(
|
||||||
|
left_margin, right_margin, on_click_template);
|
||||||
particle->destroy = &particle_default_destroy;
|
particle->destroy = &particle_default_destroy;
|
||||||
particle->instantiate = &instantiate;
|
particle->instantiate = &instantiate;
|
||||||
return particle;
|
return particle;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../particle.h"
|
#include "../particle.h"
|
||||||
|
|
||||||
struct particle *particle_empty_new(int left_margin, int right_margin);
|
struct particle *particle_empty_new(
|
||||||
|
int left_margin, int right_margin, const char *on_click_template);
|
||||||
|
|
|
@ -139,10 +139,11 @@ 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)
|
int left_margin, int right_margin,
|
||||||
|
const char *on_click_template)
|
||||||
{
|
{
|
||||||
struct particle *particle = particle_common_new(
|
struct particle *particle = particle_common_new(
|
||||||
left_margin, right_margin, NULL);
|
left_margin, right_margin, on_click_template);
|
||||||
particle->destroy = &particle_destroy;
|
particle->destroy = &particle_destroy;
|
||||||
particle->instantiate = &instantiate;
|
particle->instantiate = &instantiate;
|
||||||
|
|
||||||
|
|
|
@ -8,4 +8,5 @@ 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, int left_margin, int right_margin);
|
struct particle *default_particle, int left_margin, int right_margin,
|
||||||
|
const char *on_click_template);
|
||||||
|
|
|
@ -134,10 +134,11 @@ 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)
|
int left_margin, int right_margin,
|
||||||
|
const char *on_click_template)
|
||||||
{
|
{
|
||||||
struct particle *particle = particle_common_new(
|
struct particle *particle = particle_common_new(
|
||||||
left_margin, right_margin, NULL);
|
left_margin, right_margin, on_click_template);
|
||||||
particle->destroy = &particle_destroy;
|
particle->destroy = &particle_destroy;
|
||||||
particle->instantiate = &instantiate;
|
particle->instantiate = &instantiate;
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
|
|
||||||
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);
|
int left_margin, int right_margin, const char *on_click_template);
|
||||||
|
|
Loading…
Add table
Reference in a new issue