DoubleSlider: Fixed a click on hovered tick, when object is height enough.

(layer step is less then 2px)
SPE-2421
This commit is contained in:
YuSanka 2024-07-18 14:05:22 +02:00 committed by Lukas Matena
parent 5e3240fd76
commit 10c0f7f255
3 changed files with 38 additions and 2 deletions

View File

@ -207,6 +207,7 @@ void DSForLayers::draw_ticks(const ImRect& slideable_region)
};
std::set<TickCode>::const_iterator tick_it = m_ticks.ticks.begin();
bool is_hovered_tick = false;
while (tick_it != m_ticks.ticks.end())
{
float tick_pos = get_tick_pos(tick_it->tick);
@ -221,11 +222,17 @@ void DSForLayers::draw_ticks(const ImRect& slideable_region)
m_focus = fiTick;
ImGuiPureWrap::tooltip(get_tooltip(tick_it->tick), ImGui::GetFontSize() * 20.f);
}
is_hovered_tick = true;
m_ctrl.SetHoveredRegion(tick_hover_box);
if (m_ctrl.IsLClickOnHoveredPos())
m_ctrl.IsActiveHigherThumb() ? SetHigherPos(tick_it->tick) : SetLowerPos(tick_it->tick);
break;
}
++tick_it;
}
if (!is_hovered_tick)
m_ctrl.InvalidateHoveredRegion();
auto active_tick_it = m_ticks.ticks.find(TickCode{ m_ctrl.GetActivePos() });
tick_it = m_ticks.ticks.begin();

View File

@ -316,6 +316,16 @@ bool ImGuiControl::IsLClickOnThumb()
return false;
}
bool ImGuiControl::IsLClickOnHoveredPos()
{
if (m_lclick_on_hovered_pos) {
// Discard left mouse click at hovered tick to avoud reuse it on next frame
m_lclick_on_hovered_pos = false;
return true;
}
return false;
}
void ImGuiControl::draw_scroll_line(const ImRect& scroll_line, const ImRect& slideable_region)
{
if (m_cb_draw_scroll_line)
@ -542,8 +552,8 @@ bool ImGuiControl::draw_slider( int* higher_pos, int* lower_pos,
ImGui::ItemHoverable(m_regions.lower_thumb, id) && context.IO.MouseClicked[0])
m_selection = ssLower;
// detect left click on selected thumb
{
// detect left click on selected thumb
const ImRect& active_thumb = m_selection == ssHigher ? m_regions.higher_thumb : m_regions.lower_thumb;
if (ImGui::ItemHoverable(active_thumb, id) && context.IO.MouseClicked[0]) {
m_active_thumb = active_thumb;
@ -561,6 +571,19 @@ bool ImGuiControl::draw_slider( int* higher_pos, int* lower_pos,
// invalidate active thumb clicking
m_active_thumb = ImRect(0.f, 0.f, 0.f, 0.f);
}
// detect left click on hovered region
if (ImGui::ItemHoverable(m_hovered_region, id) && context.IO.MouseClicked[0]) {
// clear active ID to avoid a process of behavior()
if (context.ActiveId == id && context.ActiveIdSource == ImGuiInputSource_Mouse)
ImGui::ClearActiveID();
}
else if (ImGui::ItemHoverable(m_hovered_region, id) && context.IO.MouseReleased[0]) {
const ImRect& slideable_region = m_selection == ssHigher ? m_regions.higher_slideable_region : m_regions.lower_slideable_region;
if (lclicked_on_thumb(id, slideable_region, m_min_pos, m_max_pos, m_hovered_region, m_flags)) {
m_lclick_on_hovered_pos = true;
}
}
}
// update thumb position

View File

@ -90,6 +90,7 @@ public:
bool IsRClickOnThumb() const { return m_rclick_on_selected_thumb; }
bool IsLClickOnThumb();
bool IsLClickOnHoveredPos();
bool is_horizontal() const { return !(m_flags & ImGuiSliderFlags_Vertical); }
bool render();
@ -98,6 +99,9 @@ public:
float rounding() const { return m_draw_opts.rounding(); }
ImVec2 left_dummy_sz() const { return m_draw_opts.text_dummy_sz() + m_draw_opts.text_padding(); }
void SetHoveredRegion(ImRect region) { m_hovered_region = region; }
void InvalidateHoveredRegion() { m_hovered_region = ImRect(0.f, 0.f, 0.f, 0.f); }
void set_get_label_on_move_cb(std::function<std::string(int)> cb) { m_cb_get_label_on_move = cb; }
void set_get_label_cb(std::function<std::string(int)> cb) { m_cb_get_label = cb; }
void set_draw_scroll_line_cb(std::function<void(const ImRect&, const ImRect&)> cb) { m_cb_draw_scroll_line = cb; }
@ -148,8 +152,10 @@ private:
bool m_rclick_on_selected_thumb{ false };
bool m_lclick_on_selected_thumb{ false };
bool m_lclick_on_hovered_pos { false };
bool m_suppress_process_behavior{ false };
ImRect m_active_thumb;
ImRect m_hovered_region;
bool m_draw_lower_thumb{ true };
bool m_combine_thumbs { false };