textbox: add valign
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
f149a6a55d
commit
26c446fa82
|
@ -111,6 +111,7 @@ top
|
||||||
transient_for
|
transient_for
|
||||||
type
|
type
|
||||||
urgent
|
urgent
|
||||||
|
valign
|
||||||
version
|
version
|
||||||
vertical
|
vertical
|
||||||
visible
|
visible
|
||||||
|
|
15
draw.c
15
draw.c
|
@ -200,6 +200,7 @@ draw_context_init(draw_context_t *d, int phys_screen,
|
||||||
* \param ellip Ellipsize mode.
|
* \param ellip Ellipsize mode.
|
||||||
* \param wrap Wrap mode.
|
* \param wrap Wrap mode.
|
||||||
* \param align Text alignment.
|
* \param align Text alignment.
|
||||||
|
* \param valign Vertical text alignment.
|
||||||
* \param margin Margin to respect when drawing text.
|
* \param margin Margin to respect when drawing text.
|
||||||
* \param area Area to draw to.
|
* \param area Area to draw to.
|
||||||
* \param ext Text extents.
|
* \param ext Text extents.
|
||||||
|
@ -207,7 +208,7 @@ draw_context_init(draw_context_t *d, int phys_screen,
|
||||||
void
|
void
|
||||||
draw_text(draw_context_t *ctx, draw_text_context_t *data,
|
draw_text(draw_context_t *ctx, draw_text_context_t *data,
|
||||||
PangoEllipsizeMode ellip, PangoWrapMode wrap,
|
PangoEllipsizeMode ellip, PangoWrapMode wrap,
|
||||||
alignment_t align, padding_t *margin, area_t area, area_t *ext)
|
alignment_t align, alignment_t valign, padding_t *margin, area_t area, area_t *ext)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
|
@ -240,6 +241,18 @@ draw_text(draw_context_t *ctx, draw_text_context_t *data,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch(valign)
|
||||||
|
{
|
||||||
|
case AlignCenter:
|
||||||
|
y += (area.height - ext->height) / 2;
|
||||||
|
break;
|
||||||
|
case AlignBottom:
|
||||||
|
y += area.height - ext->height;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
cairo_move_to(ctx->cr, x, y);
|
cairo_move_to(ctx->cr, x, y);
|
||||||
|
|
||||||
cairo_set_source_rgba(ctx->cr,
|
cairo_set_source_rgba(ctx->cr,
|
||||||
|
|
2
draw.h
2
draw.h
|
@ -159,7 +159,7 @@ typedef struct
|
||||||
} draw_text_context_t;
|
} draw_text_context_t;
|
||||||
|
|
||||||
bool draw_text_context_init(draw_text_context_t *, const char *, ssize_t);
|
bool draw_text_context_init(draw_text_context_t *, const char *, ssize_t);
|
||||||
void draw_text(draw_context_t *, draw_text_context_t *, PangoEllipsizeMode, PangoWrapMode, alignment_t, padding_t *, area_t, area_t *);
|
void draw_text(draw_context_t *, draw_text_context_t *, PangoEllipsizeMode, PangoWrapMode, alignment_t, alignment_t, padding_t *, area_t, area_t *);
|
||||||
void draw_rectangle(draw_context_t *, area_t, float, bool, const color_t *);
|
void draw_rectangle(draw_context_t *, area_t, float, bool, const color_t *);
|
||||||
void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t,
|
void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t,
|
||||||
const color_t *, const color_t *, const color_t *);
|
const color_t *, const color_t *, const color_t *);
|
||||||
|
|
|
@ -41,7 +41,7 @@ typedef struct
|
||||||
color_t color;
|
color_t color;
|
||||||
} border;
|
} border;
|
||||||
/** Text alignment */
|
/** Text alignment */
|
||||||
alignment_t align;
|
alignment_t align, valign;
|
||||||
/** Margin */
|
/** Margin */
|
||||||
padding_t margin;
|
padding_t margin;
|
||||||
/** Background color */
|
/** Background color */
|
||||||
|
@ -128,8 +128,7 @@ textbox_draw(widget_t *widget, draw_context_t *ctx, area_t geometry, wibox_t *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
geometry.y += (geometry.height - textbox_geometry(widget, ctx->phys_screen).height) / 2;
|
draw_text(ctx, &d->data, d->ellip, d->wrap, d->align, d->valign, &d->margin, geometry, &d->extents);
|
||||||
draw_text(ctx, &d->data, d->ellip, d->wrap, d->align, &d->margin, geometry, &d->extents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Delete a textbox widget.
|
/** Delete a textbox widget.
|
||||||
|
@ -200,6 +199,9 @@ luaA_textbox_index(lua_State *L, awesome_token_t token)
|
||||||
case A_TK_ALIGN:
|
case A_TK_ALIGN:
|
||||||
lua_pushstring(L, draw_align_tostr(d->align));
|
lua_pushstring(L, draw_align_tostr(d->align));
|
||||||
return 1;
|
return 1;
|
||||||
|
case A_TK_VALIGN:
|
||||||
|
lua_pushstring(L, draw_align_tostr(d->valign));
|
||||||
|
return 1;
|
||||||
case A_TK_BORDER_WIDTH:
|
case A_TK_BORDER_WIDTH:
|
||||||
lua_pushnumber(L, d->border.width);
|
lua_pushnumber(L, d->border.width);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -285,6 +287,10 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
|
||||||
if((buf = luaL_checklstring(L, 3, &len)))
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
d->align = draw_align_fromstr(buf, len);
|
d->align = draw_align_fromstr(buf, len);
|
||||||
break;
|
break;
|
||||||
|
case A_TK_VALIGN:
|
||||||
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
|
d->valign = draw_align_fromstr(buf, len);
|
||||||
|
break;
|
||||||
case A_TK_BORDER_COLOR:
|
case A_TK_BORDER_COLOR:
|
||||||
if((buf = luaL_checklstring(L, 3, &len)))
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
color_init_reply(color_init_unchecked(&d->border.color, buf, len));
|
color_init_reply(color_init_unchecked(&d->border.color, buf, len));
|
||||||
|
@ -381,6 +387,7 @@ widget_textbox(widget_t *w)
|
||||||
|
|
||||||
textbox_data_t *d = w->data = p_new(textbox_data_t, 1);
|
textbox_data_t *d = w->data = p_new(textbox_data_t, 1);
|
||||||
d->ellip = PANGO_ELLIPSIZE_END;
|
d->ellip = PANGO_ELLIPSIZE_END;
|
||||||
|
d->valign = AlignCenter;
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue