Add modals!
This commit is contained in:
@@ -14,6 +14,27 @@
|
||||
|
||||
#define UI_WIDGET_MAX_DROPDOWN_ITEMS 32
|
||||
#define UI_WIDGET_MAX_TEXT_INPUTS 16
|
||||
#define UI_WIDGET_MAX_WINDOWS 16
|
||||
|
||||
struct UI_ModalState {
|
||||
B32 active;
|
||||
uint32_t id; // Hash of the modal's string ID
|
||||
S32 result; // Button index pressed, -1 = pending
|
||||
};
|
||||
|
||||
struct UI_WindowSlot {
|
||||
uint32_t id; // Hash of the window's string ID (0 = unused)
|
||||
Vec2F32 position;
|
||||
Vec2F32 size;
|
||||
B32 open;
|
||||
int16_t z_order;
|
||||
};
|
||||
|
||||
struct UI_DragState {
|
||||
uint32_t dragging_id; // Window ID currently being dragged (0 = none)
|
||||
Vec2F32 drag_anchor; // Mouse position when drag started
|
||||
Vec2F32 pos_anchor; // Window position when drag started
|
||||
};
|
||||
|
||||
struct UI_WidgetState {
|
||||
// Text input focus
|
||||
@@ -38,6 +59,15 @@ struct UI_WidgetState {
|
||||
|
||||
// Click detection
|
||||
B32 mouse_clicked; // true on the frame mouse transitions from up->down
|
||||
|
||||
// Modal state
|
||||
UI_ModalState modal;
|
||||
|
||||
// Window state
|
||||
UI_WindowSlot windows[UI_WIDGET_MAX_WINDOWS];
|
||||
S32 window_count;
|
||||
int16_t next_z;
|
||||
UI_DragState drag;
|
||||
};
|
||||
|
||||
extern UI_WidgetState g_wstate;
|
||||
@@ -76,3 +106,16 @@ B32 ui_text_input(const char *id, char *buf, S32 buf_size);
|
||||
// Dropdown / combo box. Sets *selected to chosen index. Returns true if changed.
|
||||
// options is an array of label strings, count is the number of options.
|
||||
B32 ui_dropdown(const char *id, const char **options, S32 count, S32 *selected);
|
||||
|
||||
// Modal dialog. Returns button index pressed (0-based), -1 if pending, -2 if Escape dismissed.
|
||||
// Call every frame while active — it draws the overlay and dialog box.
|
||||
S32 ui_modal(const char *id, const char *title, const char *message,
|
||||
const char **buttons, S32 button_count);
|
||||
B32 ui_modal_is_active();
|
||||
|
||||
// Draggable floating window. content_fn is called inside the window body each frame.
|
||||
// *open is set to 0 when the close button is clicked. Returns true while window is open.
|
||||
typedef void (*UI_WindowContentFn)(void *user_data);
|
||||
B32 ui_window(const char *id, const char *title, B32 *open,
|
||||
Vec2F32 initial_pos, Vec2F32 initial_size,
|
||||
UI_WindowContentFn content_fn, void *user_data);
|
||||
|
||||
Reference in New Issue
Block a user