mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-25 10:43:46 +00:00
Fix invalid scroll on ui::View after changing required size of attached widget (regressiong introduced in b4eb7a0ccda38b91bd8fd253e54718c3a18d81b6)
This commit is contained in:
parent
71046b6042
commit
951fb7c357
@ -129,8 +129,8 @@ void View::setScrollableSize(const gfx::Size& sz,
|
|||||||
|
|
||||||
// Setup viewport
|
// Setup viewport
|
||||||
if (setScrollPos) {
|
if (setScrollPos) {
|
||||||
invalidate();
|
|
||||||
setViewScroll(viewScroll()); // Setup the same scroll-point
|
setViewScroll(viewScroll()); // Setup the same scroll-point
|
||||||
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,13 +169,24 @@ void View::updateView(const bool restoreScrollPos)
|
|||||||
setScrollableSize(m_viewport.calculateNeededSize(), false);
|
setScrollableSize(m_viewport.calculateNeededSize(), false);
|
||||||
|
|
||||||
m_viewport.setBounds(m_viewport.bounds());
|
m_viewport.setBounds(m_viewport.bounds());
|
||||||
invalidate();
|
if (restoreScrollPos ||
|
||||||
if (restoreScrollPos) {
|
// Force restoring the old scroll position if we are out of
|
||||||
|
// bounds in the viewport limits.
|
||||||
|
scroll != limitScrollPosToViewport(scroll)) {
|
||||||
if (vw)
|
if (vw)
|
||||||
setViewScroll(scroll);
|
setViewScroll(scroll);
|
||||||
else
|
else
|
||||||
setViewScroll(Point(0, 0));
|
setViewScroll(Point(0, 0));
|
||||||
}
|
}
|
||||||
|
ASSERT(viewScroll() == limitScrollPosToViewport(viewScroll()));
|
||||||
|
|
||||||
|
if (Widget* child = attachedWidget()) {
|
||||||
|
updateAttachedWidgetBounds(viewScroll());
|
||||||
|
ASSERT(child->bounds().w >= viewportBounds().w);
|
||||||
|
ASSERT(child->bounds().h >= viewportBounds().h);
|
||||||
|
}
|
||||||
|
|
||||||
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
Viewport* View::viewport()
|
Viewport* View::viewport()
|
||||||
@ -253,10 +264,6 @@ void View::onSetViewScroll(const gfx::Point& pt)
|
|||||||
if (newScroll == oldScroll)
|
if (newScroll == oldScroll)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// This is the movement for the scrolled region (which is inverse to
|
|
||||||
// the scroll position delta/movement).
|
|
||||||
Point delta = oldScroll - newScroll;
|
|
||||||
|
|
||||||
// Visible viewport region that is not overlapped by windows
|
// Visible viewport region that is not overlapped by windows
|
||||||
Region drawableRegion;
|
Region drawableRegion;
|
||||||
m_viewport.getDrawableRegion(
|
m_viewport.getDrawableRegion(
|
||||||
@ -297,19 +304,8 @@ void View::onSetViewScroll(const gfx::Point& pt)
|
|||||||
onScrollRegion(ev);
|
onScrollRegion(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move viewport children
|
// Move attached widget
|
||||||
cpos.offset(-newScroll);
|
updateAttachedWidgetBounds(newScroll);
|
||||||
for (auto child : m_viewport.children()) {
|
|
||||||
Size reqSize = child->sizeHint();
|
|
||||||
cpos.w = MAX(reqSize.w, cpos.w);
|
|
||||||
cpos.h = MAX(reqSize.h, cpos.h);
|
|
||||||
if (cpos.w != child->bounds().w ||
|
|
||||||
cpos.h != child->bounds().h)
|
|
||||||
child->setBounds(cpos);
|
|
||||||
else
|
|
||||||
child->offsetWidgets(cpos.x - child->bounds().x,
|
|
||||||
cpos.y - child->bounds().y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change scroll bar positions
|
// Change scroll bar positions
|
||||||
m_scrollbar_h.setPos(newScroll.x);
|
m_scrollbar_h.setPos(newScroll.x);
|
||||||
@ -319,7 +315,10 @@ void View::onSetViewScroll(const gfx::Point& pt)
|
|||||||
Region invalidRegion(cpos);
|
Region invalidRegion(cpos);
|
||||||
invalidRegion &= drawableRegion;
|
invalidRegion &= drawableRegion;
|
||||||
|
|
||||||
// Move the valid screen region.
|
// Move the valid screen region. "delta" is the movement for the
|
||||||
|
// scrolled region (which is inverse to the scroll position
|
||||||
|
// delta/movement).
|
||||||
|
const Point delta = oldScroll - newScroll;
|
||||||
{
|
{
|
||||||
// The movable region includes the given "validRegion"
|
// The movable region includes the given "validRegion"
|
||||||
// intersecting itself when it's in the new position, so we don't
|
// intersecting itself when it's in the new position, so we don't
|
||||||
@ -372,6 +371,23 @@ void View::onScrollChange()
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void View::updateAttachedWidgetBounds(const gfx::Point& scrollPos)
|
||||||
|
{
|
||||||
|
Rect cpos = m_viewport.childrenBounds();
|
||||||
|
cpos.offset(-scrollPos);
|
||||||
|
for (auto child : m_viewport.children()) {
|
||||||
|
Size reqSize = child->sizeHint();
|
||||||
|
cpos.w = MAX(reqSize.w, cpos.w);
|
||||||
|
cpos.h = MAX(reqSize.h, cpos.h);
|
||||||
|
if (cpos.w != child->bounds().w ||
|
||||||
|
cpos.h != child->bounds().h)
|
||||||
|
child->setBounds(cpos);
|
||||||
|
else
|
||||||
|
child->offsetWidgets(cpos.x - child->bounds().x,
|
||||||
|
cpos.y - child->bounds().y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gfx::Point View::limitScrollPosToViewport(const gfx::Point& pt) const
|
gfx::Point View::limitScrollPosToViewport(const gfx::Point& pt) const
|
||||||
{
|
{
|
||||||
const Size maxSize = getScrollableSize();
|
const Size maxSize = getScrollableSize();
|
||||||
|
@ -71,6 +71,7 @@ namespace ui {
|
|||||||
virtual void onScrollChange();
|
virtual void onScrollChange();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateAttachedWidgetBounds(const gfx::Point& scrollPos);
|
||||||
gfx::Point limitScrollPosToViewport(const gfx::Point& pt) const;
|
gfx::Point limitScrollPosToViewport(const gfx::Point& pt) const;
|
||||||
|
|
||||||
bool m_hasBars;
|
bool m_hasBars;
|
||||||
|
@ -1570,6 +1570,9 @@ double Widget::onGetTextDouble() const
|
|||||||
|
|
||||||
void Widget::offsetWidgets(int dx, int dy)
|
void Widget::offsetWidgets(int dx, int dy)
|
||||||
{
|
{
|
||||||
|
if (dx == 0 && dy == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
m_updateRegion.offset(dx, dy);
|
m_updateRegion.offset(dx, dy);
|
||||||
m_bounds.offset(dx, dy);
|
m_bounds.offset(dx, dy);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user