fix text node extent invalidation
This commit is contained in:
parent
f4fcca122b
commit
ae80e1776f
4 changed files with 17 additions and 15 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue