From c0f727c4eb96cbfee4963ef2107b3f9468f8b3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Sun, 3 Nov 2024 20:22:03 -0500 Subject: [PATCH] [ui] Improve combobox behaviour --- src/lib/score/graphics/widgets/QGraphicsCombo.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/score/graphics/widgets/QGraphicsCombo.cpp b/src/lib/score/graphics/widgets/QGraphicsCombo.cpp index 8b35907e91..260693800f 100644 --- a/src/lib/score/graphics/widgets/QGraphicsCombo.cpp +++ b/src/lib/score/graphics/widgets/QGraphicsCombo.cpp @@ -108,10 +108,10 @@ struct DefaultComboImpl if((event->buttons() & Qt::LeftButton) && self.m_grab) { double v = InfiniteScroller::move(event); - int curPos = v * (self.array.size() - 1); + int curPos = std::round(v * (self.array.size() - 1)); if(curPos != self.m_value) { - self.m_value = curPos; + self.m_value = std::clamp(curPos, 0, int(self.array.size() - 1)); self.sliderMoved(); self.update(); } @@ -128,10 +128,10 @@ struct DefaultComboImpl if(self.m_grab) { double v = InfiniteScroller::move(event); - int curPos = v * (self.array.size() - 1); + int curPos = std::round(v * (self.array.size() - 1)); if(curPos != self.m_value) { - self.m_value = curPos; + self.m_value = std::clamp(curPos, 0, int(self.array.size() - 1)); self.update(); } self.m_grab = false;