improve terms

This commit is contained in:
hippoz 2023-09-01 19:22:11 +03:00
parent e659e6f3e2
commit d3d12b6e08
Signed by: hippoz
GPG key ID: 56C4E02A85F2FBED
8 changed files with 53 additions and 56 deletions

View file

@ -55,7 +55,7 @@ int background_node_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
case UI_EVENT_PRESSED: /* through */ case UI_EVENT_PRESSED: /* through */
case UI_EVENT_UNPRESSED: { case UI_EVENT_UNPRESSED: {
if (n->update_on_status) { if (n->update_on_status) {
window_invalidate_node(node->window, node); window_invalidate_region_node(node->window, node);
} }
break; break;
} }

View file

@ -71,6 +71,41 @@ int app_handle(struct UINode *node, void *data, int event_type, size_t d, void *
sidebar->rect.w = 200; sidebar->rect.w = 200;
dispatcher_new(sidebar, UI_EVENT_TIMER_END, SIDEBAR_ANIAMTE, state, app_handle); dispatcher_new(sidebar, UI_EVENT_TIMER_END, SIDEBAR_ANIAMTE, state, app_handle);
background_node_new(sidebar, UIZinc800, 0); background_node_new(sidebar, UIZinc800, 0);
UINode *buttons = NULL;
{
buttons = node_new(sidebar, "buttons");
buttons->width_policy = UI_SIZE_POLICY_GROW;
buttons->height_policy = UI_SIZE_POLICY_COMPUTED;
box_layout_new(buttons, UI_DIRECTION_VERTICAL);
for (int i = 0; i < 5000; i++) {
UINode *button_row = node_new(buttons, "button_row");
button_row->width_policy = UI_SIZE_POLICY_GROW;
UIBoxLayoutNode *layout = box_layout_new(button_row, UI_DIRECTION_HORIZONTAL);
layout->gap = 6;
for (int j = 0; j < 3; j++) {
UINode *button = node_new(button_row, "button");
button->width_policy = UI_SIZE_POLICY_GROW;
button->height_policy = UI_SIZE_POLICY_STATIC;
button->rect.w = 48;
button->rect.h = 48;
button->flags |= UI_NODE_CONSUMES_HITS;
UIBoxLayoutNode *button_layout = box_layout_new(button, UI_DIRECTION_HORIZONTAL);
button_layout->justify_primary = UI_BOX_LAYOUT_JUSTIFY_CENTER;
button_layout->justify_secondary = UI_BOX_LAYOUT_JUSTIFY_CENTER;
state_background_node_new(button, UIPurple600, UIPurple700, UIPurple800, 6.0);
UINode *text_container = node_new(button, "text_container");
text_node_new(text_container, state->font, UINeutral50, "+");
dispatcher_new(button, UI_EVENT_UNPRESSED, INCREMENT_COUNT, state, app_handle);
}
}
}
scrollable_new(sidebar, buttons);
state->sidebar_node = sidebar; state->sidebar_node = sidebar;
} }
@ -128,44 +163,6 @@ int app_handle(struct UINode *node, void *data, int event_type, size_t d, void *
text_input->text_node->node.height_policy = UI_SIZE_POLICY_GROW; text_input->text_node->node.height_policy = UI_SIZE_POLICY_GROW;
} }
/* a bunch of buttons */
{
UINode *scroll_container = node_new(node, "buttons_scroll_container");
scroll_container->width_policy = UI_SIZE_POLICY_GROW;
scroll_container->height_policy = UI_SIZE_POLICY_GROW;
UIScrollableNode *scroll = scrollable_new(scroll_container, NULL);
UINode *buttons = node_new(scroll_container, "buttons");
buttons->width_policy = UI_SIZE_POLICY_GROW;
buttons->height_policy = UI_SIZE_POLICY_COMPUTED;
scroll->target = buttons;
box_layout_new(buttons, UI_DIRECTION_VERTICAL);
for (int i = 0; i < 5000; i++) {
UINode *button_row = node_new(buttons, "button_row");
button_row->width_policy = UI_SIZE_POLICY_GROW;
UIBoxLayoutNode *layout = box_layout_new(button_row, UI_DIRECTION_HORIZONTAL);
layout->gap = 6;
for (int j = 0; j < 3; j++) {
UINode *button = node_new(button_row, "button");
button->width_policy = UI_SIZE_POLICY_GROW;
button->height_policy = UI_SIZE_POLICY_STATIC;
button->rect.w = 48;
button->rect.h = 48;
button->flags |= UI_NODE_CONSUMES_HITS;
UIBoxLayoutNode *button_layout = box_layout_new(button, UI_DIRECTION_HORIZONTAL);
button_layout->justify_primary = UI_BOX_LAYOUT_JUSTIFY_CENTER;
button_layout->justify_secondary = UI_BOX_LAYOUT_JUSTIFY_CENTER;
state_background_node_new(button, UIPurple600, UIPurple700, UIPurple800, 6.0);
UINode *text_container = node_new(button, "text_container");
text_node_new(text_container, state->font, UINeutral50, "+");
dispatcher_new(button, UI_EVENT_UNPRESSED, INCREMENT_COUNT, state, app_handle);
}
}
}
break; break;
} }
case SIDEBAR_BEGIN_ANIMATE: { case SIDEBAR_BEGIN_ANIMATE: {
@ -186,7 +183,7 @@ int app_handle(struct UINode *node, void *data, int event_type, size_t d, void *
if (state->sidebar_animate_time_ms >= state->sidebar_animate_duration_ms) { if (state->sidebar_animate_time_ms >= state->sidebar_animate_duration_ms) {
state->sidebar_node->rect.w = state->sidebar_animate_target_w; state->sidebar_node->rect.w = state->sidebar_animate_target_w;
} }
node_request_relayout(state->sidebar_node); node_update(state->sidebar_node);
if (state->sidebar_node->rect.w == state->sidebar_animate_target_w) { if (state->sidebar_node->rect.w == state->sidebar_animate_target_w) {
state->sidebar_animate_time_ms = 0; state->sidebar_animate_time_ms = 0;
return 0; return 0;
@ -208,7 +205,7 @@ int app_handle(struct UINode *node, void *data, int event_type, size_t d, void *
state->count = d; state->count = d;
snprintf(state->counter_text, sizeof(state->counter_text), "%d", state->count); snprintf(state->counter_text, sizeof(state->counter_text), "%d", state->count);
text_node_set_text(state->counter_text_node, state->counter_text); text_node_set_text(state->counter_text_node, state->counter_text);
node_request_relayout((UINode*)state->counter_text_node); node_update((UINode*)state->counter_text_node);
break; break;
} }
} }

View file

@ -5,7 +5,7 @@
#include "rect.h" #include "rect.h"
typedef struct UIWindow UIWindow; typedef struct UIWindow UIWindow;
int window_invalidate_node(UIWindow *window, UINode *node); int window_invalidate_region_node(UIWindow *window, UINode *node);
static inline uint32_t hash_ui_event(enum UIEvent ev, int count) static inline uint32_t hash_ui_event(enum UIEvent ev, int count)
{ {
@ -260,7 +260,7 @@ void node_dump(UINode *node, int depth)
} }
} }
void node_request_relayout(UINode *node) void node_update(UINode *node)
{ {
UINode *current = NULL; UINode *current = NULL;
for (current = node; current->parent && current->width_policy != UI_SIZE_POLICY_STATIC && current->height_policy != UI_SIZE_POLICY_STATIC; current = current->parent) { for (current = node; current->parent && current->width_policy != UI_SIZE_POLICY_STATIC && current->height_policy != UI_SIZE_POLICY_STATIC; current = current->parent) {
@ -268,6 +268,6 @@ void node_request_relayout(UINode *node)
} }
if (current) { if (current) {
node_dispatch(current, UI_EVENT_RELAYOUT, 0, NULL); node_dispatch(current, UI_EVENT_RELAYOUT, 0, NULL);
window_invalidate_node(current->window, current); window_invalidate_region_node(current->window, current);
} }
} }

