Browse Source

fix GridBox node.

Ethosa 5 years ago
parent
commit
4934648c79
2 changed files with 30 additions and 6 deletions
  1. 7 2
      src/nodesnim/nodescontrol/grid_box.nim
  2. 23 4
      tests/test15.nim

+ 7 - 2
src/nodesnim/nodescontrol/grid_box.nim

@@ -51,7 +51,7 @@ method getChildSize*(self: GridBoxPtr): Vector2Ref =
       inc raw
     else:
       if self.raw > 1:
-        raw = 0
+        raw = 1
       y += self.separator + maxsize.y
   if y > maxsize.y:
     y -= self.separator
@@ -82,11 +82,12 @@ method draw*(self: GridBoxPtr, w, h: GLfloat) =
       inc raw
     else:
       if self.raw > 1:
-        raw = 0
+        raw = 1
       x = self.rect_size.x*self.child_anchor.x1 - fakesize.x*self.child_anchor.x2
       y += maxsize.y + self.separator
       child.position.x = x + maxsize.x*self.child_anchor.x1 - child.rect_size.x*self.child_anchor.x2
       child.position.y = y + maxsize.y*self.child_anchor.y1 - child.rect_size.y*self.child_anchor.y2
+      x += maxsize.x + self.separator
   procCall self.ControlPtr.draw(w, h)
 
 method resize*(self: GridBoxPtr, w, h: GLfloat) =
@@ -103,3 +104,7 @@ method resize*(self: GridBoxPtr, w, h: GLfloat) =
 method setRaw*(self: GridBoxPtr, raw: int) {.base.} =
   self.raw = raw
   self.rect_size = self.getChildSize()
+
+method setSeparator*(self: GridBoxPtr, separator: float) {.base.} =
+  self.separator = separator
+  self.rect_size = self.getChildSize()

+ 23 - 4
tests/test15.nim

@@ -20,23 +20,42 @@ var
   orangeobj: ColorRectObj
   orange = ColorRect(orangeobj)  # #ffaa00
 
+  mangoobj: ColorRectObj
+  mango = ColorRect(mangoobj)  # #ffcc33
+
+  yellowobj: ColorRectObj
+  yellow = ColorRect(yellowobj)  # #ffcc66
+
+  red2obj: ColorRectObj
+  red2 = ColorRect(red2obj)  # #ff6655
+
 
 red.color = Color(0xff6699ff'u32)
 pink.color = Color(0xff64ffff'u32)
 orange.color = Color(0xffaa00ff'u32)
+mango.color = Color(0xffcc33ff'u32)
+yellow.color = Color(0xffcc66ff'u32)
+red2.color = Color(0xff6655ff'u32)
 
 red.resize(128, 128)
-pink.resize(64, 64)
-orange.resize(32, 32)
+pink.resize(128, 128)
+orange.resize(128, 128)
+mango.resize(128, 128)
+yellow.resize(128, 128)
+red2.resize(128, 128)
 
 # Add rects in the Box node.
 grid_box.addChild(red)
 grid_box.addChild(pink)
 grid_box.addChild(orange)
+grid_box.addChild(mango)
+grid_box.addChild(yellow)
+grid_box.addChild(red2)
 
 main.addChild(grid_box)
-grid_box.setAnchor(0, 0.5, 0, 0.5)
-grid_box.setRaw(1)
+grid_box.setAnchor(0.5, 0.5, 0.5, 0.5)
+grid_box.setRaw(3)
+grid_box.setSeparator(16)
 
 
 addScene(main)