Remove code for connecting noodles
This commit is contained in:
parent
8501eb787e
commit
4610561eff
@ -7,6 +7,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define MAX_UI_ELEMENTS 8192
|
#define MAX_UI_ELEMENTS 8192
|
||||||
|
#define RESERVED_UI_SLOT 0
|
||||||
|
#define UI_ELEM_START_INDEX 1
|
||||||
|
|
||||||
#define BUTTON_WIDTH 100
|
#define BUTTON_WIDTH 100
|
||||||
#define BUTTON_HEIGHT 40
|
#define BUTTON_HEIGHT 40
|
||||||
@ -28,7 +30,10 @@ enum ui_elem_type {
|
|||||||
|
|
||||||
struct ui_elem {
|
struct ui_elem {
|
||||||
u64 id;
|
u64 id;
|
||||||
rect rect;
|
union {
|
||||||
|
rect rec;
|
||||||
|
line ln;
|
||||||
|
};
|
||||||
ui_elem_type type;
|
ui_elem_type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
40
src/ui.c
40
src/ui.c
@ -73,7 +73,7 @@ bool ui_button(const window *wnd, ui_ctx *ctx, rect rec,
|
|||||||
u64 id = get_id(ctx);
|
u64 id = get_id(ctx);
|
||||||
ctx->elements[id] = (ui_elem){
|
ctx->elements[id] = (ui_elem){
|
||||||
.id = id,
|
.id = id,
|
||||||
.rect = rec,
|
.rec = rec,
|
||||||
.type = UI_ELEM_BUTTON,
|
.type = UI_ELEM_BUTTON,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ ui_node_elem ui_node(const window *wnd, ui_ctx *ctx, ui_node_elem node,
|
|||||||
u64 id = get_id(ctx);
|
u64 id = get_id(ctx);
|
||||||
ctx->elements[id] = (ui_elem){
|
ctx->elements[id] = (ui_elem){
|
||||||
.id = id,
|
.id = id,
|
||||||
.rect = node.rec,
|
.rec = node.rec,
|
||||||
.type = UI_ELEM_NODE,
|
.type = UI_ELEM_NODE,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ ui_node_elem ui_node(const window *wnd, ui_ctx *ctx, ui_node_elem node,
|
|||||||
node.rec.topleft.y += ctx->rel_y;
|
node.rec.topleft.y += ctx->rel_y;
|
||||||
|
|
||||||
for (u64 i = 0; i < node.inputs; ++i) {
|
for (u64 i = 0; i < node.inputs; ++i) {
|
||||||
if (node.noodles[i].connected_node == 0) {
|
if (node.noodles[i].connected_node == RESERVED_UI_SLOT) {
|
||||||
node.noodles[i].noodle.p0.x += ctx->rel_x;
|
node.noodles[i].noodle.p0.x += ctx->rel_x;
|
||||||
node.noodles[i].noodle.p0.y += ctx->rel_y;
|
node.noodles[i].noodle.p0.y += ctx->rel_y;
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ internal ui_noodle_elem ui_noodle(const window *wnd, ui_ctx *ctx,
|
|||||||
u64 id = get_id(ctx);
|
u64 id = get_id(ctx);
|
||||||
ctx->elements[id] = (ui_elem){
|
ctx->elements[id] = (ui_elem){
|
||||||
.id = id,
|
.id = id,
|
||||||
.rect = (rect){0},
|
.ln = noodle.noodle,
|
||||||
.type = UI_ELEM_NOODLE,
|
.type = UI_ELEM_NOODLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -290,37 +290,9 @@ internal ui_noodle_elem ui_noodle(const window *wnd, ui_ctx *ctx,
|
|||||||
if (ctx->mouse_up) {
|
if (ctx->mouse_up) {
|
||||||
if (ctx->hovered == ctx->active && ctx->hovered == id) {
|
if (ctx->hovered == ctx->active && ctx->hovered == id) {
|
||||||
ctx->hovered = ctx->active = -1;
|
ctx->hovered = ctx->active = -1;
|
||||||
|
|
||||||
for (u64 i = 0; i < ctx->count; ++i) {
|
|
||||||
const ui_elem *elem = &(ctx->elements[i]);
|
|
||||||
|
|
||||||
if (elem->type != UI_ELEM_NODE || elem->id == parent_id) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!aabb(elem->rect, ctx->mouse_x, ctx->mouse_y)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
point p0 = (point){
|
|
||||||
.x = elem->rect.topleft.x + elem->rect.w / 2,
|
|
||||||
.y = elem->rect.topleft.y + elem->rect.h / 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
line updated_noodle = (line){
|
|
||||||
.p0 = p0,
|
|
||||||
.p1 = noodle.noodle.p1,
|
|
||||||
};
|
|
||||||
return (ui_noodle_elem){
|
|
||||||
.noodle = updated_noodle,
|
|
||||||
.connected_node = i,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
noodle.connected_node = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (noodle.connected_node > 0) {
|
if (noodle.connected_node > RESERVED_UI_SLOT) {
|
||||||
return noodle;
|
return noodle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +313,7 @@ internal ui_noodle_elem ui_noodle(const window *wnd, ui_ctx *ctx,
|
|||||||
return noodle;
|
return noodle;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rect *node = &(ctx->elements[parent_id].rect);
|
const rect *node = &(ctx->elements[parent_id].rec);
|
||||||
if (!aabb(bounding_box, ctx->mouse_x, ctx->mouse_y) ||
|
if (!aabb(bounding_box, ctx->mouse_x, ctx->mouse_y) ||
|
||||||
aabb(*node, ctx->mouse_x, ctx->mouse_y)) {
|
aabb(*node, ctx->mouse_x, ctx->mouse_y)) {
|
||||||
return noodle;
|
return noodle;
|
||||||
|
Loading…
Reference in New Issue
Block a user