Browse Source

Fix missing scrollbar in multiline h2d.Flow

Also fix scrollbars not taking padding into account
Leonardo Jeanteur 5 months ago
parent
commit
7c4277534f
1 changed files with 35 additions and 5 deletions
  1. 35 5
      h2d/Flow.hx

+ 35 - 5
h2d/Flow.hx

@@ -446,6 +446,9 @@ class Flow extends Object {
 	**/
 	**/
 	public var innerHeight(get, never) : Int;
 	public var innerHeight(get, never) : Int;
 
 
+	// does not do a reflow on get
+	var scrollInnerHeight(get, never) : Int;
+
 	/**
 	/**
 		Flow total width. Compared to `Flow.innerWidth`, it also includes paddings and, if enabled, borders (see `Flow.borderWidth`).
 		Flow total width. Compared to `Flow.innerWidth`, it also includes paddings and, if enabled, borders (see `Flow.borderWidth`).
 
 
@@ -628,14 +631,14 @@ class Flow extends Object {
 			enableInteractive = true;
 			enableInteractive = true;
 			if( scrollBar == null ) {
 			if( scrollBar == null ) {
 				scrollBar = makeScrollBar();
 				scrollBar = makeScrollBar();
-				addChild(scrollBar);
+				addChildAt(scrollBar, 0);
 				scrollBar.verticalAlign = Top;
 				scrollBar.verticalAlign = Top;
 				scrollBar.enableInteractive = true;
 				scrollBar.enableInteractive = true;
 
 
 				function setCursor( e : hxd.Event) {
 				function setCursor( e : hxd.Event) {
 					var cursorY = e.relY - scrollBarCursor.minHeight * 0.5;
 					var cursorY = e.relY - scrollBarCursor.minHeight * 0.5;
 					if( cursorY < 0 ) cursorY = 0;
 					if( cursorY < 0 ) cursorY = 0;
-					scrollPosY = (cursorY / (scrollBar.minHeight - scrollBarCursor.minHeight)) * (contentHeight - calculatedHeight);
+					scrollPosY = (cursorY / (scrollBar.minHeight - scrollBarCursor.minHeight)) * (contentHeight - scrollInnerHeight);
 				}
 				}
 
 
 				var pushed = false;
 				var pushed = false;
@@ -740,7 +743,7 @@ class Flow extends Object {
 		if( scrollBarCursor == null ) return;
 		if( scrollBarCursor == null ) return;
 		var prev = needReflow;
 		var prev = needReflow;
 		var p = scrollBar.getProperties(scrollBarCursor);
 		var p = scrollBar.getProperties(scrollBarCursor);
-		p.paddingTop = Std.int( scrollPosY * (calculatedHeight - scrollBarCursor.minHeight) / (contentHeight - calculatedHeight) );
+		p.paddingTop = Std.int( scrollPosY * (scrollInnerHeight - scrollBarCursor.minHeight) / (contentHeight - calculatedHeight) );
 		needReflow = prev;
 		needReflow = prev;
 	}
 	}
 
 
@@ -776,6 +779,10 @@ class Flow extends Object {
 		return flowCeil(calculatedHeight) - (paddingTop + paddingBottom #if flow_border + (borderTop + borderBottom) #end);
 		return flowCeil(calculatedHeight) - (paddingTop + paddingBottom #if flow_border + (borderTop + borderBottom) #end);
 	}
 	}
 
 
+	function get_scrollInnerHeight() {
+		return flowCeil(calculatedHeight) - (paddingTop + paddingBottom #if flow_border + (borderTop + borderBottom) #end);
+	}
+
 	function set_paddingLeft(v) {
 	function set_paddingLeft(v) {
 		if( paddingLeft == v ) return v;
 		if( paddingLeft == v ) return v;
 		needReflow = true;
 		needReflow = true;
@@ -1128,6 +1135,23 @@ class Flow extends Object {
 		onBeforeReflow();
 		onBeforeReflow();
 		syncPos();
 		syncPos();
 
 
+		var c = null;
+		if (dom?.hasClass("align-test-parent"))
+			c = "align-test-parent";
+		if (dom?.hasClass("align-test"))
+			c = "align-test";
+		if (dom?.hasClass("align-test-child1"))
+			c = "align-test-child1";
+		if (dom?.hasClass("align-test-child2"))
+			c = "align-test-child2";
+		var deb = c != null;
+		var a = 0;
+		if (deb) {
+			if (a == c.length) {
+				trace("hello break please");
+			}
+		}
+
 		if( !isConstraint && (fillWidth || fillHeight) ) {
 		if( !isConstraint && (fillWidth || fillHeight) ) {
 			var scene = getScene();
 			var scene = getScene();
 			var cw = fillWidth ? scene.width : -1;
 			var cw = fillWidth ? scene.width : -1;
@@ -1216,6 +1240,9 @@ class Flow extends Object {
 						c.y += height - Std.int(p.calculatedHeight);
 						c.y += height - Std.int(p.calculatedHeight);
 					case Middle:
 					case Middle:
 						c.y += Std.int((height - p.calculatedHeight) * 0.5);
 						c.y += Std.int((height - p.calculatedHeight) * 0.5);
+					case Top:
+						if( p.isAbsolute )
+							c.y = paddingTop + borderTop + p.offsetY + p.paddingTop;
 					default:
 					default:
 					}
 					}
 				}
 				}
@@ -1381,6 +1408,9 @@ class Flow extends Object {
 						c.x += width - p.calculatedWidth;
 						c.x += width - p.calculatedWidth;
 					case Middle:
 					case Middle:
 						c.x += Std.int((width - p.calculatedWidth) * 0.5);
 						c.x += Std.int((width - p.calculatedWidth) * 0.5);
+					case Left:
+						if( p.isAbsolute )
+							c.x = paddingLeft + borderLeft + p.offsetX + p.paddingLeft;
 					default:
 					default:
 					}
 					}
 				}
 				}
@@ -1632,8 +1662,8 @@ class Flow extends Object {
 				scrollBar.visible = false;
 				scrollBar.visible = false;
 			else {
 			else {
 				scrollBar.visible = true;
 				scrollBar.visible = true;
-				scrollBar.minHeight = flowCeil(calculatedHeight);
-				scrollBarCursor.minHeight = hxd.Math.imax(1, Std.int(calculatedHeight * (1 - (contentHeight - calculatedHeight)/contentHeight)));
+				scrollBar.minHeight = scrollInnerHeight;
+				scrollBarCursor.minHeight = hxd.Math.imax(1, Std.int(scrollInnerHeight * (1 - (contentHeight - scrollInnerHeight)/contentHeight)));
 				updateScrollCursor();
 				updateScrollCursor();
 			}
 			}
 		}
 		}