Browse Source

fixed scroll position should be adjusted when content size changes

Nicolas Cannasse 4 tháng trước cách đây
mục cha
commit
3752c599d1
1 tập tin đã thay đổi với 15 bổ sung10 xóa
  1. 15 10
      h2d/Flow.hx

+ 15 - 10
h2d/Flow.hx

@@ -1771,16 +1771,6 @@ class Flow extends Object {
 			}
 		}
 
-		if( scrollPosY != 0 ) {
-			var i = 0;
-			var sy = Std.int(scrollPosY);
-			for( c in children ) {
-				var p = properties[i++];
-				if( p.isAbsolute ) continue;
-				c.y -= sy;
-			}
-		}
-
 		contentWidth = cw;
 		contentHeight = ch;
 
@@ -1802,6 +1792,21 @@ class Flow extends Object {
 		calculatedWidth = cw;
 		calculatedHeight = ch;
 
+		if( scrollPosY != 0 ) {
+
+			var maxScroll = Std.int(contentHeight - calculatedHeight);
+			if( maxScroll < 0 ) maxScroll = 0;
+			if( scrollPosY > maxScroll ) @:bypassAccessor scrollPosY = maxScroll;
+
+			var i = 0;
+			var sy = Std.int(scrollPosY);
+			for( c in children ) {
+				var p = properties[i++];
+				if( p.isAbsolute ) continue;
+				c.y -= sy;
+			}
+		}
+
 		if( scrollBar != null ) {
 			if( contentHeight <= calculatedHeight )
 				scrollBar.visible = false;