From ae80e1776f1a52a884c5035e815d0da781bb2c0e Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Wed, 24 May 2023 23:00:17 +0300 Subject: [PATCH] fix text node extent invalidation --- src/main.c | 2 +- src/text-input-node.c | 6 +----- src/text-node.c | 21 +++++++++++++-------- src/text-node.h | 3 ++- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main.c b/src/main.c index 74011ff..db56cb9 100644 --- a/src/main.c +++ b/src/main.c @@ -183,7 +183,7 @@ int app_handle(struct UINode *node, void *data, int event_type, size_t d, void * case UPDATE_COUNT: { state->count = d; snprintf(state->counter_text, sizeof(state->counter_text), "%d", state->count); - state->counter_text_node->pending_text = state->counter_text; + text_node_set_text(state->counter_text_node, state->counter_text); node_request_relayout((UINode*)state->counter_text_node); break; } diff --git a/src/text-input-node.c b/src/text-input-node.c index 1b6293d..461c456 100644 --- a/src/text-input-node.c +++ b/src/text-input-node.c @@ -26,10 +26,6 @@ int text_input_handle(UINode *node, enum UIEvent ev, size_t d, void *p) UITextInputNode *n = (UITextInputNode *)node; switch (ev) { - case UI_EVENT_ATTACHED: { - node_notify_subscribe(node->parent, node, (enum UIEvent[]){ UI_EVENT_KEY_DOWN, UI_EVENT_PRESSED, UI_EVENT_UNPRESSED, 0 }); - break; - } case UI_EVENT_KEY_DOWN: { xkb_keycode_t keycode = d; struct xkb_state *xkb_state = (struct xkb_state*)p; @@ -87,7 +83,7 @@ int text_input_handle(UINode *node, enum UIEvent ev, size_t d, void *p) } if (n->text_node) { - n->text_node->pending_text = n->text.data; + text_node_set_text(n->text_node, n->text.data); n->text_node->caret_index = n->text_cursor_index; n->text_node->wrap = true; node_request_relayout(&n->text_node->node); diff --git a/src/text-node.c b/src/text-node.c index 3ec0efe..e1cd663 100644 --- a/src/text-node.c +++ b/src/text-node.c @@ -12,7 +12,7 @@ UITextNode *text_node_new(UINode *parent, PangoFontDescription *desc, UIRGBA col UITextNode *n = malloc(sizeof(UITextNode)); node_init(&n->node); n->node.flags = UI_NODE_COMPONENT; - n->pending_text = text; + n->_pending_text = text; n->desc = desc; n->layout = NULL; n->color = color; @@ -25,6 +25,12 @@ UITextNode *text_node_new(UINode *parent, PangoFontDescription *desc, UIRGBA col return n; } +void text_node_set_text(UITextNode *text_node, char *text) +{ + text_node->_pending_text = text; + text_node->node.cached_computed_extents = false; +} + int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p) { (void)d; @@ -36,11 +42,11 @@ int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p) UITextNode *n = (UITextNode*)node; - if (n->pending_text) { + if (n->_pending_text) { if (n->layout) { - pango_layout_set_text(n->layout, n->pending_text, -1); + pango_layout_set_text(n->layout, n->_pending_text, -1); pango_cairo_update_layout(node->drw, n->layout); - n->pending_text = NULL; + n->_pending_text = NULL; } else { PangoLayout *layout = pango_cairo_create_layout(n->node.drw); pango_layout_set_font_description(layout, n->desc); @@ -49,11 +55,10 @@ int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p) } else { pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); } - pango_layout_set_text(layout, n->pending_text, -1); + pango_layout_set_text(layout, n->_pending_text, -1); n->layout = layout; - n->pending_text = NULL; + n->_pending_text = NULL; } - node->parent->cached_computed_extents = false; } switch (ev) { @@ -118,7 +123,7 @@ int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p) g_object_unref(n->layout); } n->layout = NULL; - n->pending_text = NULL; + n->_pending_text = NULL; break; } default: { diff --git a/src/text-node.h b/src/text-node.h index 89a4019..26d6b39 100644 --- a/src/text-node.h +++ b/src/text-node.h @@ -11,7 +11,7 @@ typedef struct UITextNode { UINode node; PangoFontDescription *desc; PangoLayout *layout; - char *pending_text; + char *_pending_text; UIRGBA color; ssize_t caret_index; UINode *caret_node; @@ -19,6 +19,7 @@ typedef struct UITextNode { } UITextNode; int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p); +void text_node_set_text(UITextNode *text_node, char *text); UITextNode *text_node_new(UINode *parent, PangoFontDescription *desc, UIRGBA color, char *text); #endif // _UI__TEXT_NODE_H