fix text node size handing and add wrapping support
This commit is contained in:
parent
091bb0a57b
commit
7901afc47c
2 changed files with 13 additions and 1 deletions
|
@ -18,6 +18,7 @@ UITextNode *text_node_new(UINode *parent, PangoFontDescription *desc, UIRGBA col
|
|||
n->color = color;
|
||||
n->caret_index = -1;
|
||||
n->caret_node = NULL;
|
||||
n->wrap = false;
|
||||
n->node.text = "text";
|
||||
n->node.handle_proto = text_node_handle;
|
||||
node_attach(parent, (UINode*)n);
|
||||
|
@ -43,7 +44,11 @@ int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
|
|||
} else {
|
||||
PangoLayout *layout = pango_cairo_create_layout(n->node.drw);
|
||||
pango_layout_set_font_description(layout, n->desc);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
if (n->wrap) {
|
||||
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
|
||||
} else {
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
}
|
||||
pango_layout_set_text(layout, n->pending_text, -1);
|
||||
n->layout = layout;
|
||||
n->pending_text = NULL;
|
||||
|
@ -80,6 +85,12 @@ int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
|
|||
if (!n->layout) {
|
||||
break;
|
||||
}
|
||||
if (node->parent->width_policy != UI_SIZE_POLICY_COMPUTED) {
|
||||
pango_layout_set_width(n->layout, pango_units_from_double(node->parent->rect.w));
|
||||
}
|
||||
if (node->parent->height_policy != UI_SIZE_POLICY_COMPUTED) {
|
||||
pango_layout_set_height(n->layout, pango_units_from_double(node->parent->rect.h));
|
||||
}
|
||||
if (n->caret_index >= 0) {
|
||||
if (!n->caret_node) {
|
||||
n->caret_node = node_new(&n->node, "caret");
|
||||
|
|
|
@ -15,6 +15,7 @@ typedef struct UITextNode {
|
|||
UIRGBA color;
|
||||
ssize_t caret_index;
|
||||
UINode *caret_node;
|
||||
bool wrap;
|
||||
} UITextNode;
|
||||
|
||||
int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p);
|
||||
|
|
Loading…
Reference in a new issue