From ca691d1294f6df3046abfd07fb9c344d97c81e2a Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Fri, 20 Dec 2024 02:17:41 +0100 Subject: [PATCH] enlarge scrollbars when focused --- src/ugui_div.c3 | 9 +++++---- src/ugui_slider.c3 | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ugui_div.c3 b/src/ugui_div.c3 index a59d37d..709c8eb 100644 --- a/src/ugui_div.c3 +++ b/src/ugui_div.c3 @@ -11,13 +11,11 @@ struct ElemDiv { struct scroll_x { bool enabled; bool on; - bool focus; float value; } struct scroll_y { bool enabled; bool on; - bool focus; float value; } Rect children_bounds; // current frame children bounds @@ -99,8 +97,11 @@ fn void! Ctx.div_end(&ctx) // vertical overflow elem.div.scroll_y.on = cbc.y > bc.y && elem.div.scroll_y.enabled; - short wdim = elem.div.scroll_y.on ? (elem.div.scroll_y.focus ? SCROLLBAR_DIM*3 : SCROLLBAR_DIM) : 0; - short hdim = elem.div.scroll_x.on ? (elem.div.scroll_x.focus ? SCROLLBAR_DIM*3 : SCROLLBAR_DIM) : 0; + Id hsid = ctx.gen_id("div_scrollbar_horizontal")!; + Id vsid = ctx.gen_id("div_scrollbar_vertical")!; + + short wdim = elem.div.scroll_y.on ? (ctx.focus_id == vsid ? SCROLLBAR_DIM*3 : SCROLLBAR_DIM) : 0; + short hdim = elem.div.scroll_x.on ? (ctx.focus_id == hsid ? SCROLLBAR_DIM*3 : SCROLLBAR_DIM) : 0; if (elem.div.scroll_y.on) { Rect vslider = { diff --git a/src/ugui_slider.c3 b/src/ugui_slider.c3 index e078103..4641322 100644 --- a/src/ugui_slider.c3 +++ b/src/ugui_slider.c3 @@ -54,7 +54,7 @@ fn ElemEvents! Ctx.slider_hor(&ctx, Point m = ctx.input.mouse.pos; elem.events = ctx.get_elem_events(elem); - if (ctx.elem_focus(elem) && elem.events.mouse_hold) { + if (ctx.elem_focus(elem) && ctx.is_mouse_down(BTN_LEFT)) { *value = calc_value(elem.bounds.x, m.x, elem.bounds.w, hw); elem.slider.handle.x = calc_slider(elem.bounds.x, elem.bounds.w-hw, *value); elem.events.update = true; @@ -117,7 +117,7 @@ fn ElemEvents! Ctx.slider_ver(&ctx, Point m = ctx.input.mouse.pos; elem.events = ctx.get_elem_events(elem); - if (ctx.elem_focus(elem) && elem.events.mouse_hold) { + if (ctx.elem_focus(elem) && ctx.is_mouse_down(BTN_LEFT)) { *value = calc_value(elem.bounds.y, m.y, elem.bounds.h, hh); elem.slider.handle.y = calc_slider(elem.bounds.y, elem.bounds.h-hh, *value); elem.events.update = true;