draw: remove border markup, move it to textbox

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-12-02 16:31:35 +01:00
parent 29702799dc
commit 68f31f0629
4 changed files with 51 additions and 56 deletions

View File

@ -49,9 +49,6 @@ List of *awesome* markup elements and their attributes:
- image: path to a background image - image: path to a background image
- align: background image alignment - align: background image alignment
- resize: resize background image to text size - resize: resize background image to text size
* border
- color: border color
- width: border width
* margin * margin
- left: left margin in pixel - left: left margin in pixel
- right: right margin in pixel - right: right margin in pixel

74
draw.c
View File

@ -164,58 +164,39 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
/* hack: markup.c validates tags so we can avoid strcmps here */ /* hack: markup.c validates tags so we can avoid strcmps here */
switch (*elem) { switch (*elem) {
case 'b': case 'b':
if(elem[1] == 'g') /* bg? */ if(elem[2] == '_') /* bg_margin */
{ for(; *names; names++, values++)
if(elem[2] == '_') /* bg_margin */ switch(a_tokenize(*names, -1))
for(; *names; names++, values++) {
switch(a_tokenize(*names, -1)) case A_TK_LEFT:
{ data->bg_margin.left = atoi(*values);
case A_TK_LEFT: break;
data->bg_margin.left = atoi(*values); case A_TK_TOP:
break; data->bg_margin.top = atoi(*values);
case A_TK_TOP: default:
data->bg_margin.top = atoi(*values); break;
default: }
break; else /* bg */
}
else /* bg */
for(; *names; names++, values++)
switch(a_tokenize(*names, -1))
{
case A_TK_COLOR:
reqs[++reqs_nbr] = xcolor_init_unchecked(&data->bg_color,
*values,
a_strlen(*values));
bg_color_nbr = reqs_nbr;
break;
case A_TK_IMAGE:
if(data->bg_image)
image_delete(&data->bg_image);
data->bg_image = image_new_from_file(*values);
break;
case A_TK_ALIGN:
data->bg_align = draw_align_fromstr(*values, -1);
break;
case A_TK_RESIZE:
data->bg_resize = a_strtobool(*values, -1);
default:
break;
}
}
else /* border */
for(; *names; names++, values++) for(; *names; names++, values++)
switch(a_tokenize(*names, -1)) switch(a_tokenize(*names, -1))
{ {
case A_TK_COLOR: case A_TK_COLOR:
reqs[++reqs_nbr] = xcolor_init_unchecked(&data->border.color, reqs[++reqs_nbr] = xcolor_init_unchecked(&data->bg_color,
*values, *values,
a_strlen(*values)); a_strlen(*values));
bg_color_nbr = reqs_nbr;
break; break;
case A_TK_WIDTH: case A_TK_IMAGE:
data->border.width = atoi(*values); if(data->bg_image)
image_delete(&data->bg_image);
data->bg_image = image_new_from_file(*values);
break; break;
case A_TK_ALIGN:
data->bg_align = draw_align_fromstr(*values, -1);
break;
case A_TK_RESIZE:
data->bg_resize = a_strtobool(*values, -1);
default: default:
break; break;
} }
@ -268,7 +249,7 @@ static bool
draw_text_markup_expand(draw_parser_data_t *data, draw_text_markup_expand(draw_parser_data_t *data,
const char *str, ssize_t slen) const char *str, ssize_t slen)
{ {
static char const * const elements[] = { "bg", "bg_margin", "text", "margin", "border", NULL }; static char const * const elements[] = { "bg", "bg_margin", "text", "margin", NULL };
markup_parser_data_t p = markup_parser_data_t p =
{ {
.elements = elements, .elements = elements,
@ -366,9 +347,6 @@ draw_text(draw_context_t *ctx, font_t *font, PangoEllipsizeMode ellip, PangoWrap
if(pdata->has_bg_color) if(pdata->has_bg_color)
draw_rectangle(ctx, area, 1.0, true, &pdata->bg_color); draw_rectangle(ctx, area, 1.0, true, &pdata->bg_color);
if(pdata->border.width > 0)
draw_rectangle(ctx, area, pdata->border.width, false, &pdata->border.color);
if(pdata->bg_image) if(pdata->bg_image)
{ {
x = area.x; x = area.x;

5
draw.h
View File

@ -170,11 +170,6 @@ typedef struct
int offset; int offset;
xcolor_t color; xcolor_t color;
} shadow; } shadow;
struct
{
int width;
xcolor_t color;
} border;
} draw_parser_data_t; } draw_parser_data_t;
void draw_text(draw_context_t *, font_t *, PangoEllipsizeMode, PangoWrapMode, area_t, const char *, ssize_t len, draw_parser_data_t *, area_t *); void draw_text(draw_context_t *, font_t *, PangoEllipsizeMode, PangoWrapMode, area_t, const char *, ssize_t len, draw_parser_data_t *, area_t *);

View File

@ -39,6 +39,12 @@ typedef struct
PangoWrapMode wrap; PangoWrapMode wrap;
/** Draw parser data */ /** Draw parser data */
draw_parser_data_t pdata; draw_parser_data_t pdata;
/** Border */
struct
{
int width;
xcolor_t color;
} border;
} textbox_data_t; } textbox_data_t;
static area_t static area_t
@ -76,6 +82,10 @@ textbox_draw(widget_t *widget, draw_context_t *ctx, area_t geometry,
int screen, wibox_t *p) int screen, wibox_t *p)
{ {
textbox_data_t *d = widget->data; textbox_data_t *d = widget->data;
if(d->border.width > 0)
draw_rectangle(ctx, geometry, d->border.width, false, &d->border.color);
draw_text(ctx, globalconf.font, d->ellip, d->wrap, geometry, d->text, d->len, &d->pdata, &d->extents); draw_text(ctx, globalconf.font, d->ellip, d->wrap, geometry, d->text, d->len, &d->pdata, &d->extents);
} }
@ -100,6 +110,8 @@ textbox_destructor(widget_t *w)
* \lfield width The width of the textbox. Set to 0 for auto. * \lfield width The width of the textbox. Set to 0 for auto.
* \lfield wrap The wrap mode: word, char, word_char. * \lfield wrap The wrap mode: word, char, word_char.
* \lfield ellipsize The ellipsize mode: start, middle or end. * \lfield ellipsize The ellipsize mode: start, middle or end.
* \lfield border_width The border width to draw around.
* \lfield border_color The border color.
*/ */
static int static int
luaA_textbox_index(lua_State *L, awesome_token_t token) luaA_textbox_index(lua_State *L, awesome_token_t token)
@ -109,6 +121,12 @@ luaA_textbox_index(lua_State *L, awesome_token_t token)
switch(token) switch(token)
{ {
case A_TK_BORDER_WIDTH:
lua_pushnumber(L, d->border.width);
return 1;
case A_TK_BORDER_COLOR:
luaA_pushcolor(L, &d->border.color);
return 1;
case A_TK_TEXT: case A_TK_TEXT:
lua_pushstring(L, d->text); lua_pushstring(L, d->text);
return 1; return 1;
@ -163,6 +181,13 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
switch(token) switch(token)
{ {
case A_TK_BORDER_COLOR:
if((buf = luaL_checklstring(L, 3, &len)))
xcolor_init_reply(xcolor_init_unchecked(&d->border.color, buf, len));
break;
case A_TK_BORDER_WIDTH:
d->border.width = luaL_checknumber(L, 3);
break;
case A_TK_TEXT: case A_TK_TEXT:
if(lua_isnil(L, 3) if(lua_isnil(L, 3)
|| (buf = luaL_checklstring(L, 3, &len))) || (buf = luaL_checklstring(L, 3, &len)))