aboutsummaryrefslogtreecommitdiff
path: root/teensy
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-26 16:52:48 -0400
committeriamcheeseman <[email protected]>2026-05-26 16:52:48 -0400
commit9d18177b5cf6488d9591b069e441b0a6b2b9592a (patch)
tree338f395a4ff906443bec68ce873e515be3ce2dc5 /teensy
parent9de6584a9327c7cb1c64f9064d21ef9c1012590e (diff)
add window flag functionality
Diffstat (limited to 'teensy')
-rw-r--r--teensy/teensy_ui.c83
-rw-r--r--teensy/teensy_ui.h17
2 files changed, 68 insertions, 32 deletions
diff --git a/teensy/teensy_ui.c b/teensy/teensy_ui.c
index 374d2bf..f518431 100644
--- a/teensy/teensy_ui.c
+++ b/teensy/teensy_ui.c
@@ -214,6 +214,18 @@ bool is_hovered(ty_Recti rect)
}
static
+ty_Recti win_rect(Window *win)
+{
+ ty_Recti rect = win->rect;
+ if (!(win->flags & TYUI_WIN_NOTITLE)) {
+ rect.y += tyui.style.title_bar_height;
+ rect.h -= tyui.style.title_bar_height;
+ }
+
+ return rect;
+}
+
+static
Window create_window(ty_Recti rect, uint32_t flags)
{
Window win = {0};
@@ -247,7 +259,8 @@ void tyui_init(const ty_Font *font)
};
uint32_t root_flags = 0;
- root_flags |= TYUI_WIN_NORESIZE;
+ root_flags |= TYUI_WIN_NORESIZEX;
+ root_flags |= TYUI_WIN_NORESIZEY;
root_flags |= TYUI_WIN_NOCLOSE;
root_flags |= TYUI_WIN_NOMOVE;
root_flags |= TYUI_WIN_INVISIBLE;
@@ -335,33 +348,43 @@ bool tyui_begin_window_ex(tyui_Window_Conf conf, bool *closed_ptr)
tyui.active = win;
win->layout = win->layout_stack;
- if (win->flags & TYUI_WIN_INVISIBLE)
- goto done;
-
ty_Vec2i mouse_pos = ty_mouse_pos();
ty_Vec2i md = mouse_delta();
mouse_pos.x -= md.x;
mouse_pos.y -= md.y;
- bool hovering_resizer = false;
+ bool resizing_x = false;
+ bool resizing_y = false;
// Grabbing resizer?
{
+ ty_Vec2i win_start = ty_recti_start(win->rect);
ty_Vec2i win_end = ty_recti_end(win->rect);
- ty_Recti resize_rect = ty_recti(
- win_end.x - 20, win_end.y - 20 + TEXT_HEIGHT,
- 20, 20
+
+ ty_Recti resize_rect_right = ty_recti(
+ win_end.x - 20, win_start.y,
+ 20, win->rect.h
);
- hovering_resizer =
- ty_pointi_in_recti(mouse_pos, resize_rect) ||
- ty_pointi_in_recti(ty_mouse_pos(), resize_rect);
+ ty_Recti resize_rect_bottom = ty_recti(
+ win_start.x, win_end.y - 20 + TEXT_HEIGHT,
+ win->rect.w, 20
+ );
- if (win->lmb_down && hovering_resizer) {
- win->rect.w += md.x;
- win->rect.h += md.y;
+ resizing_x =
+ ty_pointi_in_recti(mouse_pos, resize_rect_right) &&
+ (win->flags & TYUI_WIN_NORESIZEX) == 0;
+ resizing_y =
+ ty_pointi_in_recti(mouse_pos, resize_rect_bottom) &&
+ (win->flags & TYUI_WIN_NORESIZEY) == 0;
+ if (win->lmb_down && resizing_x) {
+ win->rect.w += md.x;
win->rect.w = ty_max(win->rect.w, conf.min_size.x);
+ }
+
+ if (win->lmb_down && resizing_y) {
+ win->rect.h += md.y;
win->rect.h = ty_max(win->rect.h, conf.min_size.y);
}
}
@@ -372,10 +395,10 @@ bool tyui_begin_window_ex(tyui_Window_Conf conf, bool *closed_ptr)
// Grabbing title bar?
{
if (
- win->lmb_down &&
+ win->lmb_down &&
+ (win->flags & TYUI_WIN_NOMOVE) == 0 &&
(ty_pointi_in_recti(mouse_pos, title_rect) ||
- ty_pointi_in_recti(ty_mouse_pos(), title_rect))
- ) {
+ ty_pointi_in_recti(ty_mouse_pos(), title_rect))) {
win->rect.x += md.x;
win->rect.y += md.y;
@@ -389,18 +412,22 @@ bool tyui_begin_window_ex(tyui_Window_Conf conf, bool *closed_ptr)
rect_cmd(title_rect, tyui.style.win_title);
text_cmd(conf.title, ty_recti_shrink(title_rect, 1), TYUI_ALIGN_LEFT);
- ty_Recti body_rect = win->rect;
- body_rect.y += tyui.style.title_bar_height;
- body_rect.h -= tyui.style.title_bar_height;
+ if (win->flags & TYUI_WIN_INVISIBLE)
+ goto skip_invisible;
+
+ ty_Recti body_rect = win_rect(win);
rect_cmd(body_rect, tyui.style.win_border);
rect_cmd(ty_recti_shrink(body_rect, 1), tyui.style.win_bg);
- if (hovering_resizer) {
+ if (resizing_x) {
ty_Recti right_bar = ty_recti(
win->rect.x + win->rect.w - 1, 0,
1, win->rect.y + win->rect.h
);
rect_cmd(right_bar, tyui.style.win_title);
+ }
+
+ if (resizing_y) {
ty_Recti bot_bar = ty_recti(
0, win->rect.y + win->rect.h - 1,
win->rect.x + win->rect.w, 1
@@ -408,10 +435,13 @@ bool tyui_begin_window_ex(tyui_Window_Conf conf, bool *closed_ptr)
rect_cmd(bot_bar, tyui.style.win_title);
}
+skip_invisible:
+
tyui_push_layout((float[]){-1, 0});
- layout()->total_height = tyui.style.title_bar_height + tyui.style.padding;
+ layout()->total_height = tyui.style.padding;
+ if ((win->flags & TYUI_WIN_NOTITLE) == 0)
+ layout()->total_height += tyui.style.title_bar_height;
-done:
return !closed;
}
@@ -616,11 +646,14 @@ void focus_window(tyui_Id win_id)
if (idx < 0)
ty_log_err("uh oh");
+ Window *win = &tyui.windows[win_id - 1];
+ win->focused = true;
+ if (win->flags & TYUI_WIN_ALWAYS_BELOW)
+ return;
+
for (int i = idx; i < tyui.window_count - 1; i++)
tyui.window_order[i] = tyui.window_order[i + 1];
tyui.window_order[tyui.window_count - 1] = win_id;
-
- tyui.windows[win_id - 1].focused = true;
}
static
diff --git a/teensy/teensy_ui.h b/teensy/teensy_ui.h
index abcf291..c1081d4 100644
--- a/teensy/teensy_ui.h
+++ b/teensy/teensy_ui.h
@@ -7,19 +7,22 @@
#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_WIN_NORESIZEX (1 << 0)
+#define TYUI_WIN_NORESIZEY (1 << 1)
+#define TYUI_WIN_NOCLOSE (1 << 2)
+#define TYUI_WIN_NOMOVE (1 << 3)
+#define TYUI_WIN_NOTITLE (1 << 4)
+#define TYUI_WIN_INVISIBLE (1 << 5)
+#define TYUI_WIN_ALWAYS_BELOW (1 << 6)
// Marks the beginning of a window, with sane defaults.
-#define tyui_begin_window(_title, _rect, _id) \
+#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, \
+ .min_size = TYUI_DEFAULT_MIN_WINDOW_SIZE, \
+ __VA_ARGS__ \
}, NULL)
// Displays left-aligned, formatted text.