diff options
Diffstat (limited to 'teensy/teensy_ui.c')
| -rw-r--r-- | teensy/teensy_ui.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/teensy/teensy_ui.c b/teensy/teensy_ui.c index 54b846e..c9d37ea 100644 --- a/teensy/teensy_ui.c +++ b/teensy/teensy_ui.c @@ -61,6 +61,7 @@ typedef struct { bool lmb_pressed; bool rmb_pressed; int scroll; + int content_height; } Window; typedef struct { @@ -442,18 +443,20 @@ bool tyui_begin_window_ex(tyui_Window_Conf conf, bool *closed_ptr) skip_invisible: tyui.active = win; - clip_cmd(win_content(win)); + ty_Recti content = win_content(win); + clip_cmd(content); // TODO: Maybe make a distinction between focused and the top-most hovered // window? By forcing the user to focus the window, they must click on it // beforehand, which is bad UX. if (tyui.focused_win == win && is_hovered(win->rect)) { - win->scroll += ty_platform_get_scroll() * TYUI_SCROLL; - win->scroll = ty_min(win->scroll, 0); + win->scroll -= ty_platform_get_scroll() * TYUI_SCROLL; + int max_scroll = ty_max(win->content_height - content.h, 0); + win->scroll = ty_clamp(win->scroll, 0, max_scroll); } tyui_push_layout((float[]){-1, 0}); - layout()->total_height = tyui.style.padding + win->scroll; + layout()->total_height = tyui.style.padding - win->scroll; if ((win->flags & TYUI_WIN_NOTITLE) == 0) layout()->total_height += tyui.style.title_bar_height; @@ -467,6 +470,8 @@ void tyui_end_window(void) return; } + window()->content_height = window()->layout_stack[0].total_height + window()->scroll; + tyui.active = &tyui.root; clip_cmd(window()->rect); |
