#ifndef _UI__NODE_H #define _UI__NODE_H #include #include #include "rect.h" #include enum UIEvent { UI_EVENT_REPAINT, UI_EVENT_RELAYOUT, UI_EVENT_GET_WIDTH, UI_EVENT_GET_HEIGHT, UI_EVENT_HOVERED, UI_EVENT_UNHOVERED, UI_EVENT_PRESSED, UI_EVENT_UNPRESSED, UI_EVENT_DESTROY, UI_EVENT_TIMER_END, UI_EVENT_BUTTON_LEFT_UPDATE, // d == 1 if pressed, d == 0 if released UI_EVENT_BUTTON_RIGHT_UPDATE, // d == 1 if pressed, d == 0 if released UI_EVENT_SCROLL, // p (double*) = delta UI_EVENT_KEY_DOWN, // d (unsigned int) = keycode, p (struct xkb_state*) = xkb state }; enum UISizePolicy { UI_SIZE_POLICY_DYNAMIC, UI_SIZE_POLICY_GROW, UI_SIZE_POLICY_FIXED, UI_SIZE_POLICY_STATIC }; enum UIDirection { UI_DIRECTION_HORIZONTAL, UI_DIRECTION_VERTICAL }; #define UI_NODE_COMPONENT (1 << 0) #define UI_NODE_RETAINS_PRESS (1 << 1) typedef struct UINode { const char *text; UIRect rect; double window_rel_x, window_rel_y; struct UINode *parent; struct UINode **nodes; struct UIWindow *window; cairo_t *drw; int nodes_count, nodes_capacity; uint32_t flags; enum UISizePolicy width_policy; enum UISizePolicy height_policy; int (*handle)(struct UINode *node, enum UIEvent ev, size_t d, void *p); int (*handle_proto)(struct UINode *node, enum UIEvent ev, size_t d, void *p); } UINode; int node_dispatch(UINode *node, enum UIEvent ev, size_t d, void *p); UINode *node_by_point(UINode *root, double x, double y); void node_init(UINode *node); void node_free(UINode *node); void node_repaint(UINode *node, UIRect *rect, bool do_group, double window_rel_x, double window_rel_y); 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); #endif // _UI__NODE_H