enlarge scrollbars when focused

c3
Alessandro Mauri 6 days ago
parent f7985f8c7f
commit ca691d1294
  1. 9
      src/ugui_div.c3
  2. 4
      src/ugui_slider.c3

@ -11,13 +11,11 @@ struct ElemDiv {
struct scroll_x { struct scroll_x {
bool enabled; bool enabled;
bool on; bool on;
bool focus;
float value; float value;
} }
struct scroll_y { struct scroll_y {
bool enabled; bool enabled;
bool on; bool on;
bool focus;
float value; float value;
} }
Rect children_bounds; // current frame children bounds Rect children_bounds; // current frame children bounds
@ -99,8 +97,11 @@ fn void! Ctx.div_end(&ctx)
// vertical overflow // vertical overflow
elem.div.scroll_y.on = cbc.y > bc.y && elem.div.scroll_y.enabled; 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; Id hsid = ctx.gen_id("div_scrollbar_horizontal")!;
short hdim = elem.div.scroll_x.on ? (elem.div.scroll_x.focus ? SCROLLBAR_DIM*3 : SCROLLBAR_DIM) : 0; 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) { if (elem.div.scroll_y.on) {
Rect vslider = { Rect vslider = {

@ -54,7 +54,7 @@ fn ElemEvents! Ctx.slider_hor(&ctx,
Point m = ctx.input.mouse.pos; Point m = ctx.input.mouse.pos;
elem.events = ctx.get_elem_events(elem); 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); *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.slider.handle.x = calc_slider(elem.bounds.x, elem.bounds.w-hw, *value);
elem.events.update = true; elem.events.update = true;
@ -117,7 +117,7 @@ fn ElemEvents! Ctx.slider_ver(&ctx,
Point m = ctx.input.mouse.pos; Point m = ctx.input.mouse.pos;
elem.events = ctx.get_elem_events(elem); 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); *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.slider.handle.y = calc_slider(elem.bounds.y, elem.bounds.h-hh, *value);
elem.events.update = true; elem.events.update = true;

Loading…
Cancel
Save