mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
Convert SSD title to scaled font buffer
This commit is contained in:
parent
b25965d03e
commit
05ae654547
3 changed files with 21 additions and 21 deletions
|
|
@ -53,6 +53,7 @@ struct view;
|
|||
struct wl_list;
|
||||
struct wlr_box;
|
||||
struct wlr_scene_tree;
|
||||
struct scaled_font_buffer;
|
||||
|
||||
struct ssd_button {
|
||||
struct view *view;
|
||||
|
|
@ -115,7 +116,7 @@ struct ssd_part {
|
|||
enum ssd_part_type type;
|
||||
|
||||
/* Buffer pointer. May be NULL */
|
||||
struct lab_data_buffer *buffer;
|
||||
struct scaled_font_buffer *buffer;
|
||||
|
||||
/* This part represented in scene graph */
|
||||
struct wlr_scene_node *node;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "labwc.h"
|
||||
#include "ssd.h"
|
||||
#include "node.h"
|
||||
#include "common/font.h"
|
||||
|
||||
/* Internal helpers */
|
||||
static void
|
||||
|
|
@ -165,10 +166,8 @@ ssd_destroy_parts(struct wl_list *list)
|
|||
wlr_scene_node_destroy(part->node);
|
||||
part->node = NULL;
|
||||
}
|
||||
if (part->buffer) {
|
||||
wlr_buffer_drop(&part->buffer->base);
|
||||
part->buffer = NULL;
|
||||
}
|
||||
/* part->buffer will free itself along the scene_buffer node */
|
||||
part->buffer = NULL;
|
||||
if (part->geometry) {
|
||||
free(part->geometry);
|
||||
part->geometry = NULL;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "ssd.h"
|
||||
#include "theme.h"
|
||||
#include "common/font.h"
|
||||
#include "common/scaled_font_buffer.h"
|
||||
#include "common/scene-helpers.h"
|
||||
#include "node.h"
|
||||
|
||||
|
|
@ -156,13 +157,14 @@ ssd_update_title_positions(struct view *view)
|
|||
struct ssd_sub_tree *subtree;
|
||||
FOR_EACH_STATE(view, subtree) {
|
||||
part = ssd_get_part(&subtree->parts, LAB_SSD_PART_TITLE);
|
||||
if (!part) {
|
||||
if (!part || !part->node) {
|
||||
/* view->surface never been mapped */
|
||||
/* Or we somehow failed to allocate a scaled titlebar buffer */
|
||||
continue;
|
||||
}
|
||||
|
||||
buffer_width = part->buffer ? part->buffer->base.width : 0;
|
||||
buffer_height = part->buffer ? part->buffer->base.height : 0;
|
||||
buffer_width = part->buffer ? part->buffer->width : 0;
|
||||
buffer_height = part->buffer ? part->buffer->height : 0;
|
||||
x = BUTTON_WIDTH;
|
||||
y = (theme->title_height - buffer_height) / 2;
|
||||
if (title_bg_width <= 0) {
|
||||
|
|
@ -243,25 +245,23 @@ ssd_update_title(struct view *view)
|
|||
if (!part) {
|
||||
/* Initialize part and wlr_scene_buffer without attaching a buffer */
|
||||
part = add_scene_part(&subtree->parts, LAB_SSD_PART_TITLE);
|
||||
part->node = &wlr_scene_buffer_create(subtree->tree, NULL)->node;
|
||||
part->buffer = scaled_font_buffer_create(subtree->tree);
|
||||
if (part->buffer) {
|
||||
part->node = &part->buffer->scene_buffer->node;
|
||||
} else {
|
||||
wlr_log(WLR_ERROR, "Failed to create title node");
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate and update the lab_data_buffer, drops the old buffer */
|
||||
font_buffer_update(&part->buffer, title_bg_width, title, &font,
|
||||
text_color, 1);
|
||||
if (!part->buffer) {
|
||||
/* This can happen for example by defining a font size of 0 */
|
||||
wlr_log(WLR_ERROR, "Failed to create title buffer");
|
||||
if (part->buffer) {
|
||||
scaled_font_buffer_update(part->buffer,
|
||||
title, title_bg_width, &font, text_color);
|
||||
}
|
||||
|
||||
/* (Re)set the buffer */
|
||||
wlr_scene_buffer_set_buffer(
|
||||
wlr_scene_buffer_from_node(part->node),
|
||||
part->buffer ? &part->buffer->base : NULL);
|
||||
|
||||
/* And finally update the cache */
|
||||
dstate->width = part->buffer ? part->buffer->base.width : 0;
|
||||
dstate->width = part->buffer ? part->buffer->width : 0;
|
||||
dstate->truncated = title_bg_width <= dstate->width;
|
||||
|
||||
} FOR_EACH_END
|
||||
|
||||
if (!title_unchanged) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue