mirror of
https://github.com/labwc/labwc.git
synced 2026-05-07 12:06:30 -04:00
scaled-buffer: introduce scaled_font_buffer_update_markup()
This function behaves identically to `scaled_font_buffer_update()` but allows setting the text as pango markup, supporting further customization like underscores.
This commit is contained in:
parent
0caefa6a9e
commit
07a0a4e59b
4 changed files with 46 additions and 9 deletions
|
|
@ -79,7 +79,7 @@ font_get_buffer_size(int max_width, const char *text, struct font *font,
|
|||
void
|
||||
font_buffer_create(struct lab_data_buffer **buffer, int max_width,
|
||||
int height, const char *text, struct font *font, const float *color,
|
||||
cairo_pattern_t *bg_pattern, double scale)
|
||||
cairo_pattern_t *bg_pattern, double scale, bool use_markup)
|
||||
{
|
||||
if (string_null_or_empty(text)) {
|
||||
return;
|
||||
|
|
@ -123,7 +123,13 @@ font_buffer_create(struct lab_data_buffer **buffer, int max_width,
|
|||
PangoLayout *layout = pango_cairo_create_layout(cairo);
|
||||
pango_context_set_round_glyph_positions(pango_layout_get_context(layout), false);
|
||||
pango_layout_set_width(layout, width * PANGO_SCALE);
|
||||
pango_layout_set_text(layout, text, -1);
|
||||
|
||||
if (use_markup) {
|
||||
pango_layout_set_markup(layout, text, -1);
|
||||
} else {
|
||||
pango_layout_set_text(layout, text, -1);
|
||||
}
|
||||
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
|
||||
if (!opaque_bg) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ _create_buffer(struct scaled_buffer *scaled_buffer, double scale)
|
|||
|
||||
/* Buffer gets free'd automatically along the backing wlr_buffer */
|
||||
font_buffer_create(&buffer, self->max_width, self->height, self->text,
|
||||
&self->font, self->color, bg_pattern, scale);
|
||||
&self->font, self->color, bg_pattern, scale, self->use_markup);
|
||||
|
||||
if (!buffer) {
|
||||
wlr_log(WLR_ERROR, "font_buffer_create() failed");
|
||||
|
|
@ -56,6 +56,7 @@ _equal(struct scaled_buffer *scaled_buffer_a,
|
|||
struct scaled_font_buffer *b = scaled_buffer_b->data;
|
||||
|
||||
return str_equal(a->text, b->text)
|
||||
&& a->use_markup == b->use_markup
|
||||
&& a->max_width == b->max_width
|
||||
&& str_equal(a->font.name, b->font.name)
|
||||
&& a->font.size == b->font.size
|
||||
|
|
@ -104,10 +105,10 @@ scaled_font_buffer_create_for_titlebar(struct wlr_scene_tree *parent,
|
|||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
scaled_font_buffer_update(struct scaled_font_buffer *self, const char *text,
|
||||
static void
|
||||
_scaled_font_buffer_update(struct scaled_font_buffer *self, const char *text,
|
||||
int max_width, struct font *font, const float *color,
|
||||
const float *bg_color)
|
||||
const float *bg_color, bool use_markup)
|
||||
{
|
||||
assert(self);
|
||||
assert(text);
|
||||
|
|
@ -120,6 +121,7 @@ scaled_font_buffer_update(struct scaled_font_buffer *self, const char *text,
|
|||
|
||||
/* Update internal state */
|
||||
self->text = xstrdup(text);
|
||||
self->use_markup = use_markup;
|
||||
self->max_width = max_width;
|
||||
if (font->name) {
|
||||
self->font.name = xstrdup(font->name);
|
||||
|
|
@ -139,3 +141,19 @@ scaled_font_buffer_update(struct scaled_font_buffer *self, const char *text,
|
|||
scaled_buffer_request_update(self->scaled_buffer,
|
||||
self->width, self->height);
|
||||
}
|
||||
|
||||
void
|
||||
scaled_font_buffer_update(struct scaled_font_buffer *self, const char *text,
|
||||
int max_width, struct font *font, const float *color,
|
||||
const float *bg_color)
|
||||
{
|
||||
_scaled_font_buffer_update(self, text, max_width, font, color, bg_color, false);
|
||||
}
|
||||
|
||||
void
|
||||
scaled_font_buffer_update_markup(struct scaled_font_buffer *self, const char *text,
|
||||
int max_width, struct font *font, const float *color,
|
||||
const float *bg_color, bool use_markup)
|
||||
{
|
||||
_scaled_font_buffer_update(self, text, max_width, font, color, bg_color, use_markup);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue