graph, progressbar: fix bar/plot additions
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
f970665cff
commit
0178a75c7d
|
@ -122,9 +122,32 @@ graph_plot_add(graph_data_t *d, const char *title)
|
||||||
plot.vertical_gradient = true;
|
plot.vertical_gradient = true;
|
||||||
|
|
||||||
plot_array_append(&d->plots, plot);
|
plot_array_append(&d->plots, plot);
|
||||||
|
|
||||||
return &d->plots.tab[d->plots.len - 1];
|
return &d->plots.tab[d->plots.len - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the plot, and create one if it does not exist.
|
||||||
|
* \param d The graph private data.
|
||||||
|
* \param title The plot title.
|
||||||
|
* \return A maybe new plot.
|
||||||
|
*/
|
||||||
|
static plot_t *
|
||||||
|
graph_plot_get(graph_data_t *d, const char *title)
|
||||||
|
{
|
||||||
|
plot_t *plot;
|
||||||
|
|
||||||
|
/* check if this section is defined already */
|
||||||
|
for(int j = 0; j < d->plots.len; j++)
|
||||||
|
{
|
||||||
|
plot = &d->plots.tab[j];
|
||||||
|
if(!a_strcmp(title, plot->title))
|
||||||
|
return plot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* no plot found -> create one */
|
||||||
|
return graph_plot_add(d, title);
|
||||||
|
}
|
||||||
|
|
||||||
/** Draw a graph widget.
|
/** Draw a graph widget.
|
||||||
* \param ctx The draw context.
|
* \param ctx The draw context.
|
||||||
* \param screen The screen number.
|
* \param screen The screen number.
|
||||||
|
@ -290,16 +313,7 @@ luaA_graph_plot_properties_set(lua_State *L)
|
||||||
title = luaL_checkstring(L, 2);
|
title = luaL_checkstring(L, 2);
|
||||||
luaA_checktable(L, 3);
|
luaA_checktable(L, 3);
|
||||||
|
|
||||||
for(int j = 0; j < d->plots.len; j++)
|
plot = graph_plot_get(d, title);
|
||||||
{
|
|
||||||
plot = &d->plots.tab[j];
|
|
||||||
if(!a_strcmp(title, plot->title))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* no plot found -> create one */
|
|
||||||
if(!plot)
|
|
||||||
plot = graph_plot_add(d, title);
|
|
||||||
|
|
||||||
if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
|
if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
|
||||||
reqs[++reqs_nbr] = xcolor_init_unchecked(&plot->color_start, buf, len);
|
reqs[++reqs_nbr] = xcolor_init_unchecked(&plot->color_start, buf, len);
|
||||||
|
@ -359,16 +373,7 @@ luaA_graph_plot_data_add(lua_State *L)
|
||||||
float value;
|
float value;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(int j = 0; j < d->plots.len; j++)
|
plot = graph_plot_get(d, title);
|
||||||
{
|
|
||||||
plot = &d->plots.tab[j];
|
|
||||||
if(!a_strcmp(title, plot->title))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* no plot found -> create one */
|
|
||||||
if(!plot)
|
|
||||||
plot = graph_plot_add(d, title);
|
|
||||||
|
|
||||||
/* assign incoming value */
|
/* assign incoming value */
|
||||||
value = MAX(luaL_checknumber(L, 3), 0);
|
value = MAX(luaL_checknumber(L, 3), 0);
|
||||||
|
@ -426,7 +431,7 @@ luaA_graph_plot_data_add(lua_State *L)
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
* \luastack
|
* \luastack
|
||||||
* \lfield plot_properties_set A function to set plot properties.
|
* \lfield plot_properties_set A function to set plot properties.
|
||||||
* \lfield plot_add_add A function to add data to a plot.
|
* \lfield plot_data_add A function to add data to a plot.
|
||||||
* \lfield height Graph height.
|
* \lfield height Graph height.
|
||||||
* \lfield widget Graph width.
|
* \lfield widget Graph width.
|
||||||
* \lfield bg Background color.
|
* \lfield bg Background color.
|
||||||
|
|
|
@ -87,11 +87,12 @@ typedef struct
|
||||||
} progressbar_data_t;
|
} progressbar_data_t;
|
||||||
|
|
||||||
/** Add a new bar to the progressbar private data structure.
|
/** Add a new bar to the progressbar private data structure.
|
||||||
* \param d The private data structure.
|
* \param bars The bar array.
|
||||||
* \param title The graph title.
|
* \param title The bar title.
|
||||||
|
* \return The new bar.
|
||||||
*/
|
*/
|
||||||
static bar_t *
|
static bar_t *
|
||||||
progressbar_bar_add(progressbar_data_t *d, const char *title)
|
progressbar_bar_add(bar_array_t *bars, const char *title)
|
||||||
{
|
{
|
||||||
bar_t bar;
|
bar_t bar;
|
||||||
|
|
||||||
|
@ -105,9 +106,31 @@ progressbar_bar_add(progressbar_data_t *d, const char *title)
|
||||||
bar.max_value = 100.0;
|
bar.max_value = 100.0;
|
||||||
|
|
||||||
/* append the bar in the list */
|
/* append the bar in the list */
|
||||||
bar_array_append(&d->bars, bar);
|
bar_array_append(bars, bar);
|
||||||
|
|
||||||
return &d->bars.tab[d->bars.len - 1];
|
return &bars->tab[bars->len - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the bar, and create one if it does not exist.
|
||||||
|
* \param bars The bar array.
|
||||||
|
* \param title The bar title.
|
||||||
|
* \return A maybe new bar.
|
||||||
|
*/
|
||||||
|
static bar_t *
|
||||||
|
progressbar_bar_get(bar_array_t *bars, const char *title)
|
||||||
|
{
|
||||||
|
bar_t *bar;
|
||||||
|
|
||||||
|
/* check if this section is defined already */
|
||||||
|
for(int j = 0; j < bars->len; j++)
|
||||||
|
{
|
||||||
|
bar = &bars->tab[j];
|
||||||
|
if(!a_strcmp(title, bar->title))
|
||||||
|
return bar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* no bar found -> create one */
|
||||||
|
return progressbar_bar_add(bars, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Draw a progressbar.
|
/** Draw a progressbar.
|
||||||
|
@ -406,24 +429,14 @@ luaA_progressbar_bar_properties_set(lua_State *L)
|
||||||
size_t len;
|
size_t len;
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
const char *buf, *title = luaL_checkstring(L, 2);
|
const char *buf, *title = luaL_checkstring(L, 2);
|
||||||
bar_t *bar = NULL;
|
bar_t *bar;
|
||||||
progressbar_data_t *d = (*widget)->data;
|
progressbar_data_t *d = (*widget)->data;
|
||||||
xcolor_init_request_t reqs[6];
|
xcolor_init_request_t reqs[6];
|
||||||
int8_t i, reqs_nbr = -1;
|
int8_t i, reqs_nbr = -1;
|
||||||
|
|
||||||
luaA_checktable(L, 3);
|
luaA_checktable(L, 3);
|
||||||
|
|
||||||
/* check if this section is defined already */
|
bar = progressbar_bar_get(&d->bars, title);
|
||||||
for(int j = 0; j < d->bars.len; j++)
|
|
||||||
{
|
|
||||||
bar = &d->bars.tab[j];
|
|
||||||
if(!a_strcmp(title, bar->title))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* no bar found -> create one */
|
|
||||||
if(!bar)
|
|
||||||
bar = progressbar_bar_add(d, title);
|
|
||||||
|
|
||||||
if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
|
if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
|
||||||
reqs[++reqs_nbr] = xcolor_init_unchecked(&bar->fg, buf, len);
|
reqs[++reqs_nbr] = xcolor_init_unchecked(&bar->fg, buf, len);
|
||||||
|
@ -482,19 +495,9 @@ luaA_progressbar_bar_data_add(lua_State *L)
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
const char *title = luaL_checkstring(L, 2);
|
const char *title = luaL_checkstring(L, 2);
|
||||||
progressbar_data_t *d = (*widget)->data;
|
progressbar_data_t *d = (*widget)->data;
|
||||||
bar_t *bar = NULL;
|
bar_t *bar;
|
||||||
|
|
||||||
/* check if this section is defined already */
|
bar = progressbar_bar_get(&d->bars, title);
|
||||||
for(int j = 0; j < d->bars.len; j++)
|
|
||||||
{
|
|
||||||
bar = &d->bars.tab[j];
|
|
||||||
if(!a_strcmp(title, bar->title))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* no bar found -> create one */
|
|
||||||
if(!bar)
|
|
||||||
bar = progressbar_bar_add(d, title);
|
|
||||||
|
|
||||||
bar->value = luaL_checknumber(L, 3);
|
bar->value = luaL_checknumber(L, 3);
|
||||||
bar->value = MAX(bar->min_value, MIN(bar->max_value, bar->value));
|
bar->value = MAX(bar->min_value, MIN(bar->max_value, bar->value));
|
||||||
|
|
Loading…
Reference in New Issue