render selection behind text
This commit is contained in:
parent
7f3312c12a
commit
2f4a7f74b5
@ -4565,6 +4565,44 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_Key search_scroll_box = UI_KeyF("search scroll box");
|
||||
V_TextboxState *search_state = &palette->search_state;
|
||||
|
||||
f32 font_size = UI_Top(FontSize);
|
||||
GC_FontKey font = UI_Top(Font);
|
||||
|
||||
// Vec4 search_color = Color_Black;
|
||||
Vec4 search_color = Zi;
|
||||
|
||||
b32 has_focus = UI_MatchKey(search_box, prev_frame->text_input_focus);
|
||||
{
|
||||
// FIXME: Remove this
|
||||
has_focus = 1;
|
||||
if (UI_Downs(search_box, Button_M1))
|
||||
{
|
||||
has_focus = 1;
|
||||
V.text_input_ns = frame->time_ns;
|
||||
}
|
||||
if (!palette->is_showing)
|
||||
{
|
||||
has_focus = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (UI_HotAbsolute(search_box))
|
||||
{
|
||||
WND_SetCursor(window_frame, WND_CursorKind_Text);
|
||||
}
|
||||
|
||||
V_TextboxDeltaFlag tb_applied_flags = 0;
|
||||
|
||||
// Apply text input deltas
|
||||
{
|
||||
frame->text_input_focus = search_box;
|
||||
if (text_input_deltas.first)
|
||||
{
|
||||
V.text_input_ns = frame->time_ns;
|
||||
tb_applied_flags |= V_ApplyTextboxDeltas(search_state, text_input_deltas);
|
||||
}
|
||||
}
|
||||
|
||||
String search_text = V_StringFromTextbox(frame->arena, search_state);
|
||||
search_pattern = LowerString(frame->arena, search_text);
|
||||
is_searching = search_text.len != 0;
|
||||
@ -4577,54 +4615,15 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
display_text = Lit(" Search...");
|
||||
}
|
||||
|
||||
f32 font_size = UI_Top(FontSize);
|
||||
GC_FontKey font = UI_Top(Font);
|
||||
|
||||
// Vec4 search_color = Color_Black;
|
||||
Vec4 search_color = Zi;
|
||||
|
||||
// TODO: Cache run for UI
|
||||
String32 codepoints = String32FromString(frame->arena, search_text);
|
||||
GC_Run run = GC_RunFromString32(frame->arena, codepoints, font, font_size);
|
||||
|
||||
b32 has_focus = UI_MatchKey(search_box, prev_frame->text_input_focus);
|
||||
|
||||
// FIXME: Remove this
|
||||
has_focus = 1;
|
||||
|
||||
// if (UI_Downs(search_box, Button_M1))
|
||||
if (UI_Downs(search_box, Button_M1))
|
||||
{
|
||||
has_focus = 1;
|
||||
V.text_input_ns = frame->time_ns;
|
||||
}
|
||||
|
||||
if (!palette->is_showing)
|
||||
{
|
||||
has_focus = 0;
|
||||
}
|
||||
|
||||
if (UI_HotAbsolute(search_box))
|
||||
{
|
||||
WND_SetCursor(window_frame, WND_CursorKind_Text);
|
||||
}
|
||||
|
||||
V_TextboxDeltaFlag tb_applied_flags = 0;
|
||||
b32 started_dragging_text = 0;
|
||||
b32 is_dragging_text = 0;
|
||||
if (has_focus)
|
||||
{
|
||||
// Apply text input deltas
|
||||
{
|
||||
frame->text_input_focus = search_box;
|
||||
if (text_input_deltas.first)
|
||||
{
|
||||
V.text_input_ns = frame->time_ns;
|
||||
tb_applied_flags |= V_ApplyTextboxDeltas(search_state, text_input_deltas);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply mouse select
|
||||
// Generate & apply mouse selection delta
|
||||
if (UI_Held(search_box, Button_M1))
|
||||
{
|
||||
V.text_input_ns = frame->time_ns;
|
||||
@ -4653,13 +4652,6 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
tb_applied_flags |= V_ApplyTextboxDelta(search_state, delta);
|
||||
}
|
||||
}
|
||||
|
||||
// // Apply mouse selection drag
|
||||
// if (UI_Held(search_box))
|
||||
// {
|
||||
// f32 drag_delta = UI_CursorPos().x - UI_DragCursorPos().x;
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -4675,9 +4667,9 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_SetNext(BackgroundColor, search_color);
|
||||
UI_SetNext(ChildAlignment, UI_Region_Right);
|
||||
// UI_SetNext(BorderColor, item_border_color);
|
||||
UI_PushDF(BorderSize, 0);
|
||||
// UI_SetNext(Rounding, UI_Rpx(5));
|
||||
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_Scissor);
|
||||
// UI_PushDF(BorderSize, 0)
|
||||
UI_PushDF(Parent, UI_BuildRowEx(search_box))
|
||||
{
|
||||
//- Compute caret / selection pos
|
||||
@ -4705,7 +4697,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
}
|
||||
}
|
||||
|
||||
f32 caret_start_lerp_rate = 25 * frame->dt;
|
||||
f32 caret_start_lerp_rate = 20 * frame->dt;
|
||||
f32 caret_end_lerp_rate = 50 * frame->dt;
|
||||
{
|
||||
if (started_dragging_text)
|
||||
@ -4713,10 +4705,10 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
caret_start_lerp_rate = 1;
|
||||
caret_end_lerp_rate = 1;
|
||||
}
|
||||
if (is_dragging_text)
|
||||
{
|
||||
caret_end_lerp_rate *= 2;
|
||||
}
|
||||
// if (tb_applied_flags & V_TextboxDeltaFlag_UpdateText)
|
||||
// {
|
||||
// caret_end_lerp_rate = 1;
|
||||
// }
|
||||
caret_start_lerp_rate = SaturateF32(caret_start_lerp_rate);
|
||||
caret_end_lerp_rate = SaturateF32(caret_end_lerp_rate);
|
||||
}
|
||||
@ -4729,7 +4721,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
{
|
||||
{
|
||||
f32 new_text_scroll_px = palette->caret_end_px - 10;
|
||||
palette->text_scroll_px = MinF32( palette->text_scroll_px, new_text_scroll_px);
|
||||
palette->text_scroll_px = MinF32(palette->text_scroll_px, new_text_scroll_px);
|
||||
}
|
||||
{
|
||||
f32 new_text_scroll_px = palette->caret_end_px - search_box_width + 10;
|
||||
@ -4742,9 +4734,10 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_Size caret_height = UI_Px(search_height.v, 1);
|
||||
f32 h = TweakFloat("Text selection hue", 200, 0, 360);
|
||||
f32 s = TweakFloat("Text selection saturation", 1, 0, 1);
|
||||
f32 v = TweakFloat("Text selection brightness", 1, 0, 1);
|
||||
f32 v = TweakFloat("Text selection brightness", 0.6, 0, 1);
|
||||
Vec4 selection_color = SrgbFromHsv(h, s, v);
|
||||
selection_color.a = 0.25;
|
||||
// Vec4 selection_color = theme.col.button_active;
|
||||
// selection_color.a = 1;
|
||||
|
||||
Vec4 caret_color = VEC4(1, 1, 1, 0.75);
|
||||
caret_color.a *= AbsF32(CosF32(SecondsFromNs(frame->time_ns - V.text_input_ns) * 3));
|
||||
@ -4754,16 +4747,13 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_SetNext(Anchor, UI_Region_Left);
|
||||
UI_SetNext(ChildAlignment, UI_Region_Left);
|
||||
UI_SetNext(Width, UI_Shrink(0, 1));
|
||||
UI_SetNext(TextColor, display_text_color);
|
||||
UI_SetNext(Text, display_text);
|
||||
UI_SetNext(Parent, search_box);
|
||||
UI_SetNext(
|
||||
Flags,
|
||||
UI_BoxFlag_DrawText |
|
||||
UI_BoxFlag_DontTruncateText |
|
||||
UI_BoxFlag_Floating |
|
||||
UI_BoxFlag_DontClampFloatingX
|
||||
);
|
||||
// UI_PushDF(Parent, UI_BuildRowEx(search_scroll_box))
|
||||
UI_PushDF(Parent, UI_BuildRowEx(search_scroll_box))
|
||||
{
|
||||
UI_Key caret_box = UI_KeyF("search caret");
|
||||
@ -4773,18 +4763,30 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
{
|
||||
f32 min = MinF32(palette->caret_end_px, palette->caret_start_px);
|
||||
f32 max = MaxF32(palette->caret_end_px, palette->caret_start_px);
|
||||
|
||||
UI_SetNext(Width, UI_Px(max - min, 1));
|
||||
UI_SetNext(Height, caret_height);
|
||||
UI_SetNext(FloatingPos, VEC2(min, 0));
|
||||
UI_SetNext(Anchor, UI_Region_Left);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating, UI_BoxFlag_CaptureMouse);
|
||||
UI_SetNext(BorderSize, 0);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX);
|
||||
UI_SetNext(BackgroundColor, selection_color);
|
||||
UI_SetNext(FontSize, font_size);
|
||||
UI_BuildBoxEx(selection_box);
|
||||
}
|
||||
|
||||
//- Text
|
||||
{
|
||||
UI_SetNext(ChildAlignment, UI_Region_Left);
|
||||
UI_SetNext(Width, UI_Shrink(0, 1));
|
||||
UI_SetNext(TextColor, display_text_color);
|
||||
UI_SetNext(Text, display_text);
|
||||
UI_SetNext(
|
||||
Flags,
|
||||
UI_BoxFlag_DrawText |
|
||||
UI_BoxFlag_DontTruncateText
|
||||
);
|
||||
UI_BuildBox();
|
||||
}
|
||||
|
||||
//- Caret
|
||||
if (has_focus)
|
||||
{
|
||||
@ -4792,7 +4794,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_SetNext(Height, caret_height);
|
||||
UI_SetNext(FloatingPos, VEC2(palette->caret_end_px, 0));
|
||||
UI_SetNext(Anchor, UI_Region_Left);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating, UI_BoxFlag_CaptureMouse);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX);
|
||||
UI_SetNext(BorderSize, 0);
|
||||
UI_SetNext(BackgroundColor, caret_color);
|
||||
UI_SetNext(FontSize, font_size);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user