Updated GUI library
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "../render/2d.h"
|
||||
#include "../lib/text.h"
|
||||
#include "../lib/event.h"
|
||||
#include "../lib/array.h"
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +23,7 @@ struct Gui_Input
|
||||
bool mouse_released_this_frame;
|
||||
s64 text_cursor_move;
|
||||
char text[32];
|
||||
s32 scroll_move;
|
||||
|
||||
v2 absolute_pointer_position_last_frame;
|
||||
};
|
||||
@@ -58,6 +60,13 @@ struct Gui_Style
|
||||
f32 window_corner_radius;
|
||||
v4 window_titlebar_color;
|
||||
v4 window_titlebar_color_inactive;
|
||||
|
||||
f32 scrollbar_size;
|
||||
f32 scrollbar_corner_radius;
|
||||
f32 scrollbar_inner_bar_size;
|
||||
f32 scrollbar_inner_bar_corner_radius;
|
||||
v4 scrollbar_color;
|
||||
v4 scrollbar_inner_bar_color;
|
||||
};
|
||||
|
||||
struct Gui_Window
|
||||
@@ -94,16 +103,15 @@ struct Gui_Context
|
||||
u64 text_length;
|
||||
|
||||
// Windows
|
||||
Gui_Window *windows;
|
||||
u32 window_count;
|
||||
u32 window_capacity;
|
||||
Array<Gui_Window> windows;
|
||||
Gui_Window *current_window;
|
||||
r_framebuffer *old_framebuffer;
|
||||
|
||||
// Clipping
|
||||
Array<Rect> clipping;
|
||||
|
||||
// ID
|
||||
Gui_Id *id_stack;
|
||||
u32 id_count;
|
||||
u32 id_capacity;
|
||||
Array<Gui_Id> id_stack;
|
||||
|
||||
Gui_Input input;
|
||||
Gui_Style style;
|
||||
@@ -150,18 +158,20 @@ v2 gui_text_compute_size(const char *text);
|
||||
// Button
|
||||
bool gui_button(Gui_Context *ctx, Rect r, const char *text);
|
||||
bool gui_button(Rect r, const char *text);
|
||||
// @Feature: Buttons with widgets inside
|
||||
|
||||
// Slider
|
||||
bool gui_slider(Gui_Context *ctx, Rect r, f32 min, f32 max, f32 *value);
|
||||
bool gui_slider(Rect r, f32 min, f32 max, f32 *value);
|
||||
bool gui_slider_range(Gui_Context *ctx, Rect r, f32 min, f32 max, f32 *value);
|
||||
bool gui_slider_range(Rect r, f32 min, f32 max, f32 *value);
|
||||
|
||||
bool gui_slider_text(Gui_Context *ctx, Rect r, f32 min, f32 max, f32 *value, const char *text);
|
||||
bool gui_slider_text(Rect r, f32 min, f32 max, f32 *value, const char *text);
|
||||
|
||||
// Checkbox
|
||||
// Option buttons
|
||||
// Combo box
|
||||
// Tooltips
|
||||
bool gui_slider_text(Gui_Context *ctx, Rect r, f32 *ratio, const char *text); // ratio must be between 0 and 1.
|
||||
bool gui_slider_text(Rect r, f32 *ratio, const char *text);
|
||||
|
||||
// @Feature: Checkbox
|
||||
// @Feature: Option buttons
|
||||
// @Feature: Combo box
|
||||
// @Feature: Tooltips
|
||||
|
||||
// Images
|
||||
bool gui_image(Gui_Context *ctx, Rect r, r_texture *texture);
|
||||
@@ -178,13 +188,38 @@ void gui_panel(Gui_Context *ctx, Rect r);
|
||||
void gui_panel(Rect r);
|
||||
|
||||
// Windows
|
||||
struct Gui_Titlebar_State
|
||||
{
|
||||
v2 move;
|
||||
v2 anchor_point;
|
||||
bool close;
|
||||
};
|
||||
|
||||
struct Gui_Window_Titlebar_State
|
||||
{
|
||||
Rect inner_r;
|
||||
Gui_Titlebar_State titlebar;
|
||||
};
|
||||
|
||||
bool gui_window_start(Gui_Context *ctx, Rect r, Gui_Id id); // You have to provide some kind of unique id to identify windows
|
||||
bool gui_window_start(Rect r, Gui_Id id);
|
||||
bool gui_window_with_titlebar_start(Gui_Context *ctx, Rect r, const char *title, Gui_Window_Titlebar_State *state);
|
||||
bool gui_window_with_titlebar_start(Rect r, const char *title, Gui_Window_Titlebar_State *state);
|
||||
void gui_window_end(Gui_Context *ctx);
|
||||
void gui_window_end();
|
||||
|
||||
bool gui_window_titlebar(Gui_Context *ctx, Rect r, const char *title, bool *close, v2 *move);
|
||||
bool gui_window_titlebar(Rect r, const char *title, bool *close, v2 *move);
|
||||
// Standalone titlebar for your custom windows
|
||||
bool gui_window_titlebar(Gui_Context *ctx, Rect r, const char *title, Gui_Titlebar_State *state);
|
||||
bool gui_window_titlebar(Rect r, const char *title, Gui_Titlebar_State *state);
|
||||
|
||||
|
||||
// @Feature: Panel
|
||||
// If you want to change which zone is displayed, change position in displayed_r. size will always be computed from r after removing the scrollbar size
|
||||
bool gui_scrollable_area_start(Gui_Context *ctx, Rect r, v2 area_size, Rect *displayed_r);
|
||||
bool gui_scrollable_area_start(Rect r, v2 area_size, Rect *displayed_r);
|
||||
void gui_scrollable_area_end(Gui_Context *ctx);
|
||||
void gui_scrollable_area_end();
|
||||
|
||||
|
||||
Gui_Window *gui_window_by_id(Gui_Context *ctx, Rect r, Gui_Id id); // Rect r might be needed for creation
|
||||
void gui_window_update_rect(Gui_Context *ctx, Gui_Window *window, Rect r);
|
||||
@@ -199,4 +234,9 @@ Gui_Id gui_id_from_pointer(Gui_Context *ctx, const void* ptr);
|
||||
void gui_id_stack_push(Gui_Context *ctx, Gui_Id id);
|
||||
void gui_id_stack_pop(Gui_Context *ctx);
|
||||
|
||||
// Clipping
|
||||
void gui_clip_start(Gui_Context *ctx, Rect r);
|
||||
void gui_clip_end(Gui_Context *ctx);
|
||||
bool gui_is_clipped(Gui_Context *ctx, Rect r); // Returns true only if completely clipped
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user