[draw] Add margin code inside markup string
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
1fc2b7997a
commit
f12f1798dd
|
@ -431,8 +431,7 @@ redraw(void)
|
|||
|
||||
if(a_strlen(globalconf.prompt))
|
||||
{
|
||||
draw_text(globalconf.ctx, geometry,
|
||||
MARGIN, globalconf.prompt, globalconf.styles.focus);
|
||||
draw_text(globalconf.ctx, geometry, globalconf.prompt, globalconf.styles.focus);
|
||||
|
||||
len = MARGIN * 2 + draw_text_extents(globalconf.connection, globalconf.default_screen,
|
||||
globalconf.styles.focus.font, globalconf.prompt).width;
|
||||
|
@ -440,8 +439,7 @@ redraw(void)
|
|||
geometry.width -= len;
|
||||
}
|
||||
|
||||
draw_text(globalconf.ctx, geometry,
|
||||
MARGIN, globalconf.text, globalconf.styles.normal);
|
||||
draw_text(globalconf.ctx, geometry, globalconf.text, globalconf.styles.normal);
|
||||
|
||||
len = MARGIN * 2 + MAX(draw_text_extents(globalconf.connection, globalconf.default_screen,
|
||||
globalconf.styles.normal.font, globalconf.text).width,
|
||||
|
@ -463,7 +461,7 @@ redraw(void)
|
|||
else
|
||||
selected_item_is_drawn = true;
|
||||
}
|
||||
draw_text(globalconf.ctx, geometry, MARGIN / 2, item->data, style);
|
||||
draw_text(globalconf.ctx, geometry, item->data, style);
|
||||
geometry.x += len;
|
||||
geometry.width -= len;
|
||||
}
|
||||
|
@ -485,7 +483,7 @@ redraw(void)
|
|||
if(geometry.x < prompt_len)
|
||||
break;
|
||||
|
||||
draw_text(globalconf.ctx, geometry, MARGIN / 2, item->data, style);
|
||||
draw_text(globalconf.ctx, geometry, item->data, style);
|
||||
}
|
||||
|
||||
if(item)
|
||||
|
|
|
@ -211,7 +211,7 @@ main(int argc, char **argv)
|
|||
geometry.width, geometry.height, sw->drawable);
|
||||
|
||||
geometry.x = geometry.y = 0;
|
||||
draw_text(ctx, geometry, 0, argv[optind], globalconf.style);
|
||||
draw_text(ctx, geometry, argv[optind], globalconf.style);
|
||||
|
||||
if(icon_geometry.width > 0 && icon_geometry.height > 0)
|
||||
draw_image(ctx, 0, (geometry.height / 2) - (globalconf.style.font->height / 2),
|
||||
|
|
|
@ -221,6 +221,10 @@ typedef struct
|
|||
int phys_screen;
|
||||
char *text;
|
||||
alignment_t align;
|
||||
struct
|
||||
{
|
||||
int left, right;
|
||||
} margin;
|
||||
bool has_bg_color;
|
||||
xcolor_t bg_color;
|
||||
} draw_parser_data_t;
|
||||
|
@ -229,14 +233,14 @@ static bool
|
|||
draw_text_markup_expand(draw_parser_data_t *data,
|
||||
const char *str, ssize_t slen)
|
||||
{
|
||||
const char *elements[] = { "bg", "text", NULL };
|
||||
const char *elements[] = { "bg", "text", "margin", NULL };
|
||||
markup_parser_data_t *p;
|
||||
int i;
|
||||
|
||||
p = markup_parser_data_new(elements, NULL, countof(elements));
|
||||
|
||||
if(!markup_parse(p, str, slen))
|
||||
return false;
|
||||
return a_strdup(str);
|
||||
|
||||
/* bg */
|
||||
if(p->attribute_names[0])
|
||||
|
@ -251,6 +255,16 @@ draw_text_markup_expand(draw_parser_data_t *data,
|
|||
if(!a_strcmp(p->attribute_names[1][i], "align"))
|
||||
data->align = draw_align_get_from_str(p->attribute_values[1][i]);
|
||||
|
||||
/* margin */
|
||||
if(p->attribute_names[2])
|
||||
for(i = 0; p->attribute_names[2][i]; i++)
|
||||
{
|
||||
if(!a_strcmp(p->attribute_names[2][i], "left"))
|
||||
data->margin.left = atoi(p->attribute_values[2][i]);
|
||||
else if(!a_strcmp(p->attribute_names[2][i], "right"))
|
||||
data->margin.right = atoi(p->attribute_values[2][i]);
|
||||
}
|
||||
|
||||
/* stole text */
|
||||
data->text = p->text;
|
||||
p->text = NULL;
|
||||
|
@ -263,16 +277,11 @@ draw_text_markup_expand(draw_parser_data_t *data,
|
|||
/** Draw text into a draw context
|
||||
* \param ctx DrawCtx to draw to
|
||||
* \param area area to draw to
|
||||
* \param padding padding to add before drawing the text
|
||||
* \param text text to draw
|
||||
* \return area_t with width and height are set to what used
|
||||
*/
|
||||
void
|
||||
draw_text(DrawCtx *ctx,
|
||||
area_t area,
|
||||
int padding,
|
||||
const char *text,
|
||||
style_t style)
|
||||
draw_text(DrawCtx *ctx, area_t area, const char *text, style_t style)
|
||||
{
|
||||
int x, y;
|
||||
ssize_t len, olen;
|
||||
|
@ -311,13 +320,16 @@ draw_text(DrawCtx *ctx,
|
|||
else
|
||||
draw_rectangle(ctx, area, 1.0, true, style.bg);
|
||||
|
||||
pango_layout_set_width(ctx->layout, pango_units_from_double(area.width - padding));
|
||||
pango_layout_set_width(ctx->layout,
|
||||
pango_units_from_double(area.width
|
||||
- (parser_data.margin.left
|
||||
+ parser_data.margin.right)));
|
||||
pango_layout_set_ellipsize(ctx->layout, PANGO_ELLIPSIZE_END);
|
||||
pango_layout_set_markup(ctx->layout, buf, len);
|
||||
pango_layout_set_font_description(ctx->layout, style.font->desc);
|
||||
pango_layout_get_pixel_extents(ctx->layout, NULL, &ext);
|
||||
|
||||
x = area.x + padding;
|
||||
x = area.x + parser_data.margin.left;
|
||||
/* + 1 is added for rounding, so that in any case of doubt we rather draw
|
||||
* the text 1px lower than too high which usually results in a better type
|
||||
* face */
|
||||
|
|
|
@ -125,7 +125,7 @@ void draw_context_delete(DrawCtx **);
|
|||
font_t *draw_font_new(xcb_connection_t *, int, char *);
|
||||
void draw_font_delete(font_t **);
|
||||
|
||||
void draw_text(DrawCtx *, area_t, int, const char *, style_t);
|
||||
void draw_text(DrawCtx *, area_t, const char *, style_t);
|
||||
void draw_rectangle(DrawCtx *, area_t, float, bool, xcolor_t);
|
||||
void draw_rectangle_gradient(DrawCtx *, area_t, float, bool, area_t, xcolor_t *, xcolor_t *, xcolor_t *);
|
||||
|
||||
|
|
|
@ -148,10 +148,7 @@ markup_parse_text(GMarkupParseContext *context __attribute__ ((unused)),
|
|||
len = a_strlen(p->text);
|
||||
rlen = len + 1 + text_len;
|
||||
p_realloc(&p->text, rlen);
|
||||
if(len)
|
||||
a_strncat(p->text, rlen, text, len);
|
||||
else
|
||||
a_strncpy(p->text, rlen, text, text_len);
|
||||
a_strncat(p->text, rlen, text, text_len);
|
||||
}
|
||||
|
||||
/** Create a markup_parser_data_t structure with elements list.
|
||||
|
@ -169,6 +166,7 @@ markup_parser_data_new(const char **elements, const char **elements_sub, ssize_t
|
|||
|
||||
p = p_new(markup_parser_data_t, 1);
|
||||
|
||||
p->text = p_new(char, 1);
|
||||
p->elements = elements;
|
||||
p->elements_sub = elements_sub;
|
||||
p->attribute_names = p_new(char **, nelem);
|
||||
|
|
2
mouse.c
2
mouse.c
|
@ -145,7 +145,7 @@ mouse_resizebar_draw(DrawCtx *ctx, style_t style, simple_window_t *sw, area_t ge
|
|||
|
||||
snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d",
|
||||
geometry.x, geometry.y, geometry.width, geometry.height);
|
||||
draw_text(ctx, draw_geometry, style.font->height / 2, size, style);
|
||||
draw_text(ctx, draw_geometry, size, style);
|
||||
simplewindow_move(sw,
|
||||
geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2,
|
||||
geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2);
|
||||
|
|
|
@ -216,8 +216,7 @@ titlebar_draw(client_t *c)
|
|||
|
||||
text = titlebar_text(c);
|
||||
geometry.x = geometry.y = 0;
|
||||
draw_text(ctx, geometry, 0,
|
||||
text, globalconf.screens[c->screen].styles.normal);
|
||||
draw_text(ctx, geometry, text, globalconf.screens[c->screen].styles.normal);
|
||||
p_delete(&text);
|
||||
|
||||
switch(c->titlebar.position)
|
||||
|
|
|
@ -123,7 +123,6 @@ taglist_draw(widget_t *widget,
|
|||
*area = draw_text_extents(ctx->connection, ctx->default_screen,
|
||||
style.font, text[i]);
|
||||
area->x = widget->area.width;
|
||||
area->width += style.font->height;
|
||||
area->height = widget->statusbar->height;
|
||||
area_list_append(&data->draw_area, area);
|
||||
widget->area.width += area->width;
|
||||
|
@ -142,7 +141,7 @@ taglist_draw(widget_t *widget,
|
|||
tag && area;
|
||||
tag = tag->next, area = area->next, i++)
|
||||
{
|
||||
draw_text(ctx, *area, 0, text[i], style);
|
||||
draw_text(ctx, *area, text[i], style);
|
||||
|
||||
if(tag_isoccupied(tag))
|
||||
{
|
||||
|
|
|
@ -169,7 +169,7 @@ tasklist_draw(widget_t *widget, DrawCtx *ctx, int offset, int used)
|
|||
if(i == n - 1)
|
||||
area.width += box_width_rest;
|
||||
|
||||
draw_text(ctx, area, style.font->height / 2, text, style);
|
||||
draw_text(ctx, area, text, style);
|
||||
|
||||
p_delete(&text);
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ textbox_draw(widget_t *widget, DrawCtx *ctx, int offset, int used)
|
|||
if(!widget->user_supplied_y)
|
||||
widget->area.y = 0;
|
||||
|
||||
draw_text(ctx, widget->area, 0, d->text, globalconf.screens[widget->statusbar->screen].styles.normal);
|
||||
draw_text(ctx, widget->area, d->text, globalconf.screens[widget->statusbar->screen].styles.normal);
|
||||
|
||||
return widget->area.width;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue