renamed elem.rect to elem.bounds
This commit is contained in:
parent
1cad13e597
commit
8bc38452b3
5 changed files with 36 additions and 36 deletions
|
|
@ -20,20 +20,20 @@ fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size)
|
|||
// if the element is new or the parent was updated then redo layout
|
||||
if (c_elem.flags.is_new || parent.flags.updated) {
|
||||
// 2. Layout
|
||||
c_elem.rect = ctx.position_element(parent, size, true);
|
||||
c_elem.bounds = ctx.position_element(parent, size, true);
|
||||
c_elem.slider.handle = Rect{
|
||||
.x = (short)(c_elem.rect.x + (int)(c_elem.rect.w * c_elem.slider.value)),
|
||||
.y = c_elem.rect.y,
|
||||
.w = (short)(c_elem.rect.w * 0.25),
|
||||
.h = c_elem.rect.h,
|
||||
.x = (short)(c_elem.bounds.x + (int)(c_elem.bounds.w * c_elem.slider.value)),
|
||||
.y = c_elem.bounds.y,
|
||||
.w = (short)(c_elem.bounds.w * 0.25),
|
||||
.h = c_elem.bounds.h,
|
||||
};
|
||||
}
|
||||
|
||||
c_elem.events = ctx.get_elem_events(c_elem);
|
||||
if (parent.flags.has_focus && c_elem.events.mouse_hover) {
|
||||
if (point_in_rect(ctx.input.mouse.pos, c_elem.slider.handle) && c_elem.events.mouse_hold) {
|
||||
short x = (short)clamp(ctx.input.mouse.pos.x - c_elem.slider.handle.w/2, c_elem.rect.x, c_elem.rect.x + c_elem.rect.w - c_elem.slider.handle.w);
|
||||
float v = (float)(c_elem.slider.handle.x-c_elem.rect.x) / (float)(c_elem.rect.w-c_elem.slider.handle.w);
|
||||
short x = (short)clamp(ctx.input.mouse.pos.x - c_elem.slider.handle.w/2, c_elem.bounds.x, c_elem.bounds.x + c_elem.bounds.w - c_elem.slider.handle.w);
|
||||
float v = (float)(c_elem.slider.handle.x-c_elem.bounds.x) / (float)(c_elem.bounds.w-c_elem.slider.handle.w);
|
||||
c_elem.slider.handle.x = x;
|
||||
c_elem.slider.value = v;
|
||||
c_elem.events.update = true;
|
||||
|
|
@ -47,7 +47,7 @@ fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size)
|
|||
Cmd cmd = {
|
||||
.type = CMD_RECT,
|
||||
.rect = {
|
||||
.rect = c_elem.rect,
|
||||
.rect = c_elem.bounds,
|
||||
.color = bg_color,
|
||||
},
|
||||
};
|
||||
|
|
@ -92,20 +92,20 @@ fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size)
|
|||
// if the element is new or the parent was updated then redo layout
|
||||
if (c_elem.flags.is_new || parent.flags.updated) {
|
||||
// 2. Layout
|
||||
c_elem.rect = ctx.position_element(parent, size, true);
|
||||
c_elem.bounds = ctx.position_element(parent, size, true);
|
||||
c_elem.slider.handle = Rect{
|
||||
.x = c_elem.rect.x,
|
||||
.y = (short)(c_elem.rect.y + (int)(c_elem.rect.h * c_elem.slider.value)),
|
||||
.w = c_elem.rect.w,
|
||||
.h = (short)(c_elem.rect.h * 0.25),
|
||||
.x = c_elem.bounds.x,
|
||||
.y = (short)(c_elem.bounds.y + (int)(c_elem.bounds.h * c_elem.slider.value)),
|
||||
.w = c_elem.bounds.w,
|
||||
.h = (short)(c_elem.bounds.h * 0.25),
|
||||
};
|
||||
}
|
||||
|
||||
c_elem.events = ctx.get_elem_events(c_elem);
|
||||
if (parent.flags.has_focus && c_elem.events.mouse_hover) {
|
||||
if (point_in_rect(ctx.input.mouse.pos, c_elem.slider.handle) && c_elem.events.mouse_hold) {
|
||||
short y = (short)clamp(ctx.input.mouse.pos.y - c_elem.slider.handle.h/2, c_elem.rect.y, c_elem.rect.y + c_elem.rect.h - c_elem.slider.handle.h);
|
||||
float v = (float)(c_elem.slider.handle.y-c_elem.rect.y) / (float)(c_elem.rect.h-c_elem.slider.handle.h);
|
||||
short y = (short)clamp(ctx.input.mouse.pos.y - c_elem.slider.handle.h/2, c_elem.bounds.y, c_elem.bounds.y + c_elem.bounds.h - c_elem.slider.handle.h);
|
||||
float v = (float)(c_elem.slider.handle.y-c_elem.bounds.y) / (float)(c_elem.bounds.h-c_elem.slider.handle.h);
|
||||
c_elem.slider.handle.y = y;
|
||||
c_elem.slider.value = v;
|
||||
c_elem.events.update = true;
|
||||
|
|
@ -119,7 +119,7 @@ fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size)
|
|||
Cmd cmd = {
|
||||
.type = CMD_RECT,
|
||||
.rect = {
|
||||
.rect = c_elem.rect,
|
||||
.rect = c_elem.bounds,
|
||||
.color = bg_color,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue