improve terms
This commit is contained in:
parent
e659e6f3e2
commit
d3d12b6e08
8 changed files with 53 additions and 56 deletions
|
@ -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_UNPRESSED: {
|
||||
if (n->update_on_status) {
|
||||
window_invalidate_node(node->window, node);
|
||||
window_invalidate_region_node(node->window, node);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
77
src/main.c
77
src/main.c
|
@ -71,6 +71,41 @@ int app_handle(struct UINode *node, void *data, int event_type, size_t d, void *
|
|||
sidebar->rect.w = 200;
|
||||
dispatcher_new(sidebar, UI_EVENT_TIMER_END, SIDEBAR_ANIAMTE, state, app_handle);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
state->sidebar_animate_time_ms = 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;
|
||||
snprintf(state->counter_text, sizeof(state->counter_text), "%d", state->count);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "rect.h"
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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;
|
||||
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) {
|
||||
node_dispatch(current, UI_EVENT_RELAYOUT, 0, NULL);
|
||||
window_invalidate_node(current->window, current);
|
||||
window_invalidate_region_node(current->window, current);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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_new(UINode *parent, const char *text);
|
||||
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);
|
||||
|
||||
#endif // _UI__NODE_H
|
||||
|
|
|
@ -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.y = n->y_scroll ? -n->y_scroll : 0;
|
||||
window_invalidate_node(node->window, node);
|
||||
window_invalidate_region_node(node->window, node);
|
||||
break;
|
||||
}
|
||||
case UI_EVENT_RELAYOUT: {
|
||||
|
|
|
@ -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);
|
||||
n->text_node->caret_index = n->text_cursor_index;
|
||||
n->text_node->wrap = true;
|
||||
node_request_relayout(&n->text_node->node);
|
||||
node_update(&n->text_node->node);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -94,14 +94,14 @@ int text_input_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
|
|||
case UI_EVENT_PRESSED: {
|
||||
if (n->text_node) {
|
||||
n->text_node->caret_index = n->text_cursor_index;
|
||||
node_request_relayout(&n->text_node->node);
|
||||
node_update(&n->text_node->node);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UI_EVENT_UNPRESSED: {
|
||||
if (n->text_node) {
|
||||
n->text_node->caret_index = -1;
|
||||
node_request_relayout(&n->text_node->node);
|
||||
node_update(&n->text_node->node);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
12
src/window.c
12
src/window.c
|
@ -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_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->parent) {
|
||||
|
@ -153,12 +153,12 @@ done:
|
|||
return window;
|
||||
}
|
||||
|
||||
bool window_flush_invalidated(UIWindow *window)
|
||||
bool window_flush_invalidated_region(UIWindow *window)
|
||||
{
|
||||
if (ui_rect_null(&window->invalid_region)) {
|
||||
return false;
|
||||
}
|
||||
begin_clock("Flush invalidated widgets");
|
||||
begin_clock("Flush invalidated region");
|
||||
|
||||
cairo_push_group(window->drw);
|
||||
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;
|
||||
UIRect region = { ev->x, ev->y, ev->width, ev->height };
|
||||
window->invalid_region = ui_rect_united(&window->invalid_region, ®ion);
|
||||
window_invalidate_node(window, window->root);
|
||||
window_invalidate_region_node(window, window->root);
|
||||
end_clock();
|
||||
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.h = ev->height;
|
||||
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
|
||||
//node_dump(window->root, 0);
|
||||
#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");
|
||||
xcb_flush(window->_xcb_connection);
|
||||
end_clock();
|
||||
|
|
|
@ -42,7 +42,7 @@ typedef struct UIWindow {
|
|||
UIWindowXKBKeyboard *xkb_core_keyboard;
|
||||
} UIWindow;
|
||||
|
||||
int window_invalidate_node(UIWindow *window, UINode *node);
|
||||
int window_invalidate_region_node(UIWindow *window, UINode *node);
|
||||
void window_free(UIWindow *window);
|
||||
UIWindow *window_new(int width, int height);
|
||||
bool window_flush_invalidated(UIWindow *window);
|
||||
|
|
Loading…
Reference in a new issue