Compare commits

...

3 commits

3 changed files with 31 additions and 6 deletions

View file

@ -116,6 +116,29 @@ int app_handle(struct UINode *node, void *data, int event_type, size_t d, void *
text_input->text_node = text_node_new(&text_input->node, state->font, UINeutral50, NULL);
}
/* 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_DYNAMIC;
scroll->target = buttons;
box_layout_new(buttons, UI_DIRECTION_VERTICAL);
for (int i = 0; i < 100; i++) {
UINode *button = node_new(buttons, "button");
state_background_node_new(button, UIPurple600, UIPurple700, UIPurple800, 6.0);
text_node_new(button, state->font, UINeutral50, "button");
dispatcher_new(button, UI_EVENT_UNPRESSED, INCREMENT_COUNT, state, app_handle);
button->width_policy = UI_SIZE_POLICY_GROW;
}
}
break;
}
case SIDEBAR_BEGIN_ANIMATE: {

View file

@ -48,10 +48,8 @@ UINode *node_by_point(UINode *root, double x, double y)
{
for (int i = 0; i < root->nodes_count; i++) {
UINode *node = root->nodes[i];
double local_x = x - node->window_rel_x;
double local_y = y - node->window_rel_y;
if (ui_rect_contains_point(&node->rect, local_x, local_y) && !(node->flags & UI_NODE_DISABLED)) {
return node_by_point(node, local_x, local_y);
if (ui_rect_contains_point(&node->rect, x - node->window_rel_x, y - node->window_rel_y) && !(node->flags & UI_NODE_DISABLED)) {
return node_by_point(node, x, y);
}
}
return root;

View file

@ -51,13 +51,17 @@ int scrollable_handle(UINode *node, enum UIEvent ev, size_t d, void *p)
if (target->width_policy == UI_SIZE_POLICY_DYNAMIC) {
node_dispatch(target, UI_EVENT_GET_WIDTH, 0, &w);
target->rect.w = w;
} else if (target->width_policy == UI_SIZE_POLICY_GROW) {
target->rect.w = node->parent->rect.w;
}
if (target->height_policy == UI_SIZE_POLICY_DYNAMIC) {
node_dispatch(target, UI_EVENT_GET_HEIGHT, 0, &h);
target->rect.h = h;
} else if (target->height_policy == UI_SIZE_POLICY_GROW) {
target->rect.h = node->parent->rect.h;
}
target->rect.x = -n->x_scroll;
target->rect.y = -n->y_scroll;
target->rect.x = n->x_scroll ? -n->x_scroll : 0;
target->rect.y = n->y_scroll ? -n->y_scroll : 0;
node_dispatch(target, UI_EVENT_RELAYOUT, 0, NULL);
break;
}