diff --git a/ui.c b/ui.c index 6f8a3c7..d14ce8d 100644 --- a/ui.c +++ b/ui.c @@ -745,12 +745,12 @@ void draw_color_picker_popup(UIConstraints *picker_button_con) { UIConstraints popup_con = default_constraints; set_parent_constraint(&popup_con, picker_button_con); set_x_constraint(&popup_con, 0, UI_CONSTRAINT_FIXED); - set_y_constraint(&popup_con, picker_button_con->height + 20, UI_CONSTRAINT_FIXED); + set_y_constraint(&popup_con, 1.4f, UI_CONSTRAINT_RELATIVE); set_width_constraint(&popup_con, 450, UI_CONSTRAINT_RELATIVE_PIXELS); set_height_constraint(&popup_con, 480, UI_CONSTRAINT_RELATIVE_PIXELS); UiStyle popup_style = { .bg_color = mult_color(COLOR_WHITE, 0.94f), - .border_radius = 8, + .border_radius = popup_con.width * 0.02f, .align = ALIGN_TOP_LEFT, }; draw_quad(&popup_con, popup_style); @@ -782,6 +782,7 @@ void draw_color_picker_popup(UIConstraints *picker_button_con) { }; if (draw_button(&button_con, "Revert", button_style, BUTTON_STATE_ACTIVE)) { zephr_ctx->ui.popup_open = false; + zephr_ctx->ui.popup_parent_hash = 0; } button_style.align = ALIGN_BOTTOM_RIGHT; @@ -792,9 +793,15 @@ void draw_color_picker_popup(UIConstraints *picker_button_con) { if (draw_button(&button_con, "Apply", button_style, BUTTON_STATE_ACTIVE)) { *zephr_ctx->ui.popup_revert_color = selected_color; zephr_ctx->ui.popup_open = false; + zephr_ctx->ui.popup_parent_hash = 0; } - zephr_ctx->ui.popup_rect = (Rect){{popup_con.x, popup_con.y}, {popup_con.width, popup_con.height}}; + Rect rect = { + {popup_con.x, popup_con.y}, + {popup_con.width, popup_con.height}, + }; + + zephr_ctx->ui.popup_rect = rect; } void draw_color_picker_with_location_and_id(u32 id, const char* file, int line, UIConstraints *constraints, Color *color, Alignment align, ButtonState state) { @@ -858,8 +865,12 @@ void draw_color_picker_with_location_and_id(u32 id, const char* file, int line, zephr_ctx->ui.popup_open = true; zephr_ctx->ui.popup_parent_constraints = con; zephr_ctx->ui.popup_revert_color = color; - /* zephr_ctx->ui.popup_rect = (Rect){rect.pos, rect.size}; */ - /* draw_color_picker_overlay(constraints); */ + zephr_ctx->ui.popup_parent_hash = hash; + } + + if (zephr_ctx->ui.popup_parent_hash == hash) { + zephr_ctx->ui.popup_open = true; + zephr_ctx->ui.popup_parent_constraints = con; } /* if (is_hovered && state == BUTTON_STATE_ACTIVE && zephr_ctx->mouse.released && zephr_ctx->mouse.button == ZEPHR_MOUSE_BUTTON_LEFT) { */ diff --git a/ui.h b/ui.h index b63d92c..603ca54 100644 --- a/ui.h +++ b/ui.h @@ -43,6 +43,7 @@ typedef struct Rect { typedef struct UI { bool popup_open; + UiIdHash popup_parent_hash; Rect popup_rect; UIConstraints popup_parent_constraints; Color *popup_revert_color; diff --git a/zephr.c b/zephr.c index c5a53cb..00f46bb 100644 --- a/zephr.c +++ b/zephr.c @@ -853,6 +853,7 @@ bool zephr_should_quit(void) { zephr_ctx->cursor = ZEPHR_CURSOR_ARROW; zephr_ctx->mouse.released = false; + zephr_ctx->mouse.pressed = false; audio_update(); @@ -866,6 +867,7 @@ void zephr_swap_buffers(void) { if (zephr_ctx->ui.popup_open) { draw_color_picker_popup(&zephr_ctx->ui.popup_parent_constraints); } + zephr_ctx->ui.popup_open = false; glXSwapBuffers(x11_display, x11_window); XDefineCursor(x11_display, x11_window, zephr_ctx->cursors[zephr_ctx->cursor]); @@ -1064,10 +1066,6 @@ bool zephr_iter_events(ZephrEvent *event_out) { switch (xev.xbutton.button) { case Button1: event_out->mouse.button = ZEPHR_MOUSE_BUTTON_LEFT; - /* if (!inside_rect(&zephr_ctx->ui.popup_rect, &event_out->mouse.position)) { */ - /* zephr_ctx->ui.popup_open = false; */ - /* zephr_ctx->ui.active_element = 0; */ - /* } */ break; case Button2: event_out->mouse.button = ZEPHR_MOUSE_BUTTON_MIDDLE;