sway_text_node: allow max width to be fractional

Signed-off-by: Loukas Agorgianitis <loukas@agorgianitis.com>
This commit is contained in:
Loukas Agorgianitis 2025-06-01 17:44:48 +03:00
parent 0c302325e4
commit 8292d15a3a
No known key found for this signature in database
GPG key ID: DDC6FA7D5BB332E6
2 changed files with 6 additions and 6 deletions

View file

@ -4,7 +4,7 @@
struct sway_text_node {
int width;
int max_width;
double max_width;
int height;
int baseline;
bool pango_markup;
@ -21,7 +21,7 @@ void sway_text_node_set_color(struct sway_text_node *node, float color[4]);
void sway_text_node_set_text(struct sway_text_node *node, char *text);
void sway_text_node_set_max_width(struct sway_text_node *node, int max_width);
void sway_text_node_set_max_width(struct sway_text_node *node, double max_width);
void sway_text_node_set_background(struct sway_text_node *node, float background[4]);

View file

@ -56,8 +56,8 @@ struct text_buffer {
struct wl_listener destroy;
};
static int get_text_width(struct sway_text_node *props) {
int width = props->width;
static double get_text_width(struct sway_text_node *props) {
double width = props->width;
if (props->max_width >= 0) {
width = MIN(width, props->max_width);
}
@ -139,7 +139,7 @@ static void render_backing_buffer(struct text_buffer *buffer) {
pixman_region64f_t opaque;
pixman_region64f_init(&opaque);
if (background[3] == 1) {
pixman_region64f_union_rect(&opaque, &opaque, 0, 0,
pixman_region64f_union_rectf(&opaque, &opaque, 0, 0,
get_text_width(&buffer->props), buffer->props.height);
}
wlr_scene_buffer_set_opaque_region(buffer->buffer_node, &opaque);
@ -279,7 +279,7 @@ void sway_text_node_set_text(struct sway_text_node *node, char *text) {
render_backing_buffer(buffer);
}
void sway_text_node_set_max_width(struct sway_text_node *node, int max_width) {
void sway_text_node_set_max_width(struct sway_text_node *node, double max_width) {
struct text_buffer *buffer = wl_container_of(node, buffer, props);
if (max_width == buffer->props.max_width) {
return;