View file

@ -107,7 +107,7 @@ void node_repaint(UINode *node, UIRect *rect, bool do_group, double window_rel_x
UINode *node_attach(UINode *parent, UINode *node); UINode *node_attach(UINode *parent, UINode *node);
UINode *node_new(UINode *parent, const char *text); UINode *node_new(UINode *parent, const char *text);
void node_dump(UINode *node, int depth); void node_dump(UINode *node, int depth);
void node_request_relayout(UINode *node); void node_update(UINode *node);
void node_notify_subscribe(UINode *node, UINode *target, enum UIEvent *events); void node_notify_subscribe(UINode *node, UINode *target, enum UIEvent *events);
#endif // _UI__NODE_H #endif // _UI__NODE_H

View file

@ -52,7 +52,7 @@ int scrollable_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
} }
target->rect.x = n->x_scroll ? -n->x_scroll : 0; target->rect.x = n->x_scroll ? -n->x_scroll : 0;
target->rect.y = n->y_scroll ? -n->y_scroll : 0; target->rect.y = n->y_scroll ? -n->y_scroll : 0;
window_invalidate_node(node->window, node); window_invalidate_region_node(node->window, node);
break; break;
} }
case UI_EVENT_RELAYOUT: { case UI_EVENT_RELAYOUT: {

View file

@ -86,7 +86,7 @@ int text_input_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
text_node_set_text(n->text_node, 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_update(&n->text_node->node);
} }
return 1; return 1;
@ -94,14 +94,14 @@ int text_input_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
case UI_EVENT_PRESSED: { case UI_EVENT_PRESSED: {
if (n->text_node) { if (n->text_node) {
n->text_node->caret_index = n->text_cursor_index; n->text_node->caret_index = n->text_cursor_index;
node_request_relayout(&n->text_node->node); node_update(&n->text_node->node);
} }
break; break;
} }
case UI_EVENT_UNPRESSED: { case UI_EVENT_UNPRESSED: {
if (n->text_node) { if (n->text_node) {
n->text_node->caret_index = -1; n->text_node->caret_index = -1;
node_request_relayout(&n->text_node->node); node_update(&n->text_node->node);
} }
break; break;
} }

View file

@ -27,7 +27,7 @@ static int window_init_core_xkb_keyboard(UIWindow *window);
static void window_keyboard_process_event(UIWindow *window, UIWindowXKBKeyboard *kb, xcb_generic_event_t *gevent); static void window_keyboard_process_event(UIWindow *window, UIWindowXKBKeyboard *kb, xcb_generic_event_t *gevent);
static void window_keyboard_deinit(UIWindowXKBKeyboard *kb); static void window_keyboard_deinit(UIWindowXKBKeyboard *kb);
int window_invalidate_node(UIWindow *window, UINode *node) int window_invalidate_region_node(UIWindow *window, UINode *node)
{ {
if (node->flags & UI_NODE_COMPONENT) { if (node->flags & UI_NODE_COMPONENT) {
if (!node->parent) { if (!node->parent) {
@ -153,12 +153,12 @@ done:
return window; return window;
} }
bool window_flush_invalidated(UIWindow *window) bool window_flush_invalidated_region(UIWindow *window)
{ {
if (ui_rect_null(&window->invalid_region)) { if (ui_rect_null(&window->invalid_region)) {
return false; return false;
} }
begin_clock("Flush invalidated widgets"); begin_clock("Flush invalidated region");
cairo_push_group(window->drw); cairo_push_group(window->drw);
node_repaint(window->root, &window->invalid_region, true, 0, 0); node_repaint(window->root, &window->invalid_region, true, 0, 0);
@ -410,7 +410,7 @@ static void window_process_xcb_event(UIWindow *window, xcb_generic_event_t *even
xcb_expose_event_t *ev = (xcb_expose_event_t*)event; xcb_expose_event_t *ev = (xcb_expose_event_t*)event;
UIRect region = { ev->x, ev->y, ev->width, ev->height }; UIRect region = { ev->x, ev->y, ev->width, ev->height };
window->invalid_region = ui_rect_united(&window->invalid_region, &region); window->invalid_region = ui_rect_united(&window->invalid_region, &region);
window_invalidate_node(window, window->root); window_invalidate_region_node(window, window->root);
end_clock(); end_clock();
break; break;
} }
@ -426,7 +426,7 @@ static void window_process_xcb_event(UIWindow *window, xcb_generic_event_t *even
window->root->rect.w = ev->width; window->root->rect.w = ev->width;
window->root->rect.h = ev->height; window->root->rect.h = ev->height;
node_dispatch(window->root, UI_EVENT_RELAYOUT, 0, NULL); node_dispatch(window->root, UI_EVENT_RELAYOUT, 0, NULL);
window_invalidate_node(window, window->root); window_invalidate_region_node(window, window->root);
#ifdef _UI_DEBUG #ifdef _UI_DEBUG
//node_dump(window->root, 0); //node_dump(window->root, 0);
#endif #endif
@ -652,7 +652,7 @@ int window_turn(UIWindow *window)
} }
} }
if (window_flush_invalidated(window)) { if (window_flush_invalidated_region(window)) {
begin_clock("Flush painting results to XCB"); begin_clock("Flush painting results to XCB");
xcb_flush(window->_xcb_connection); xcb_flush(window->_xcb_connection);
end_clock(); end_clock();

View file

@ -42,7 +42,7 @@ typedef struct UIWindow {
UIWindowXKBKeyboard *xkb_core_keyboard; UIWindowXKBKeyboard *xkb_core_keyboard;
} UIWindow; } UIWindow;
int window_invalidate_node(UIWindow *window, UINode *node); int window_invalidate_region_node(UIWindow *window, UINode *node);
void window_free(UIWindow *window); void window_free(UIWindow *window);
UIWindow *window_new(int width, int height); UIWindow *window_new(int width, int height);
bool window_flush_invalidated(UIWindow *window); bool window_flush_invalidated(UIWindow *window);