textbox: add ellipsize and wrap mode support
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
67c56d35a4
commit
a5cb98162d
|
@ -11,6 +11,7 @@ bottomleft
|
||||||
bottomright
|
bottomright
|
||||||
button
|
button
|
||||||
center
|
center
|
||||||
|
char
|
||||||
class
|
class
|
||||||
client
|
client
|
||||||
color
|
color
|
||||||
|
@ -18,6 +19,8 @@ Control
|
||||||
coords
|
coords
|
||||||
Ctrl
|
Ctrl
|
||||||
east
|
east
|
||||||
|
ellipsize
|
||||||
|
end
|
||||||
fg
|
fg
|
||||||
flex
|
flex
|
||||||
floating
|
floating
|
||||||
|
@ -41,6 +44,7 @@ len
|
||||||
line
|
line
|
||||||
Lock
|
Lock
|
||||||
machine
|
machine
|
||||||
|
middle
|
||||||
minimize
|
minimize
|
||||||
Mod1
|
Mod1
|
||||||
Mod2
|
Mod2
|
||||||
|
@ -50,9 +54,9 @@ Mod5
|
||||||
mouse_enter
|
mouse_enter
|
||||||
mouse_leave
|
mouse_leave
|
||||||
mwfact
|
mwfact
|
||||||
|
name
|
||||||
ncol
|
ncol
|
||||||
nmaster
|
nmaster
|
||||||
name
|
|
||||||
on
|
on
|
||||||
ontop
|
ontop
|
||||||
opacity
|
opacity
|
||||||
|
@ -75,6 +79,7 @@ show_icons
|
||||||
sizehints
|
sizehints
|
||||||
skip_taskbar
|
skip_taskbar
|
||||||
south
|
south
|
||||||
|
start
|
||||||
sticky
|
sticky
|
||||||
text
|
text
|
||||||
ticks_count
|
ticks_count
|
||||||
|
@ -91,5 +96,8 @@ visible
|
||||||
vertical
|
vertical
|
||||||
widgets
|
widgets
|
||||||
width
|
width
|
||||||
|
word
|
||||||
|
word_char
|
||||||
workarea
|
workarea
|
||||||
|
wrap
|
||||||
yes
|
yes
|
||||||
|
|
8
draw.c
8
draw.c
|
@ -330,13 +330,15 @@ draw_context_init(draw_context_t *d, int phys_screen,
|
||||||
/** Draw text into a draw context.
|
/** Draw text into a draw context.
|
||||||
* \param ctx Draw context to draw to.
|
* \param ctx Draw context to draw to.
|
||||||
* \param font The font to use.
|
* \param font The font to use.
|
||||||
|
* \param elip Ellipsize mode.
|
||||||
|
* \param wrap Wrap mode.
|
||||||
* \param area Area to draw to.
|
* \param area Area to draw to.
|
||||||
* \param text Text to draw.
|
* \param text Text to draw.
|
||||||
* \param len Text to draw length.
|
* \param len Text to draw length.
|
||||||
* \param data Optional parser data.
|
* \param data Optional parser data.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
draw_text(draw_context_t *ctx, font_t *font,
|
draw_text(draw_context_t *ctx, font_t *font, PangoEllipsizeMode ellip, PangoWrapMode wrap,
|
||||||
area_t area, const char *text, ssize_t len, draw_parser_data_t *pdata)
|
area_t area, const char *text, ssize_t len, draw_parser_data_t *pdata)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
@ -392,8 +394,8 @@ draw_text(draw_context_t *ctx, font_t *font,
|
||||||
- (pdata->margin.left
|
- (pdata->margin.left
|
||||||
+ pdata->margin.right)));
|
+ pdata->margin.right)));
|
||||||
pango_layout_set_height(ctx->layout, pango_units_from_double(area.height));
|
pango_layout_set_height(ctx->layout, pango_units_from_double(area.height));
|
||||||
pango_layout_set_ellipsize(ctx->layout, PANGO_ELLIPSIZE_END);
|
pango_layout_set_ellipsize(ctx->layout, ellip);
|
||||||
pango_layout_set_wrap(ctx->layout, PANGO_WRAP_WORD_CHAR);
|
pango_layout_set_wrap(ctx->layout, wrap);
|
||||||
pango_layout_set_attributes(ctx->layout, pdata->attr_list);
|
pango_layout_set_attributes(ctx->layout, pdata->attr_list);
|
||||||
pango_layout_set_font_description(ctx->layout, font->desc);
|
pango_layout_set_font_description(ctx->layout, font->desc);
|
||||||
pango_layout_get_pixel_extents(ctx->layout, NULL, &ext);
|
pango_layout_get_pixel_extents(ctx->layout, NULL, &ext);
|
||||||
|
|
2
draw.h
2
draw.h
|
@ -177,7 +177,7 @@ typedef struct
|
||||||
} border;
|
} border;
|
||||||
} draw_parser_data_t;
|
} draw_parser_data_t;
|
||||||
|
|
||||||
void draw_text(draw_context_t *, font_t *, area_t, const char *, ssize_t len, 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 *);
|
||||||
void draw_rectangle(draw_context_t *, area_t, float, bool, const xcolor_t *);
|
void draw_rectangle(draw_context_t *, area_t, float, bool, const xcolor_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 xcolor_t *, const xcolor_t *, const xcolor_t *);
|
const xcolor_t *, const xcolor_t *, const xcolor_t *);
|
||||||
|
|
2
mouse.c
2
mouse.c
|
@ -258,7 +258,7 @@ mouse_infobox_draw(simple_window_t *sw, area_t geometry, int border)
|
||||||
len = snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d",
|
len = snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d",
|
||||||
geometry.width, geometry.height, geometry.x, geometry.y);
|
geometry.width, geometry.height, geometry.x, geometry.y);
|
||||||
draw_rectangle(&sw->ctx, draw_geometry, 1.0, true, &color_without_alpha);
|
draw_rectangle(&sw->ctx, draw_geometry, 1.0, true, &color_without_alpha);
|
||||||
draw_text(&sw->ctx, globalconf.font, draw_geometry, size, len, NULL);
|
draw_text(&sw->ctx, globalconf.font, PANGO_ELLIPSIZE_NONE, PANGO_WRAP_WORD, draw_geometry, size, len, NULL);
|
||||||
simplewindow_move(sw,
|
simplewindow_move(sw,
|
||||||
geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2,
|
geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2,
|
||||||
geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2);
|
geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2);
|
||||||
|
|
|
@ -35,6 +35,8 @@ typedef struct
|
||||||
int width;
|
int width;
|
||||||
/** Extents */
|
/** Extents */
|
||||||
int extents;
|
int extents;
|
||||||
|
PangoEllipsizeMode ellip;
|
||||||
|
PangoWrapMode wrap;
|
||||||
/** Draw parser data */
|
/** Draw parser data */
|
||||||
draw_parser_data_t pdata;
|
draw_parser_data_t pdata;
|
||||||
} textbox_data_t;
|
} textbox_data_t;
|
||||||
|
@ -74,7 +76,7 @@ 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;
|
||||||
draw_text(ctx, globalconf.font, geometry, d->text, d->len, &d->pdata);
|
draw_text(ctx, globalconf.font, d->ellip, d->wrap, geometry, d->text, d->len, &d->pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Delete a textbox widget.
|
/** Delete a textbox widget.
|
||||||
|
@ -111,6 +113,34 @@ luaA_textbox_index(lua_State *L, awesome_token_t token)
|
||||||
case A_TK_WIDTH:
|
case A_TK_WIDTH:
|
||||||
lua_pushnumber(L, d->width);
|
lua_pushnumber(L, d->width);
|
||||||
return 1;
|
return 1;
|
||||||
|
case A_TK_WRAP:
|
||||||
|
switch(d->wrap)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
lua_pushliteral(L, "word");
|
||||||
|
break;
|
||||||
|
case A_TK_CHAR:
|
||||||
|
lua_pushliteral(L, "char");
|
||||||
|
break;
|
||||||
|
case A_TK_WORD_CHAR:
|
||||||
|
lua_pushliteral(L, "word_char");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
case A_TK_ELLIPSIZE:
|
||||||
|
switch(d->ellip)
|
||||||
|
{
|
||||||
|
case A_TK_START:
|
||||||
|
lua_pushliteral(L, "start");
|
||||||
|
break;
|
||||||
|
case A_TK_MIDDLE:
|
||||||
|
lua_pushliteral(L, "middle");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
lua_pushliteral(L, "end");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -155,6 +185,40 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
|
||||||
case A_TK_WIDTH:
|
case A_TK_WIDTH:
|
||||||
d->width = luaL_checknumber(L, 3);
|
d->width = luaL_checknumber(L, 3);
|
||||||
break;
|
break;
|
||||||
|
case A_TK_WRAP:
|
||||||
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
|
switch(a_tokenize(buf, len))
|
||||||
|
{
|
||||||
|
case A_TK_WORD:
|
||||||
|
d->wrap = PANGO_WRAP_WORD;
|
||||||
|
break;
|
||||||
|
case A_TK_CHAR:
|
||||||
|
d->wrap = PANGO_WRAP_CHAR;
|
||||||
|
break;
|
||||||
|
case A_TK_WORD_CHAR:
|
||||||
|
d->wrap = PANGO_WRAP_WORD_CHAR;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case A_TK_ELLIPSIZE:
|
||||||
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
|
switch(a_tokenize(buf, len))
|
||||||
|
{
|
||||||
|
case A_TK_START:
|
||||||
|
d->ellip = PANGO_ELLIPSIZE_START;
|
||||||
|
break;
|
||||||
|
case A_TK_MIDDLE:
|
||||||
|
d->ellip = PANGO_ELLIPSIZE_MIDDLE;
|
||||||
|
break;
|
||||||
|
case A_TK_END:
|
||||||
|
d->ellip = PANGO_ELLIPSIZE_END;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -184,6 +248,7 @@ textbox_new(alignment_t align)
|
||||||
w->destructor = textbox_destructor;
|
w->destructor = textbox_destructor;
|
||||||
w->geometry = textbox_geometry;
|
w->geometry = textbox_geometry;
|
||||||
w->data = d = p_new(textbox_data_t, 1);
|
w->data = d = p_new(textbox_data_t, 1);
|
||||||
|
d->ellip = PANGO_ELLIPSIZE_END;
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue