forked from external/yambar
particle/progress-bar: expose info through the new struct particle_info struct
This commit is contained in:
parent
73b8bf1346
commit
21e28315e3
5 changed files with 56 additions and 55 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include "particles/empty.h"
|
#include "particles/empty.h"
|
||||||
#include "particles/list.h"
|
#include "particles/list.h"
|
||||||
#include "particles/map.h"
|
#include "particles/map.h"
|
||||||
|
#include "particles/progress-bar.h"
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
conf_err_prefix(const keychain_t *chain, const struct yml_node *node)
|
conf_err_prefix(const keychain_t *chain, const struct yml_node *node)
|
||||||
|
@ -290,18 +291,6 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
||||||
{"right-margin", false, &conf_verify_int}, \
|
{"right-margin", false, &conf_verify_int}, \
|
||||||
{"on-click", false, &conf_verify_string},
|
{"on-click", false, &conf_verify_string},
|
||||||
|
|
||||||
static const struct attr_info progress_bar[] = {
|
|
||||||
{"tag", true, &conf_verify_string},
|
|
||||||
{"length", true, &conf_verify_int},
|
|
||||||
/* TODO: make these optional? Default to empty */
|
|
||||||
{"start", true, &conf_verify_particle},
|
|
||||||
{"end", true, &conf_verify_particle},
|
|
||||||
{"fill", true, &conf_verify_particle},
|
|
||||||
{"empty", true, &conf_verify_particle},
|
|
||||||
{"indicator", true, &conf_verify_particle},
|
|
||||||
COMMON_ATTRS
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct attr_info ramp[] = {
|
static const struct attr_info ramp[] = {
|
||||||
{"tag", true, &conf_verify_string},
|
{"tag", true, &conf_verify_string},
|
||||||
{"items", true, &conf_verify_particle_list_items},
|
{"items", true, &conf_verify_particle_list_items},
|
||||||
|
@ -326,6 +315,7 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
||||||
{"empty", &particle_empty},
|
{"empty", &particle_empty},
|
||||||
{"list", &particle_list},
|
{"list", &particle_list},
|
||||||
{"map", &particle_map},
|
{"map", &particle_map},
|
||||||
|
{"progress-bar", &particle_progress_bar},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
|
@ -333,7 +323,6 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
||||||
const struct attr_info *attrs;
|
const struct attr_info *attrs;
|
||||||
size_t count;
|
size_t count;
|
||||||
} particles[] = {
|
} particles[] = {
|
||||||
{"progress-bar", progress_bar, sizeof(progress_bar) / sizeof(progress_bar[0])},
|
|
||||||
{"ramp", ramp, sizeof(ramp) / sizeof(ramp[0])},
|
{"ramp", ramp, sizeof(ramp) / sizeof(ramp[0])},
|
||||||
{"string", string, sizeof(string) / sizeof(string[0])},
|
{"string", string, sizeof(string) / sizeof(string[0])},
|
||||||
};
|
};
|
||||||
|
|
31
config.c
31
config.c
|
@ -186,31 +186,6 @@ particle_ramp_from_config(const struct yml_node *node,
|
||||||
on_click_template);
|
on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct particle *
|
|
||||||
particle_progress_bar_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 *length = yml_get_value(node, "length");
|
|
||||||
const struct yml_node *start = yml_get_value(node, "start");
|
|
||||||
const struct yml_node *end = yml_get_value(node, "end");
|
|
||||||
const struct yml_node *fill = yml_get_value(node, "fill");
|
|
||||||
const struct yml_node *empty = yml_get_value(node, "empty");
|
|
||||||
const struct yml_node *indicator = yml_get_value(node, "indicator");
|
|
||||||
|
|
||||||
return particle_progress_bar_new(
|
|
||||||
yml_value_as_string(tag),
|
|
||||||
yml_value_as_int(length),
|
|
||||||
conf_to_particle(start, parent_font),
|
|
||||||
conf_to_particle(end, parent_font),
|
|
||||||
conf_to_particle(fill, parent_font),
|
|
||||||
conf_to_particle(empty, parent_font),
|
|
||||||
conf_to_particle(indicator, parent_font),
|
|
||||||
left_margin, right_margin, on_click_template);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct particle *
|
static struct particle *
|
||||||
particle_simple_list_from_config(const struct yml_node *node,
|
particle_simple_list_from_config(const struct yml_node *node,
|
||||||
const struct font *parent_font)
|
const struct font *parent_font)
|
||||||
|
@ -261,6 +236,9 @@ conf_to_particle(const struct yml_node *node, const struct font *parent_font)
|
||||||
else if (strcmp(type, "map") == 0)
|
else if (strcmp(type, "map") == 0)
|
||||||
ret = particle_map.from_conf(
|
ret = particle_map.from_conf(
|
||||||
pair.value, parent_font, left, right, on_click_template);
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
|
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, "string") == 0)
|
else if (strcmp(type, "string") == 0)
|
||||||
ret = particle_string_from_config(
|
ret = particle_string_from_config(
|
||||||
|
@ -268,9 +246,6 @@ conf_to_particle(const struct yml_node *node, const struct font *parent_font)
|
||||||
else if (strcmp(type, "ramp") == 0)
|
else if (strcmp(type, "ramp") == 0)
|
||||||
ret = particle_ramp_from_config(
|
ret = particle_ramp_from_config(
|
||||||
pair.value, parent_font, left, right, on_click_template);
|
pair.value, parent_font, left, right, on_click_template);
|
||||||
else if (strcmp(type, "progress-bar") == 0)
|
|
||||||
ret = particle_progress_bar_from_config(
|
|
||||||
pair.value, parent_font, left, right, on_click_template);
|
|
||||||
else
|
else
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@ struct particle_info {
|
||||||
{"margin", false, &conf_verify_int}, \
|
{"margin", false, &conf_verify_int}, \
|
||||||
{"left-margin", false, &conf_verify_int}, \
|
{"left-margin", false, &conf_verify_int}, \
|
||||||
{"right-margin", false, &conf_verify_int}, \
|
{"right-margin", false, &conf_verify_int}, \
|
||||||
{"on-click", false, &conf_verify_string}
|
{"on-click", false, &conf_verify_string}, \
|
||||||
|
{NULL, false, NULL}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#define LOG_MODULE "progress_bar"
|
#define LOG_MODULE "progress_bar"
|
||||||
#define LOG_ENABLE_DBG 0
|
#define LOG_ENABLE_DBG 0
|
||||||
#include "../log.h"
|
#include "../log.h"
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
struct private {
|
struct private {
|
||||||
char *tag;
|
char *tag;
|
||||||
|
@ -206,14 +207,14 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||||
return exposable;
|
return exposable;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct particle *
|
static struct particle *
|
||||||
particle_progress_bar_new(const char *tag, int width,
|
progress_bar_new(const char *tag, int width,
|
||||||
struct particle *start_marker,
|
struct particle *start_marker,
|
||||||
struct particle *end_marker,
|
struct particle *end_marker,
|
||||||
struct particle *fill, struct particle *empty,
|
struct particle *fill, struct particle *empty,
|
||||||
struct particle *indicator,
|
struct particle *indicator,
|
||||||
int left_margin, int right_margin,
|
int left_margin, int right_margin,
|
||||||
const char *on_click_template)
|
const char *on_click_template)
|
||||||
{
|
{
|
||||||
struct private *priv = malloc(sizeof(*priv));
|
struct private *priv = malloc(sizeof(*priv));
|
||||||
priv->tag = strdup(tag);
|
priv->tag = strdup(tag);
|
||||||
|
@ -232,3 +233,42 @@ particle_progress_bar_new(const char *tag, int width,
|
||||||
|
|
||||||
return particle;
|
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 *length = yml_get_value(node, "length");
|
||||||
|
const struct yml_node *start = yml_get_value(node, "start");
|
||||||
|
const struct yml_node *end = yml_get_value(node, "end");
|
||||||
|
const struct yml_node *fill = yml_get_value(node, "fill");
|
||||||
|
const struct yml_node *empty = yml_get_value(node, "empty");
|
||||||
|
const struct yml_node *indicator = yml_get_value(node, "indicator");
|
||||||
|
|
||||||
|
return progress_bar_new(
|
||||||
|
yml_value_as_string(tag),
|
||||||
|
yml_value_as_int(length),
|
||||||
|
conf_to_particle(start, parent_font),
|
||||||
|
conf_to_particle(end, parent_font),
|
||||||
|
conf_to_particle(fill, parent_font),
|
||||||
|
conf_to_particle(empty, parent_font),
|
||||||
|
conf_to_particle(indicator, parent_font),
|
||||||
|
left_margin, right_margin, on_click_template);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct particle_info particle_progress_bar = {
|
||||||
|
.from_conf = &from_conf,
|
||||||
|
.attr_count = PARTICLE_COMMON_ATTRS_COUNT + 7,
|
||||||
|
.attrs = {
|
||||||
|
{"tag", true, &conf_verify_string},
|
||||||
|
{"length", true, &conf_verify_int},
|
||||||
|
/* TODO: make these optional? Default to empty */
|
||||||
|
{"start", true, &conf_verify_particle},
|
||||||
|
{"end", true, &conf_verify_particle},
|
||||||
|
{"fill", true, &conf_verify_particle},
|
||||||
|
{"empty", true, &conf_verify_particle},
|
||||||
|
{"indicator", true, &conf_verify_particle},
|
||||||
|
PARTICLE_COMMON_ATTRS,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../particle.h"
|
#include "../particle.h"
|
||||||
|
|
||||||
struct particle * particle_progress_bar_new(
|
extern const struct particle_info particle_progress_bar;
|
||||||
const char *tag, int width,
|
|
||||||
struct particle *start_marker, struct particle *end_marker,
|
|
||||||
struct particle *fill, struct particle *empty, struct particle *indicator,
|
|
||||||
int left_margin, int right_margin, const char *on_click_template);
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue