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:
Michael Hofmann 2008-11-27 12:17:02 +01:00 committed by Julien Danjou
parent dbbe48898a
commit 39cd86f976
4 changed files with 16 additions and 9 deletions

View File

@ -23,6 +23,7 @@ east
ellipsize
end
fg
fixed
flex
floating
focus

6
draw.c
View File

@ -677,8 +677,8 @@ draw_text_extents(draw_text_context_t *data)
}
/** Transform a string to a alignment_t type.
* Recognized string are flex, left, center or right. Everything else will be
* recognized as AlignLeft.
* Recognized string are flex, fixed, left, center or right. Everything else
* will be recognized as AlignLeft.
* \param align Atring with align text.
* \param len The string length.
* \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_RIGHT: return AlignRight;
case A_TK_FLEX: return AlignFlex;
case A_TK_FIXED: return AlignFixed;
case A_TK_TOP: return AlignTop;
case A_TK_BOTTOM: return AlignBottom;
default: return AlignLeft;
@ -710,6 +711,7 @@ draw_align_tostr(alignment_t a)
case AlignCenter: return "center";
case AlignRight: return "right";
case AlignFlex: return "flex";
case AlignFixed: return "fixed";
case AlignBottom: return "bottom";
case AlignTop: return "top";
default: return NULL;

1
draw.h
View File

@ -61,6 +61,7 @@ typedef enum
AlignTop = (1 << 2),
AlignBottom = (1 << 3),
AlignFlex = (1 << 4),
AlignFixed = (1 << 5),
} alignment_t;
typedef struct vector_t vector_t;

View File

@ -64,6 +64,7 @@ widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment
{
case AlignLeft:
case AlignFlex:
case AlignFixed:
return offset;
}
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 */
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;
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)
{
if(widgets->tab[i].widget->align_supported & AlignFlex)
if(widgets->tab[i].widget->align_supported & AlignFlex
&& widgets->tab[i].widget->align == AlignFlex)
flex++;
else
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! */
int flex_rendered = 0;
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)
{
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;
/* give last pixels to last flex to be rendered */
@ -389,7 +392,7 @@ luaA_widget_new(lua_State *L)
w->type = wc;
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);
/* Set visible by default. */