update single header distribution
This commit is contained in:
parent
ce685968b2
commit
023c876641
1 changed files with 41 additions and 16 deletions
53
libraven.h
53
libraven.h
|
@ -639,13 +639,20 @@ int dispatcher_handle(UINode *node, enum UIEvent ev, size_t d, void *p);
|
||||||
|
|
||||||
// #include "node.h" // -- commented because of single-header bundle
|
// #include "node.h" // -- commented because of single-header bundle
|
||||||
|
|
||||||
|
enum UIBoxLayoutJustify {
|
||||||
|
UI_BOX_LAYOUT_JUSTIFY_START,
|
||||||
|
UI_BOX_LAYOUT_JUSTIFY_CENTER
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct UIBoxLayoutNode {
|
typedef struct UIBoxLayoutNode {
|
||||||
UINode node;
|
UINode node;
|
||||||
enum UIDirection direction;
|
enum UIDirection direction;
|
||||||
|
enum UIBoxLayoutJustify justify_secondary_dimension;
|
||||||
double margin_top, margin_left, margin_bottom, margin_right, gap;
|
double margin_top, margin_left, margin_bottom, margin_right, gap;
|
||||||
} UIBoxLayoutNode;
|
} UIBoxLayoutNode;
|
||||||
|
|
||||||
UIBoxLayoutNode *box_layout_new(UINode *parent, enum UIDirection direction);
|
UIBoxLayoutNode *box_layout_new(UINode *parent, enum UIDirection direction);
|
||||||
|
void box_layout_set_margins(UIBoxLayoutNode *layout, double margin);
|
||||||
int box_layout_handle(UINode *component, enum UIEvent ev, size_t d, void *p);
|
int box_layout_handle(UINode *component, enum UIEvent ev, size_t d, void *p);
|
||||||
|
|
||||||
#endif // _UI__BOX_LAYOUT_NODE_H
|
#endif // _UI__BOX_LAYOUT_NODE_H
|
||||||
|
@ -667,7 +674,7 @@ typedef struct UITextNode {
|
||||||
UINode node;
|
UINode node;
|
||||||
PangoFontDescription *desc;
|
PangoFontDescription *desc;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
char *pending_text;
|
char *_pending_text;
|
||||||
UIRGBA color;
|
UIRGBA color;
|
||||||
ssize_t caret_index;
|
ssize_t caret_index;
|
||||||
UINode *caret_node;
|
UINode *caret_node;
|
||||||
|
@ -675,6 +682,7 @@ typedef struct UITextNode {
|
||||||
} UITextNode;
|
} UITextNode;
|
||||||
|
|
||||||
int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p);
|
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);
|
UITextNode *text_node_new(UINode *parent, PangoFontDescription *desc, UIRGBA color, char *text);
|
||||||
|
|
||||||
#endif // _UI__TEXT_NODE_H
|
#endif // _UI__TEXT_NODE_H
|
||||||
|
@ -2276,7 +2284,11 @@ int box_layout_handle(UINode *component, enum UIEvent ev, size_t d, void *p)
|
||||||
x += gap;
|
x += gap;
|
||||||
}
|
}
|
||||||
current->rect.x = x;
|
current->rect.x = x;
|
||||||
|
if (box_layout_node->justify_secondary_dimension == UI_BOX_LAYOUT_JUSTIFY_CENTER) {
|
||||||
|
current->rect.y = margin_top + (maximum_secondary_position - current->rect.h) / 2;
|
||||||
|
} else {
|
||||||
current->rect.y = y;
|
current->rect.y = y;
|
||||||
|
}
|
||||||
x += current->rect.w;
|
x += current->rect.w;
|
||||||
} else {
|
} else {
|
||||||
if (current->height_policy == UI_SIZE_POLICY_GROW) {
|
if (current->height_policy == UI_SIZE_POLICY_GROW) {
|
||||||
|
@ -2288,7 +2300,11 @@ int box_layout_handle(UINode *component, enum UIEvent ev, size_t d, void *p)
|
||||||
if (current_index) {
|
if (current_index) {
|
||||||
y += gap;
|
y += gap;
|
||||||
}
|
}
|
||||||
|
if (box_layout_node->justify_secondary_dimension == UI_BOX_LAYOUT_JUSTIFY_CENTER) {
|
||||||
|
current->rect.x = margin_left + (maximum_secondary_position - current->rect.w) / 2;
|
||||||
|
} else {
|
||||||
current->rect.x = x;
|
current->rect.x = x;
|
||||||
|
}
|
||||||
current->rect.y = y;
|
current->rect.y = y;
|
||||||
y += current->rect.h;
|
y += current->rect.h;
|
||||||
}
|
}
|
||||||
|
@ -2301,6 +2317,14 @@ int box_layout_handle(UINode *component, enum UIEvent ev, size_t d, void *p)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void box_layout_set_margins(UIBoxLayoutNode *layout, double margin)
|
||||||
|
{
|
||||||
|
layout->margin_top = margin;
|
||||||
|
layout->margin_left = margin;
|
||||||
|
layout->margin_bottom = margin;
|
||||||
|
layout->margin_right = margin;
|
||||||
|
}
|
||||||
|
|
||||||
UIBoxLayoutNode *box_layout_new(UINode *parent, enum UIDirection direction)
|
UIBoxLayoutNode *box_layout_new(UINode *parent, enum UIDirection direction)
|
||||||
{
|
{
|
||||||
UIBoxLayoutNode *n = malloc(sizeof(UIBoxLayoutNode));
|
UIBoxLayoutNode *n = malloc(sizeof(UIBoxLayoutNode));
|
||||||
|
@ -2336,7 +2360,7 @@ UITextNode *text_node_new(UINode *parent, PangoFontDescription *desc, UIRGBA col
|
||||||
UITextNode *n = malloc(sizeof(UITextNode));
|
UITextNode *n = malloc(sizeof(UITextNode));
|
||||||
node_init(&n->node);
|
node_init(&n->node);
|
||||||
n->node.flags = UI_NODE_COMPONENT;
|
n->node.flags = UI_NODE_COMPONENT;
|
||||||
n->pending_text = text;
|
n->_pending_text = text;
|
||||||
n->desc = desc;
|
n->desc = desc;
|
||||||
n->layout = NULL;
|
n->layout = NULL;
|
||||||
n->color = color;
|
n->color = color;
|
||||||
|
@ -2349,6 +2373,12 @@ UITextNode *text_node_new(UINode *parent, PangoFontDescription *desc, UIRGBA col
|
||||||
return n;
|
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)
|
int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
|
||||||
{
|
{
|
||||||
(void)d;
|
(void)d;
|
||||||
|
@ -2360,11 +2390,11 @@ int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
|
||||||
|
|
||||||
UITextNode *n = (UITextNode*)node;
|
UITextNode *n = (UITextNode*)node;
|
||||||
|
|
||||||
if (n->pending_text) {
|
if (n->_pending_text) {
|
||||||
if (n->layout) {
|
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);
|
pango_cairo_update_layout(node->drw, n->layout);
|
||||||
n->pending_text = NULL;
|
n->_pending_text = NULL;
|
||||||
} else {
|
} else {
|
||||||
PangoLayout *layout = pango_cairo_create_layout(n->node.drw);
|
PangoLayout *layout = pango_cairo_create_layout(n->node.drw);
|
||||||
pango_layout_set_font_description(layout, n->desc);
|
pango_layout_set_font_description(layout, n->desc);
|
||||||
|
@ -2373,11 +2403,10 @@ int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
|
||||||
} else {
|
} else {
|
||||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
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->layout = layout;
|
||||||
n->pending_text = NULL;
|
n->_pending_text = NULL;
|
||||||
}
|
}
|
||||||
node->parent->cached_computed_extents = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ev) {
|
switch (ev) {
|
||||||
|
@ -2442,7 +2471,7 @@ int text_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
|
||||||
g_object_unref(n->layout);
|
g_object_unref(n->layout);
|
||||||
}
|
}
|
||||||
n->layout = NULL;
|
n->layout = NULL;
|
||||||
n->pending_text = NULL;
|
n->_pending_text = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -2484,10 +2513,6 @@ int text_input_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
|
||||||
UITextInputNode *n = (UITextInputNode *)node;
|
UITextInputNode *n = (UITextInputNode *)node;
|
||||||
|
|
||||||
switch (ev) {
|
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: {
|
case UI_EVENT_KEY_DOWN: {
|
||||||
xkb_keycode_t keycode = d;
|
xkb_keycode_t keycode = d;
|
||||||
struct xkb_state *xkb_state = (struct xkb_state*)p;
|
struct xkb_state *xkb_state = (struct xkb_state*)p;
|
||||||
|
@ -2545,7 +2570,7 @@ int text_input_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n->text_node) {
|
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->caret_index = n->text_cursor_index;
|
||||||
n->text_node->wrap = true;
|
n->text_node->wrap = true;
|
||||||
node_request_relayout(&n->text_node->node);
|
node_request_relayout(&n->text_node->node);
|
||||||
|
|
Loading…
Reference in a new issue