[widgets/progressbar] fix FS#145 - empty progressbar draws one pixel too far
+ check_settings should be below the check for data_items (count). + some fix on check_settings
This commit is contained in:
parent
c582f4397b
commit
4a7ebc9c5c
|
@ -74,21 +74,21 @@ typedef struct
|
||||||
static Bool
|
static Bool
|
||||||
check_settings(Data *d, int status_height)
|
check_settings(Data *d, int status_height)
|
||||||
{
|
{
|
||||||
int simple, h_total;
|
int tmp, h_total;
|
||||||
|
|
||||||
h_total = (int)(status_height * d->height + 0.5);
|
h_total = (int)(status_height * d->height + 0.5);
|
||||||
|
|
||||||
if(!d->vertical) /* horizontal */
|
if(!d->vertical) /* horizontal */
|
||||||
{
|
{
|
||||||
simple = d->width - 2 * (d->border_width + d->border_padding) - 1;
|
tmp = d->width - 2 * (d->border_width + d->border_padding) - 1;
|
||||||
if((d->ticks_count && simple - (d->ticks_count - 1) * d->ticks_gap - d->ticks_count + 1 < 0) ||
|
if((d->ticks_count && tmp - (d->ticks_count - 1) * d->ticks_gap - d->ticks_count + 1 < 0) ||
|
||||||
(!d->ticks_count && simple < 0))
|
(!d->ticks_count && tmp < 0))
|
||||||
{
|
{
|
||||||
warn("progressbar's 'width' is too small for the given configuration options\n");
|
warn("progressbar's 'width' is too small for the given configuration options\n");
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
simple = h_total - d->data_items * (d->border_width + d->border_padding + 1) - (d->data_items - 1) * d->gap;
|
tmp = h_total - d->data_items * (2 * (d->border_width + d->border_padding) + 1) - (d->data_items - 1) * d->gap;
|
||||||
if(simple < 0)
|
if(tmp < 0)
|
||||||
{
|
{
|
||||||
warn("progressbar's 'height' is too small for the given configuration options\n");
|
warn("progressbar's 'height' is too small for the given configuration options\n");
|
||||||
return False;
|
return False;
|
||||||
|
@ -96,15 +96,15 @@ check_settings(Data *d, int status_height)
|
||||||
}
|
}
|
||||||
else /* vertical / standing up */
|
else /* vertical / standing up */
|
||||||
{
|
{
|
||||||
simple = h_total - 2 * (d->border_width + d->border_padding) - 1;
|
tmp = h_total - 2 * (d->border_width + d->border_padding) - 1;
|
||||||
if((d->ticks_count && simple - (d->ticks_count - 1) * d->ticks_gap - d->ticks_count + 1 < 0) ||
|
if((d->ticks_count && tmp - (d->ticks_count - 1) * d->ticks_gap - d->ticks_count + 1 < 0) ||
|
||||||
(!d->ticks_count && simple < 0))
|
(!d->ticks_count && tmp < 0))
|
||||||
{
|
{
|
||||||
warn("progressbar's 'height' is too small for the given configuration options\n");
|
warn("progressbar's 'height' is too small for the given configuration options\n");
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
simple = d->width - d->data_items * (d->border_width + d->border_padding + 1) - (d->data_items - 1) * d->gap;
|
tmp = d->width - d->data_items * (2 * (d->border_width + d->border_padding) + 1) - (d->data_items - 1) * d->gap;
|
||||||
if(simple < 0)
|
if(tmp < 0)
|
||||||
{
|
{
|
||||||
warn("progressbar's 'width' is too small for the given configuration options\n");
|
warn("progressbar's 'width' is too small for the given configuration options\n");
|
||||||
return False;
|
return False;
|
||||||
|
@ -265,7 +265,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
}
|
}
|
||||||
else /* a horizontal progressbar */
|
else /* a horizontal progressbar */
|
||||||
{
|
{
|
||||||
pb_width = d->width - d->border_width - 2 * d->border_padding;
|
pb_width = d->width - 2 * (d->border_width + d->border_padding);
|
||||||
if(d->ticks_count && d->ticks_gap)
|
if(d->ticks_count && d->ticks_gap)
|
||||||
{
|
{
|
||||||
unit = (pb_width + d->ticks_gap) / d->ticks_count;
|
unit = (pb_width + d->ticks_gap) / d->ticks_count;
|
||||||
|
@ -458,8 +458,6 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
|
||||||
w->tell = progressbar_tell;
|
w->tell = progressbar_tell;
|
||||||
d = w->data = p_new(Data, 1);
|
d = w->data = p_new(Data, 1);
|
||||||
|
|
||||||
d->data_items = 0; /* XXX: need to initialise or for sure 0? */
|
|
||||||
|
|
||||||
d->height = cfg_getfloat(config, "height");
|
d->height = cfg_getfloat(config, "height");
|
||||||
d->width = cfg_getint(config, "width");
|
d->width = cfg_getint(config, "width");
|
||||||
|
|
||||||
|
@ -471,9 +469,6 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
|
||||||
if(!(d->vertical = cfg_getbool(config, "vertical")))
|
if(!(d->vertical = cfg_getbool(config, "vertical")))
|
||||||
d->vertical = False;
|
d->vertical = False;
|
||||||
|
|
||||||
if(!check_settings(d, statusbar->height))
|
|
||||||
return w;
|
|
||||||
|
|
||||||
d->gap = cfg_getint(config, "gap");
|
d->gap = cfg_getint(config, "gap");
|
||||||
|
|
||||||
w->alignment = cfg_getalignment(config, "align");
|
w->alignment = cfg_getalignment(config, "align");
|
||||||
|
@ -484,6 +479,12 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!check_settings(d, statusbar->height))
|
||||||
|
{
|
||||||
|
d->data_items = 0;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
d->fg = p_new(XColor, d->data_items);
|
d->fg = p_new(XColor, d->data_items);
|
||||||
d->pfg_end = p_new(XColor *, d->data_items);
|
d->pfg_end = p_new(XColor *, d->data_items);
|
||||||
d->pfg_center = p_new(XColor *, d->data_items);
|
d->pfg_center = p_new(XColor *, d->data_items);
|
||||||
|
|
Loading…
Reference in New Issue