imagebox: support vertical alignment

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-11-04 16:38:06 +01:00
parent 24a8e6d377
commit 10df0a9dc4
2 changed files with 26 additions and 1 deletions

View File

@ -86,6 +86,7 @@ topright
true true
type type
urgent urgent
valign
visible visible
vertical vertical
widgets widgets

View File

@ -30,6 +30,7 @@ typedef struct
/** Imagebox image */ /** Imagebox image */
image_t *image; image_t *image;
xcolor_t bg; xcolor_t bg;
alignment_t valign;
bool resize; bool resize;
} imagebox_data_t; } imagebox_data_t;
@ -74,7 +75,21 @@ imagebox_draw(widget_t *widget, draw_context_t *ctx, area_t geometry,
{ {
if(d->bg.initialized) if(d->bg.initialized)
draw_rectangle(ctx, geometry, 1.0, true, &d->bg); draw_rectangle(ctx, geometry, 1.0, true, &d->bg);
draw_image(ctx, geometry.x, geometry.y, d->resize ? ctx->height : 0, d->image);
int y = geometry.y;
switch(d->valign)
{
case AlignBottom:
y += geometry.height - d->image->height;
break;
case AlignCenter:
y += (geometry.height - d->image->height) / 2;
break;
default:
break;
}
draw_image(ctx, geometry.x, y, d->resize ? ctx->height : 0, d->image);
} }
} }
@ -93,6 +108,7 @@ imagebox_destructor(widget_t *w)
* \param L The Lua VM state. * \param L The Lua VM state.
* \param token The key token. * \param token The key token.
* \param resize Resize image. * \param resize Resize image.
* \param valign Vertical alignment, top, bottom or center.
* \return The number of elements pushed on stack. * \return The number of elements pushed on stack.
* \luastack * \luastack
* \lfield image The image to display. * \lfield image The image to display.
@ -117,6 +133,9 @@ luaA_imagebox_index(lua_State *L, awesome_token_t token)
case A_TK_RESIZE: case A_TK_RESIZE:
lua_pushboolean(L, d->resize); lua_pushboolean(L, d->resize);
break; break;
case A_TK_VALIGN:
lua_pushstring(L, draw_align_tostr(d->valign));
break;
default: default:
return 0; return 0;
} }
@ -162,6 +181,10 @@ luaA_imagebox_newindex(lua_State *L, awesome_token_t token)
case A_TK_RESIZE: case A_TK_RESIZE:
d->resize = luaA_checkboolean(L, 3); d->resize = luaA_checkboolean(L, 3);
break; break;
case A_TK_VALIGN:
if((buf = luaL_checklstring(L, 3, &len)))
d->valign = draw_align_fromstr(buf, len);
break;
default: default:
return 0; return 0;
} }
@ -190,6 +213,7 @@ imagebox_new(alignment_t align)
w->geometry = imagebox_geometry; w->geometry = imagebox_geometry;
w->data = d = p_new(imagebox_data_t, 1); w->data = d = p_new(imagebox_data_t, 1);
d->resize = true; d->resize = true;
d->valign = AlignTop;
return w; return w;
} }