widget: add fixed alignment
This makes it possible to have fixed-width textboxes in the flexible part of a wibox. Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
dbbe48898a
commit
39cd86f976
|
@ -23,6 +23,7 @@ east
|
||||||
ellipsize
|
ellipsize
|
||||||
end
|
end
|
||||||
fg
|
fg
|
||||||
|
fixed
|
||||||
flex
|
flex
|
||||||
floating
|
floating
|
||||||
focus
|
focus
|
||||||
|
|
6
draw.c
6
draw.c
|
@ -677,8 +677,8 @@ draw_text_extents(draw_text_context_t *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Transform a string to a alignment_t type.
|
/** Transform a string to a alignment_t type.
|
||||||
* Recognized string are flex, left, center or right. Everything else will be
|
* Recognized string are flex, fixed, left, center or right. Everything else
|
||||||
* recognized as AlignLeft.
|
* will be recognized as AlignLeft.
|
||||||
* \param align Atring with align text.
|
* \param align Atring with align text.
|
||||||
* \param len The string length.
|
* \param len The string length.
|
||||||
* \return An alignment_t type.
|
* \return An alignment_t type.
|
||||||
|
@ -691,6 +691,7 @@ draw_align_fromstr(const char *align, ssize_t len)
|
||||||
case A_TK_CENTER: return AlignCenter;
|
case A_TK_CENTER: return AlignCenter;
|
||||||
case A_TK_RIGHT: return AlignRight;
|
case A_TK_RIGHT: return AlignRight;
|
||||||
case A_TK_FLEX: return AlignFlex;
|
case A_TK_FLEX: return AlignFlex;
|
||||||
|
case A_TK_FIXED: return AlignFixed;
|
||||||
case A_TK_TOP: return AlignTop;
|
case A_TK_TOP: return AlignTop;
|
||||||
case A_TK_BOTTOM: return AlignBottom;
|
case A_TK_BOTTOM: return AlignBottom;
|
||||||
default: return AlignLeft;
|
default: return AlignLeft;
|
||||||
|
@ -710,6 +711,7 @@ draw_align_tostr(alignment_t a)
|
||||||
case AlignCenter: return "center";
|
case AlignCenter: return "center";
|
||||||
case AlignRight: return "right";
|
case AlignRight: return "right";
|
||||||
case AlignFlex: return "flex";
|
case AlignFlex: return "flex";
|
||||||
|
case AlignFixed: return "fixed";
|
||||||
case AlignBottom: return "bottom";
|
case AlignBottom: return "bottom";
|
||||||
case AlignTop: return "top";
|
case AlignTop: return "top";
|
||||||
default: return NULL;
|
default: return NULL;
|
||||||
|
|
1
draw.h
1
draw.h
|
@ -61,6 +61,7 @@ typedef enum
|
||||||
AlignTop = (1 << 2),
|
AlignTop = (1 << 2),
|
||||||
AlignBottom = (1 << 3),
|
AlignBottom = (1 << 3),
|
||||||
AlignFlex = (1 << 4),
|
AlignFlex = (1 << 4),
|
||||||
|
AlignFixed = (1 << 5),
|
||||||
} alignment_t;
|
} alignment_t;
|
||||||
|
|
||||||
typedef struct vector_t vector_t;
|
typedef struct vector_t vector_t;
|
||||||
|
|
17
widget.c
17
widget.c
|
@ -64,6 +64,7 @@ widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment
|
||||||
{
|
{
|
||||||
case AlignLeft:
|
case AlignLeft:
|
||||||
case AlignFlex:
|
case AlignFlex:
|
||||||
|
case AlignFixed:
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
return barwidth - offset - widgetwidth;
|
return barwidth - offset - widgetwidth;
|
||||||
|
@ -235,13 +236,14 @@ widget_render(widget_node_array_t *widgets, draw_context_t *ctx, xcb_gcontext_t
|
||||||
/* save left value */
|
/* save left value */
|
||||||
int fake_left = left;
|
int fake_left = left;
|
||||||
|
|
||||||
/* compute width of flex aligned widgets that does not support it */
|
/* compute width of flex or fixed aligned widgets */
|
||||||
int flex = 0;
|
int flex = 0;
|
||||||
for(int i = 0; i < widgets->len; i++)
|
for(int i = 0; i < widgets->len; i++)
|
||||||
if(widgets->tab[i].widget->align == AlignFlex
|
if(widgets->tab[i].widget->align & (AlignFlex | AlignFixed)
|
||||||
&& widgets->tab[i].widget->isvisible)
|
&& widgets->tab[i].widget->isvisible)
|
||||||
{
|
{
|
||||||
if(widgets->tab[i].widget->align_supported & AlignFlex)
|
if(widgets->tab[i].widget->align_supported & AlignFlex
|
||||||
|
&& widgets->tab[i].widget->align == AlignFlex)
|
||||||
flex++;
|
flex++;
|
||||||
else
|
else
|
||||||
fake_left += widgets->tab[i].widget->geometry(widgets->tab[i].widget,
|
fake_left += widgets->tab[i].widget->geometry(widgets->tab[i].widget,
|
||||||
|
@ -252,10 +254,11 @@ widget_render(widget_node_array_t *widgets, draw_context_t *ctx, xcb_gcontext_t
|
||||||
/* now compute everybody together! */
|
/* now compute everybody together! */
|
||||||
int flex_rendered = 0;
|
int flex_rendered = 0;
|
||||||
for(int i = 0; i < widgets->len; i++)
|
for(int i = 0; i < widgets->len; i++)
|
||||||
if(widgets->tab[i].widget->align == AlignFlex
|
if(widgets->tab[i].widget->align & (AlignFlex | AlignFixed)
|
||||||
&& widgets->tab[i].widget->isvisible)
|
&& widgets->tab[i].widget->isvisible)
|
||||||
{
|
{
|
||||||
if(widgets->tab[i].widget->align_supported & AlignFlex)
|
if(widgets->tab[i].widget->align_supported & AlignFlex
|
||||||
|
&& widgets->tab[i].widget->align == AlignFlex)
|
||||||
{
|
{
|
||||||
int width = (ctx->width - (right + fake_left)) / flex;
|
int width = (ctx->width - (right + fake_left)) / flex;
|
||||||
/* give last pixels to last flex to be rendered */
|
/* give last pixels to last flex to be rendered */
|
||||||
|
@ -269,7 +272,7 @@ widget_render(widget_node_array_t *widgets, draw_context_t *ctx, xcb_gcontext_t
|
||||||
else
|
else
|
||||||
widgets->tab[i].geometry = widgets->tab[i].widget->geometry(widgets->tab[i].widget,
|
widgets->tab[i].geometry = widgets->tab[i].widget->geometry(widgets->tab[i].widget,
|
||||||
screen, ctx->height,
|
screen, ctx->height,
|
||||||
ctx->width - (left + right));
|
ctx->width - (left + right));
|
||||||
widgets->tab[i].geometry.x = left;
|
widgets->tab[i].geometry.x = left;
|
||||||
left += widgets->tab[i].geometry.width;
|
left += widgets->tab[i].geometry.width;
|
||||||
}
|
}
|
||||||
|
@ -389,7 +392,7 @@ luaA_widget_new(lua_State *L)
|
||||||
w->type = wc;
|
w->type = wc;
|
||||||
|
|
||||||
align = luaA_getopt_lstring(L, 2, "align", "left", &len);
|
align = luaA_getopt_lstring(L, 2, "align", "left", &len);
|
||||||
w->align_supported |= AlignLeft | AlignRight;
|
w->align_supported |= AlignLeft | AlignRight | AlignFixed;
|
||||||
w->align = draw_align_fromstr(align, len);
|
w->align = draw_align_fromstr(align, len);
|
||||||
|
|
||||||
/* Set visible by default. */
|
/* Set visible by default. */
|
||||||
|
|
Loading…
Reference in New Issue