diff --git a/src/ui/int_entry.cpp b/src/ui/int_entry.cpp index 90d0d53d2..87ce6a4fc 100644 --- a/src/ui/int_entry.cpp +++ b/src/ui/int_entry.cpp @@ -175,43 +175,45 @@ void IntEntry::openPopup() { m_slider->setValue(getValue()); - // We weren't able to reproduce it, but there are crash reports - // where this openPopup() function is called and the popup is still - // alive, with the slider inside (we have to remove it before - // resetting m_popupWindow pointer to avoid deleting the slider - // pointer). - removeSlider(); + if (m_useSlider) { + // We weren't able to reproduce it, but there are crash reports + // where this openPopup() function is called and the popup is still + // alive, with the slider inside (we have to remove it before + // resetting m_popupWindow pointer to avoid deleting the slider + // pointer). + removeSlider(); - m_popupWindow = std::make_unique( - PopupWindow::ClickBehavior::CloseOnClickInOtherWindow); - m_popupWindow->setAutoRemap(false); - m_popupWindow->addChild(m_slider.get()); - m_popupWindow->Close.connect(&IntEntry::onPopupClose, this); + m_popupWindow = std::make_unique( + PopupWindow::ClickBehavior::CloseOnClickInOtherWindow); + m_popupWindow->setAutoRemap(false); + m_popupWindow->addChild(m_slider.get()); + m_popupWindow->Close.connect(&IntEntry::onPopupClose, this); - fit_bounds(display(), - m_popupWindow.get(), - gfx::Rect(0, 0, 128 * guiscale(), m_popupWindow->sizeHint().h), - [this](const gfx::Rect& workarea, - gfx::Rect& rc, - std::function getWidgetBounds) { - Rect entryBounds = getWidgetBounds(this); + fit_bounds(display(), + m_popupWindow.get(), + gfx::Rect(0, 0, 128 * guiscale(), m_popupWindow->sizeHint().h), + [this](const gfx::Rect& workarea, + gfx::Rect& rc, + std::function getWidgetBounds) { + Rect entryBounds = getWidgetBounds(this); - rc.x = entryBounds.x; - rc.y = entryBounds.y2(); + rc.x = entryBounds.x; + rc.y = entryBounds.y2(); - if (rc.x2() > workarea.x2()) - rc.x = rc.x - rc.w + entryBounds.w; + if (rc.x2() > workarea.x2()) + rc.x = rc.x - rc.w + entryBounds.w; - if (rc.y2() > workarea.y2()) - rc.y = entryBounds.y - entryBounds.h; + if (rc.y2() > workarea.y2()) + rc.y = entryBounds.y - entryBounds.h; - m_popupWindow->setBounds(rc); - }); + m_popupWindow->setBounds(rc); + }); - Region rgn(m_popupWindow->boundsOnScreen().createUnion(boundsOnScreen())); - m_popupWindow->setHotRegion(rgn); + Region rgn(m_popupWindow->boundsOnScreen().createUnion(boundsOnScreen())); + m_popupWindow->setHotRegion(rgn); - m_popupWindow->openWindow(); + m_popupWindow->openWindow(); + } } void IntEntry::closePopup() diff --git a/src/ui/int_entry.h b/src/ui/int_entry.h index 21734a593..b30d96dd8 100644 --- a/src/ui/int_entry.h +++ b/src/ui/int_entry.h @@ -27,6 +27,10 @@ public: virtual int getValue() const; virtual void setValue(int value); + // If useSlider is false, then it won't show the slider popup to change its + // value. + void useSlider(bool useSlider) { m_useSlider = useSlider; } + protected: bool onProcessMessage(Message* msg) override; void onInitTheme(InitThemeEvent& ev) override; @@ -42,6 +46,8 @@ protected: int m_max; std::unique_ptr m_popupWindow; bool m_changeFromSlider; + // If true a slider can be used to modify the value. + bool m_useSlider = true; std::unique_ptr m_slider; private: