From c29b8d0730547af5928e059fa9828876f63c4625 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Fri, 22 May 2026 12:10:48 -0400 Subject: tyui: move window parameters to a struct additionally adds a minimum window size --- teensy/teensy_ui.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'teensy/teensy_ui.c') 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(); -- cgit v1.3-2-g0d8e