浏览代码

added scrollXY on box content

ncannasse 11 年之前
父节点
当前提交
60992cd28d
共有 2 个文件被更改,包括 18 次插入8 次删除
  1. 10 8
      h2d/comp/Box.hx
  2. 8 0
      h2d/comp/ItemList.hx

+ 10 - 8
h2d/comp/Box.hx

@@ -3,6 +3,8 @@ package h2d.comp;
 class Box extends Component {
 	
 	var input : h2d.Interactive;
+	var scrollX : Float = 0.;
+	var scrollY : Float = 0.;
 	
 	public function new(?layout,?parent) {
 		super("box", parent);
@@ -61,8 +63,8 @@ class Box extends Component {
 					} else {
 						if( c.height > lineHeight ) lineHeight = c.height;
 					}
-					ctx2.xPos = xPos;
-					ctx2.yPos = yPos;
+					ctx2.xPos = xPos + scrollX;
+					ctx2.yPos = yPos + scrollY;
 					c.resizeRec(ctx2);
 					xPos += c.width + style.horizontalSpacing;
 				}
@@ -88,8 +90,8 @@ class Box extends Component {
 					xPos += c.width;
 					if( c.height > lineHeight ) lineHeight = c.height;
 				} else {
-					ctx2.xPos = xPos;
-					ctx2.yPos = 0;
+					ctx2.xPos = xPos + scrollX;
+					ctx2.yPos = scrollY;
 					c.resizeRec(ctx2);
 					xPos += c.width + style.horizontalSpacing;
 				}
@@ -115,8 +117,8 @@ class Box extends Component {
 					yPos += c.height;
 					if( c.width > colWidth ) colWidth = c.width;
 				} else {
-					ctx2.xPos = 0;
-					ctx2.yPos = yPos;
+					ctx2.xPos = scrollX;
+					ctx2.yPos = yPos + scrollY;
 					c.resizeRec(ctx2);
 					yPos += c.height + style.verticalSpacing;
 				}
@@ -162,8 +164,8 @@ class Box extends Component {
 					ctx2.maxHeight = h;
 					var d = c.style.dock;
 					if( d == null ) d = Full;
-					ctx2.xPos = xPos;
-					ctx2.yPos = yPos;
+					ctx2.xPos = xPos + scrollX;
+					ctx2.yPos = yPos + scrollY;
 					switch( d ) {
 					case Left, Top:
 					case Right:

+ 8 - 0
h2d/comp/ItemList.hx

@@ -16,6 +16,13 @@ class ItemList extends Box {
 		return selected = v;
 	}
 	
+	function onWheel( e : hxd.Event ) {
+		scrollY -= e.wheelDelta * (components.length == 0 ? 0 : (components[0].height + style.verticalSpacing));
+		if( scrollY > 0 ) scrollY = 0;
+		e.propagate = false;
+		needRebuild = true;
+	}
+	
 	override function resizeRec( ctx : Context ) {
 		super.resizeRec(ctx);
 		if( !ctx.measure ) {
@@ -62,6 +69,7 @@ class ItemList extends Box {
 						}
 					}
 				}
+				int.onWheel = onWheel;
 				if( Lambda.indexOf(childs,int) != 1 + i ) {
 					childs.remove(int);
 					childs.insert(1 + i, int); // insert over bg