Well, again I was confounded by something I thought to be easy but finally came up with a solution. It’s not the small elegant change I’d envisioned, just couldn’t figure that out.
Instead this uses 2 methods: ArrangeDown (the original Arrange) and ArrangeRight (xy swapped). To get Up and Left I added method invertPosition. This simply moves node centers to the other side. So, to arrange in the up direction first ArrangeDown then go through and calculate Center.Y = TreeHeight - Center.Y for each node which mirrors it about the midline.
DrawSubtreeLinks was split into horizontal and vertical versions too. And the g parameter was removed from the interface and other places where I didn’t see it being used. The direction choice is an integer for laziness but should be an Enumeration.
http://trochoid.weebly.com/uploads/6/2/6/4/62644133/treenodedirectional.zip
[code]Public Sub Arrange(ByRef x As Integer, ByRef y As Integer, direction As integer)
Select Case direction
Case 0 //Down
ArrangeDown( x, y )
Case 1 //Right
ArrangeRight( x, y )
Case 2 //Up
ArrangeDown( x, y )
invertPosition( x, y, direction )
Case 3 //Left
ArrangeRight( x, y )
invertPosition( x, y, direction )
End
End Sub
Private Sub invertPosition(spanX As integer, spanY As integer, direction As integer)
if direction mod 2 = 0 then //up down
Center = new Xojo.Core.Point( Center.X, spanY - Center.Y )
else //left right
Center = new Xojo.Core.Point( spanX - Center.X, Center.Y )
end
for i As integer = 0 to Children.Ubound
Children(i).invertPosition( spanX, spanY, direction )
next
End Sub[/code]
I still think a single recursive Arrange method solution is possible and thought someone would’ve spotted it by now. It’s something I’ll continue to look at in my spare time for a puzzle, at least to identify why I’m not solving it.