From 0a1d86e1f50605d13ae2974b795064c3e4cd32a8 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 12 Sep 2021 15:59:40 -0700 Subject: [PATCH] Bugfix: Scroll constraint favors top/left edge For levels having a top/left scroll boundary, the top/left point takes higher priority for resolving out-of-bounds scroll ranges instead of the bottom/right. This fixes a bug where you Zoom Out of a level far enough that the entire boundaries of a Bounded level are smaller than the viewport into the level. It could happen if playing normal levels in Play Mode on a very high-resolution monitor. Previously, the level would anchor to the bottom/right corner of your screen. With the Zoom In/Out Feature this broke the ability to scroll well on the level; so the easy fix is to put the X>0, Y>0 bounds check after the above, so the level will hug the top/left corner of the screen which fixes both problems. --- pkg/uix/canvas_scrolling.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/uix/canvas_scrolling.go b/pkg/uix/canvas_scrolling.go index ae59611..5c627fd 100644 --- a/pkg/uix/canvas_scrolling.go +++ b/pkg/uix/canvas_scrolling.go @@ -67,18 +67,6 @@ func (w *Canvas) loopConstrainScroll() error { var capped bool - // Constrain the top and left edges. - if w.wallpaper.pageType > level.Unbounded { - if w.Scroll.X > 0 { - w.Scroll.X = 0 - capped = true - } - if w.Scroll.Y > 0 { - w.Scroll.Y = 0 - capped = true - } - } - // Constrain the bottom and right for limited world sizes. if w.wallpaper.pageType >= level.Bounded && w.wallpaper.maxWidth+w.wallpaper.maxHeight > 0 { @@ -103,6 +91,18 @@ func (w *Canvas) loopConstrainScroll() error { } } + // Constrain the top and left edges. + if w.wallpaper.pageType > level.Unbounded { + if w.Scroll.X > 0 { + w.Scroll.X = 0 + capped = true + } + if w.Scroll.Y > 0 { + w.Scroll.Y = 0 + capped = true + } + } + if capped { return errors.New("scroll limited by level constraint") }