mirror of
https://github.com/labwc/labwc.git
synced 2026-02-12 04:27:57 -05:00
common/font: add scaled_font_buffer_create_for_titlebar()
Co-authored-by: tokyo4j <hrak1529@gmail.com>
This commit is contained in:
parent
3ca7adace0
commit
54b236e027
4 changed files with 76 additions and 18 deletions
|
|
@ -1,6 +1,8 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef LABWC_FONT_H
|
||||
#define LABWC_FONT_H
|
||||
|
||||
#include <cairo.h>
|
||||
#include <pango/pango-font.h>
|
||||
|
||||
struct lab_data_buffer;
|
||||
|
|
@ -36,14 +38,15 @@ void font_get_buffer_size(int max_width, const char *text, struct font *font,
|
|||
* font_buffer_create - Create ARGB8888 lab_data_buffer using pango
|
||||
* @buffer: buffer pointer
|
||||
* @max_width: max allowable width; will be ellipsized if longer
|
||||
* @height: buffer height or -1 to compute from font
|
||||
* @text: text to be generated as texture
|
||||
* @font: font description
|
||||
* @color: foreground color in rgba format
|
||||
* @bg_color: background color in rgba format
|
||||
* @bg_pattern: background pattern
|
||||
*/
|
||||
void font_buffer_create(struct lab_data_buffer **buffer, int max_width,
|
||||
const char *text, struct font *font, const float *color,
|
||||
const float *bg_color, double scale);
|
||||
int height, const char *text, struct font *font, const float *color,
|
||||
cairo_pattern_t *bg_pattern, double scale);
|
||||
|
||||
/**
|
||||
* font_finish - free some font related resources
|
||||
|
|
|
|||
|
|
@ -20,6 +20,16 @@ struct scaled_font_buffer {
|
|||
float bg_color[4];
|
||||
struct font font;
|
||||
struct scaled_scene_buffer *scaled_buffer;
|
||||
|
||||
/*
|
||||
* The following fields are used only for the titlebar, where
|
||||
* the font buffer can be rendered with a pattern background to
|
||||
* support gradients. In this case, the font buffer is also
|
||||
* padded to a fixed height (with the text centered vertically)
|
||||
* in order to align the pattern with the rest of the titlebar.
|
||||
*/
|
||||
int fixed_height;
|
||||
cairo_pattern_t *bg_pattern; /* overrides bg_color if set */
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -33,6 +43,17 @@ struct scaled_font_buffer {
|
|||
*/
|
||||
struct scaled_font_buffer *scaled_font_buffer_create(struct wlr_scene_tree *parent);
|
||||
|
||||
/**
|
||||
* Create an auto scaling font buffer for titlebar text.
|
||||
* The font buffer takes a new reference to bg_pattern.
|
||||
*
|
||||
* @param fixed_height Fixed height for the buffer (logical pixels)
|
||||
* @param bg_pattern Background pattern (solid color or gradient)
|
||||
*/
|
||||
struct scaled_font_buffer *
|
||||
scaled_font_buffer_create_for_titlebar(struct wlr_scene_tree *parent,
|
||||
int fixed_height, cairo_pattern_t *bg_pattern);
|
||||
|
||||
/**
|
||||
* Update an existing auto scaling font buffer.
|
||||
*
|
||||
|
|
@ -44,6 +65,9 @@ struct scaled_font_buffer *scaled_font_buffer_create(struct wlr_scene_tree *pare
|
|||
* - truncated = buffer->width == max_width
|
||||
* - text_changed = strcmp(old_text, new_text)
|
||||
* - font and color the same
|
||||
*
|
||||
* bg_color is ignored for font buffers created with
|
||||
* scaled_font_buffer_create_for_titlebar().
|
||||
*/
|
||||
void scaled_font_buffer_update(struct scaled_font_buffer *self, const char *text,
|
||||
int max_width, struct font *font, const float *color,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue