capture box on mouse up
This commit is contained in:
parent
8ae5498ba7
commit
a857b39097
@ -493,7 +493,7 @@
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
typedef i8 b8;
|
||||
typedef u32 b32;
|
||||
typedef i32 b32;
|
||||
#elif IsGpu
|
||||
typedef int i32;
|
||||
typedef int64_t i64;
|
||||
|
||||
@ -4368,10 +4368,12 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
f32 thumb_end = UI_Rect(thumb_key).p1.y;
|
||||
f32 thumb_height = MaxF32(thumb_end - thumb_start, 1);
|
||||
|
||||
f32 wheel_scroll_amount = item_size_px * 2;
|
||||
f32 wheel_scroll_amount = 3 * item_size_px;
|
||||
f32 button_scroll_amount = 20 * item_size_px * frame->dt;
|
||||
f32 scroll_height = MaxF32(lister_height - scissor_height, 1);
|
||||
{
|
||||
i32 wheels = UI_Downs(lister_key, Button_WheelDown) - UI_Downs(lister_key, Button_WheelUp);
|
||||
f32 wheel_scrolls = UI_Downs(lister_key, Button_WheelDown) - UI_Downs(lister_key, Button_WheelUp);
|
||||
f32 button_scrolls = UI_Held(scrollbar_down_key, Button_M1) - UI_Held(scrollbar_up_key, Button_M1);
|
||||
if (UI_Downs(thumb_key, Button_M1))
|
||||
{
|
||||
palette->drag_lister = UI_Rect(lister_key);
|
||||
@ -4389,8 +4391,12 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
f32 drag_scroll_height = (palette->drag_lister.p1.y - palette->drag_lister.p0.y) - (palette->drag_scissor.p1.y - palette->drag_scissor.p0.y);
|
||||
f32 delta_ratio = (frame->screen_cursor.y - palette->drag_cursor.y) / (drag_track_height - drag_thumb_height);
|
||||
palette->scroll = palette->drag_scroll + delta_ratio * drag_scroll_height;
|
||||
palette->target_scroll = palette->scroll;
|
||||
}
|
||||
palette->scroll += wheels * wheel_scroll_amount;
|
||||
palette->target_scroll += wheel_scrolls * wheel_scroll_amount;
|
||||
palette->target_scroll += button_scrolls * button_scroll_amount;
|
||||
palette->target_scroll = ClampF32(palette->target_scroll, 0, scroll_height);
|
||||
palette->scroll = LerpF32(palette->scroll, palette->target_scroll, SaturateF32(20 * frame->dt));
|
||||
palette->scroll = ClampF32(palette->scroll, 0, scroll_height);
|
||||
}
|
||||
|
||||
@ -5207,9 +5213,9 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
{
|
||||
Vec4 col = theme.col.hint;
|
||||
Vec4 bd_col = Zi;
|
||||
col = LerpSrgb(col, theme.col.button_active, UI_Active(scrollbar_key));
|
||||
bd_col = LerpSrgb(bd_col, theme.col.button_hot, UI_Hot(scrollbar_key));
|
||||
bd_col = LerpSrgb(bd_col, theme.col.button_active, UI_Active(scrollbar_key));
|
||||
col = LerpSrgb(col, theme.col.button_active, UI_Active(scrollbar_up_key));
|
||||
bd_col = LerpSrgb(bd_col, theme.col.button_hot, UI_Hot(scrollbar_up_key));
|
||||
bd_col = LerpSrgb(bd_col, theme.col.button_active, UI_Active(scrollbar_up_key));
|
||||
UI_SetNext(ChildAlignment, UI_Region_Center);
|
||||
UI_SetNext(BorderColor, bd_col);
|
||||
UI_SetNext(BorderSize, 1);
|
||||
@ -5237,7 +5243,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_SetNext(Height, UI_Px(new_thumb_height, 1));
|
||||
UI_SetNext(BorderSize, 1);
|
||||
UI_SetNext(BorderColor, bd);
|
||||
UI_SetNext(Rounding, UI_Rgrow(1 * theme.rounding));
|
||||
UI_SetNext(Rounding, UI_Rgrow(0.75 * theme.rounding));
|
||||
UI_SetNext(FloatingPos, VEC2(0, new_thumb_start));
|
||||
UI_SetNext(Anchor, UI_Region_Center);
|
||||
UI_SetNext(Anchor, UI_Region_Top);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
//~ Command table
|
||||
|
||||
#define V_CmdsTableXList(X) \
|
||||
X(nop, NOP, V_CmdDescFlag_HideFromPalette, V_HOTKEY(0), ) \
|
||||
X(nop, NOP, V_CmdDescFlag_HideFromPalette, V_HOTKEY( 0 ), ) \
|
||||
X(exit_program, Exit Program, V_CmdDescFlag_HideFromPalette, V_HOTKEY( Button_Escape ) ) \
|
||||
X(toggle_palette, Toggle Command Palette, V_CmdDescFlag_HideFromPalette, V_HOTKEY( Button_E, .ctrl = 1 ), V_HOTKEY( Button_P, .ctrl = 1, .shift = 1 ), ) \
|
||||
X(zoom_in, Zoom In, V_CmdDescFlag_HideFromPalette, V_HOTKEY( Button_WheelUp ), ) \
|
||||
@ -217,14 +217,7 @@ Struct(V_Palette)
|
||||
f32 show;
|
||||
|
||||
f32 scroll;
|
||||
// f32 scroll_begin;
|
||||
|
||||
|
||||
|
||||
|
||||
// f32 drag_thumb_offset;
|
||||
// f32 drag_scrollbar_container_start;
|
||||
// f32 drag_scrollbar_container_end;
|
||||
f32 target_scroll;
|
||||
|
||||
Rng2 drag_lister;
|
||||
Rng2 drag_scissor;
|
||||
@ -233,8 +226,6 @@ Struct(V_Palette)
|
||||
Vec2 drag_cursor;
|
||||
f32 drag_scroll;
|
||||
|
||||
|
||||
|
||||
V_TextboxState search_state;
|
||||
};
|
||||
|
||||
@ -274,27 +265,15 @@ Struct(V_ZoneChunk)
|
||||
Struct(V_ZoneTrack)
|
||||
{
|
||||
V_ZoneTrack *next;
|
||||
|
||||
V_Zone *root_zone;
|
||||
u64 id;
|
||||
|
||||
// Sample collection
|
||||
ProfTrack *prof_track;
|
||||
u64 next_collection_sample_seq;
|
||||
V_Zone *open_zone;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Struct(V_Profiler)
|
||||
{
|
||||
Vec2 graph_dims;
|
||||
|
||||
@ -620,6 +620,8 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags)
|
||||
UI_DebugBreak(box, UI_DebugBreakFlag_CheckCursorHover);
|
||||
//- Reset state
|
||||
{
|
||||
box->child_mouse_hovered = 0;
|
||||
box->child_mouse_captured = 0;
|
||||
box->mouse_hovered = 0;
|
||||
box->mouse_captured = 0;
|
||||
}
|
||||
@ -657,6 +659,15 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags)
|
||||
}
|
||||
}
|
||||
|
||||
if (top_hovered_box)
|
||||
{
|
||||
top_hovered_box->mouse_hovered = 1;
|
||||
}
|
||||
if (top_active_box)
|
||||
{
|
||||
top_active_box->mouse_captured = 1;
|
||||
}
|
||||
|
||||
//- Reset input state
|
||||
for (u32 button_idx = 0; button_idx < countof(frame->input.buttons); ++button_idx)
|
||||
{
|
||||
@ -689,18 +700,21 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags)
|
||||
++frame->input.buttons[Button_M1].downs;
|
||||
frame->input.buttons[Button_M1].held = 1;
|
||||
top_active_box = top_hovered_box;
|
||||
top_active_box->mouse_captured = 1;
|
||||
}
|
||||
else if (cev->button == Button_M2)
|
||||
{
|
||||
++frame->input.buttons[Button_M2].downs;
|
||||
frame->input.buttons[Button_M2].held = 1;
|
||||
top_active_box = top_hovered_box;
|
||||
top_active_box->mouse_captured = 1;
|
||||
}
|
||||
else if (cev->button == Button_M3)
|
||||
{
|
||||
++frame->input.buttons[Button_M3].downs;
|
||||
frame->input.buttons[Button_M3].held = 1;
|
||||
top_active_box = top_hovered_box;
|
||||
top_active_box->mouse_captured = 1;
|
||||
}
|
||||
else if (cev->button == Button_WheelUp)
|
||||
{
|
||||
@ -785,28 +799,6 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags)
|
||||
}
|
||||
|
||||
//- Update mouse capture tree
|
||||
if (top_hovered_box)
|
||||
{
|
||||
top_hovered_box->mouse_hovered = 1;
|
||||
for (UI_Box *parent = top_hovered_box->parent; parent; parent = parent->parent)
|
||||
{
|
||||
if (parent->desc.flags & UI_BoxFlag_CaptureThroughChildren)
|
||||
{
|
||||
parent->mouse_hovered = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (top_active_box)
|
||||
{
|
||||
top_active_box->mouse_captured = 1;
|
||||
for (UI_Box *parent = top_active_box->parent; parent; parent = parent->parent)
|
||||
{
|
||||
if (parent->desc.flags & UI_BoxFlag_CaptureThroughChildren)
|
||||
{
|
||||
parent->mouse_captured = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
top_hot_box = top_active_box ? top_active_box : top_hovered_box;
|
||||
|
||||
//- Update box feedback
|
||||
@ -816,9 +808,24 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags)
|
||||
for (u64 pre_index = UI.boxes_count; pre_index-- > 0;)
|
||||
{
|
||||
UI_Box *box = prev_frame->boxes_pre[pre_index];
|
||||
UI_Box *parent = box->parent;
|
||||
UI_Feedback *feedback = &box->feedback;
|
||||
UI_DebugBreak(box, UI_DebugBreakFlag_BuildFeedback);
|
||||
|
||||
// Propagate capture state upwards
|
||||
box->child_mouse_hovered = box->mouse_hovered || box->child_mouse_hovered;
|
||||
box->child_mouse_captured = box->mouse_captured || box->child_mouse_captured;
|
||||
if (parent)
|
||||
{
|
||||
parent->child_mouse_hovered = box->child_mouse_hovered || parent->child_mouse_hovered;
|
||||
parent->child_mouse_captured = box->child_mouse_captured || parent->child_mouse_captured;
|
||||
}
|
||||
if (box->desc.flags & UI_BoxFlag_CaptureThroughChildren)
|
||||
{
|
||||
box->mouse_hovered = box->child_mouse_hovered || box->mouse_captured;
|
||||
box->mouse_captured = box->child_mouse_captured || box->mouse_hovered;
|
||||
}
|
||||
|
||||
feedback->active_absolute = box->mouse_captured;
|
||||
feedback->hot_absolute = feedback->active_absolute || (top_active_box == 0 && box->mouse_hovered);
|
||||
feedback->hovered_absolute = box->mouse_hovered;
|
||||
|
||||
@ -374,6 +374,8 @@ Struct(UI_Box)
|
||||
f32 rounding_bl;
|
||||
|
||||
//- Feedback
|
||||
b32 child_mouse_hovered;
|
||||
b32 child_mouse_captured;
|
||||
b32 mouse_hovered;
|
||||
b32 mouse_captured;
|
||||
UI_Feedback feedback;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user