mirror of https://github.com/aseprite/aseprite.git
Make showing a slider for an IntEntry optional
This commit is contained in:
parent
8c1fa31abd
commit
26cf154198
|
@ -175,43 +175,45 @@ void IntEntry::openPopup()
|
||||||
{
|
{
|
||||||
m_slider->setValue(getValue());
|
m_slider->setValue(getValue());
|
||||||
|
|
||||||
// We weren't able to reproduce it, but there are crash reports
|
if (m_useSlider) {
|
||||||
// where this openPopup() function is called and the popup is still
|
// We weren't able to reproduce it, but there are crash reports
|
||||||
// alive, with the slider inside (we have to remove it before
|
// where this openPopup() function is called and the popup is still
|
||||||
// resetting m_popupWindow pointer to avoid deleting the slider
|
// alive, with the slider inside (we have to remove it before
|
||||||
// pointer).
|
// resetting m_popupWindow pointer to avoid deleting the slider
|
||||||
removeSlider();
|
// pointer).
|
||||||
|
removeSlider();
|
||||||
|
|
||||||
m_popupWindow = std::make_unique<TransparentPopupWindow>(
|
m_popupWindow = std::make_unique<TransparentPopupWindow>(
|
||||||
PopupWindow::ClickBehavior::CloseOnClickInOtherWindow);
|
PopupWindow::ClickBehavior::CloseOnClickInOtherWindow);
|
||||||
m_popupWindow->setAutoRemap(false);
|
m_popupWindow->setAutoRemap(false);
|
||||||
m_popupWindow->addChild(m_slider.get());
|
m_popupWindow->addChild(m_slider.get());
|
||||||
m_popupWindow->Close.connect(&IntEntry::onPopupClose, this);
|
m_popupWindow->Close.connect(&IntEntry::onPopupClose, this);
|
||||||
|
|
||||||
fit_bounds(display(),
|
fit_bounds(display(),
|
||||||
m_popupWindow.get(),
|
m_popupWindow.get(),
|
||||||
gfx::Rect(0, 0, 128 * guiscale(), m_popupWindow->sizeHint().h),
|
gfx::Rect(0, 0, 128 * guiscale(), m_popupWindow->sizeHint().h),
|
||||||
[this](const gfx::Rect& workarea,
|
[this](const gfx::Rect& workarea,
|
||||||
gfx::Rect& rc,
|
gfx::Rect& rc,
|
||||||
std::function<gfx::Rect(Widget*)> getWidgetBounds) {
|
std::function<gfx::Rect(Widget*)> getWidgetBounds) {
|
||||||
Rect entryBounds = getWidgetBounds(this);
|
Rect entryBounds = getWidgetBounds(this);
|
||||||
|
|
||||||
rc.x = entryBounds.x;
|
rc.x = entryBounds.x;
|
||||||
rc.y = entryBounds.y2();
|
rc.y = entryBounds.y2();
|
||||||
|
|
||||||
if (rc.x2() > workarea.x2())
|
if (rc.x2() > workarea.x2())
|
||||||
rc.x = rc.x - rc.w + entryBounds.w;
|
rc.x = rc.x - rc.w + entryBounds.w;
|
||||||
|
|
||||||
if (rc.y2() > workarea.y2())
|
if (rc.y2() > workarea.y2())
|
||||||
rc.y = entryBounds.y - entryBounds.h;
|
rc.y = entryBounds.y - entryBounds.h;
|
||||||
|
|
||||||
m_popupWindow->setBounds(rc);
|
m_popupWindow->setBounds(rc);
|
||||||
});
|
});
|
||||||
|
|
||||||
Region rgn(m_popupWindow->boundsOnScreen().createUnion(boundsOnScreen()));
|
Region rgn(m_popupWindow->boundsOnScreen().createUnion(boundsOnScreen()));
|
||||||
m_popupWindow->setHotRegion(rgn);
|
m_popupWindow->setHotRegion(rgn);
|
||||||
|
|
||||||
m_popupWindow->openWindow();
|
m_popupWindow->openWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntEntry::closePopup()
|
void IntEntry::closePopup()
|
||||||
|
|
|
@ -27,6 +27,10 @@ public:
|
||||||
virtual int getValue() const;
|
virtual int getValue() const;
|
||||||
virtual void setValue(int value);
|
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:
|
protected:
|
||||||
bool onProcessMessage(Message* msg) override;
|
bool onProcessMessage(Message* msg) override;
|
||||||
void onInitTheme(InitThemeEvent& ev) override;
|
void onInitTheme(InitThemeEvent& ev) override;
|
||||||
|
@ -42,6 +46,8 @@ protected:
|
||||||
int m_max;
|
int m_max;
|
||||||
std::unique_ptr<PopupWindow> m_popupWindow;
|
std::unique_ptr<PopupWindow> m_popupWindow;
|
||||||
bool m_changeFromSlider;
|
bool m_changeFromSlider;
|
||||||
|
// If true a slider can be used to modify the value.
|
||||||
|
bool m_useSlider = true;
|
||||||
std::unique_ptr<Slider> m_slider;
|
std::unique_ptr<Slider> m_slider;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue