aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--teensy/teensy_ui.c37
-rw-r--r--teensy/teensy_ui.h30
2 files changed, 35 insertions, 32 deletions
diff --git a/teensy/teensy_ui.c b/teensy/teensy_ui.c
index bdb4e91..58005b8 100644
--- a/teensy/teensy_ui.c
+++ b/teensy/teensy_ui.c
@@ -46,7 +46,6 @@ typedef struct {
} Layout;
typedef struct {
- const char *title;
Cmd *cmds;
Layout *layout;
Layout layout_stack[MAX_LAYOUTS];
@@ -223,10 +222,9 @@ bool is_hovered(ty_Recti rect)
}
static
-Window create_window(const char *title, ty_Recti rect, uint32_t flags)
+Window create_window(ty_Recti rect, uint32_t flags)
{
Window win = {};
- win.title = title;
win.rect = rect;
win.flags = flags;
win.cmds = ty_list_create();
@@ -244,11 +242,7 @@ void tyui_init(const ty_Font *font)
root_flags |= TYUI_WIN_NOMOVE;
root_flags |= TYUI_WIN_INVISIBLE;
- uictx.root = create_window(
- "__ROOT__",
- ty_recti(0, 0, 256, 256),
- root_flags
- );
+ uictx.root = create_window(ty_recti(0, 0, 256, 256), root_flags);
uictx.style = default_style;
uictx.font = font;
@@ -299,14 +293,10 @@ void tyui_pop_layout(void)
advance_layout();
}
-bool tyui_begin_window_ex(
- const char *title,
- ty_Recti rect,
- tyui_Id *id,
- uint32_t flags,
- bool *closed_ptr
-) {
- assert(id);
+bool tyui_begin_window_ex(tyui_Window_Conf conf, bool *closed_ptr)
+{
+ assert(conf.title);
+ assert(conf.id);
bool closed = false;
@@ -321,13 +311,13 @@ bool tyui_begin_window_ex(
if (closed)
return !closed;
- if (*id == 0) {
- *id = ++uictx.window_count;
- uictx.windows[*id - 1] = create_window(title, rect, flags);
- uictx.window_order[uictx.window_count - 1] = *id;
+ if (*conf.id == 0) {
+ *conf.id = ++uictx.window_count;
+ uictx.windows[*conf.id - 1] = create_window(conf.rect, conf.flags);
+ uictx.window_order[uictx.window_count - 1] = *conf.id;
}
- Window *win = &uictx.windows[*id - 1];
+ Window *win = &uictx.windows[*conf.id - 1];
uictx.active = win;
win->layout = win->layout_stack;
@@ -356,6 +346,9 @@ bool tyui_begin_window_ex(
if (win->has_lmb && hovering_resizer) {
win->rect.w += md.x;
win->rect.h += md.y;
+
+ win->rect.w = ty_max(win->rect.w, conf.min_size.x);
+ win->rect.h = ty_max(win->rect.h, conf.min_size.y);
}
}
@@ -380,7 +373,7 @@ bool tyui_begin_window_ex(
clip_cmd(TY_CLIP_NONE);
rect_cmd(title_rect, uictx.style.win_title);
- text_cmd(win->title, ty_recti_shrink(title_rect, 1), TYUI_ALIGN_LEFT);
+ text_cmd(conf.title, ty_recti_shrink(title_rect, 1), TYUI_ALIGN_LEFT);
ty_Recti body_rect = win->rect;
body_rect.y += title_bar_height();
diff --git a/teensy/teensy_ui.h b/teensy/teensy_ui.h
index 6230aff..65722ac 100644
--- a/teensy/teensy_ui.h
+++ b/teensy/teensy_ui.h
@@ -5,14 +5,22 @@
#include "teensy.h"
#define TYUI_MAX_LAYOUT_SIZE (16)
+#define TYUI_DEFAULT_MIN_WINDOW_SIZE (ty_vec2i(32, 32))
#define TYUI_WIN_NORESIZE (1 << 0)
#define TYUI_WIN_NOCLOSE (1 << 1)
#define TYUI_WIN_NOMOVE (1 << 2)
#define TYUI_WIN_INVISIBLE (1 << 3)
-#define tyui_begin_window(title, rect, id) \
- tyui_begin_window_ex(title, rect, id, 0, NULL)
+#define tyui_begin_window(_title, _rect, _id) \
+ tyui_begin_window_ex((tyui_Window_Conf){ \
+ .title = _title, \
+ .rect = _rect, \
+ .min_size = TYUI_DEFAULT_MIN_WINDOW_SIZE, \
+ .id = _id, \
+ .flags = 0, \
+ }, NULL)
+
#define tyui_text(...) tyui_text_ex(TYUI_ALIGN_LEFT, __VA_ARGS__)
#define tyui_slider(min, max, value_ptr) \
tyui_slider_ex(min, max, value_ptr, true, TYUI_ALIGN_CENTER)
@@ -26,6 +34,8 @@ enum {
TYUI_ALIGN_CENTER,
};
+typedef uint8_t tyui_Id;
+
typedef struct {
ty_Color fg_normal;
ty_Color bg_normal;
@@ -45,7 +55,13 @@ typedef struct {
const char *slider_fmt;
} tyui_Style;
-typedef uint8_t tyui_Id;
+typedef struct {
+ const char *title;
+ ty_Recti rect;
+ ty_Vec2i min_size;
+ tyui_Id *id;
+ uint32_t flags;
+} tyui_Window_Conf;
void tyui_init(const ty_Font *font);
void tyui_deinit(void);
@@ -53,13 +69,7 @@ void tyui_deinit(void);
void tyui_push_layout(const float *column_widths);
void tyui_pop_layout(void);
-bool tyui_begin_window_ex(
- const char *title,
- ty_Recti rect,
- tyui_Id *id,
- uint32_t flags,
- bool *closed
-);
+bool tyui_begin_window_ex(tyui_Window_Conf conf, bool *closed_ptr);
void tyui_end_window(void);
bool tyui_button(const char *text);