static Box CreateBoxFromYogaNode(YogaNode node, Action <YogaNode, Box> decor) { CustomWidgets.Box fb0 = new CustomWidgets.Box(100, 100) { LayoutInstance = node.ToLayoutInstance() }; decor(node, fb0); foreach (YogaNode child in node) { fb0.Add(CreateBoxFromYogaNode(child, decor)); } return(fb0); }
void InitCornerControlBoxes() { _boxLeftTop = new UIControllerBox(20, 20) { BackColor = Color.Yellow, Visible = false }; SetupCorner_Controller(_boxLeftTop); _boxLeftTop.MouseDrag += (s1, e1) => { //move other boxes ... AbstractRectUI target1 = _boxLeftTop.TargetBox; //update target if (target1 != null) { target1.SetLocationAndSize( _boxLeftTop.Right, _boxLeftTop.Bottom, _boxRightTop.Left - _boxLeftTop.Right, _boxRightBottom.Top - _boxLeftTop.Bottom); //update other controller UpdateControllerBoxes(target1); } }; _groundBox.Add(_boxLeftTop); //------------ _boxLeftBottom = new UIControllerBox(20, 20) { BackColor = Color.Yellow, Visible = false }; SetupCorner_Controller(_boxLeftBottom); _boxLeftBottom.MouseDrag += (s1, e1) => { AbstractRectUI target1 = _boxLeftBottom.TargetBox; //update target if (target1 != null) { target1.SetLocationAndSize(_boxLeftBottom.Right, _boxLeftTop.Bottom, _boxRightTop.Left - _boxLeftBottom.Right, _boxLeftBottom.Top - _boxLeftTop.Bottom); //update other controller UpdateControllerBoxes(target1); } }; _groundBox.Add(_boxLeftBottom); //------------ _boxRightTop = new UIControllerBox(20, 20) { BackColor = Color.Yellow, Visible = false }; SetupCorner_Controller(_boxRightTop); _boxRightTop.MouseDrag += (s1, e1) => { AbstractRectUI target1 = _boxRightTop.TargetBox; //update target if (target1 != null) { target1.SetLocationAndSize( _boxLeftTop.Right, _boxRightTop.Bottom, _boxRightTop.Left - _boxLeftTop.Right, _boxRightBottom.Top - _boxRightTop.Bottom); //update other controllers UpdateControllerBoxes(target1); } }; _groundBox.Add(_boxRightTop); //------------ _boxRightBottom = new UIControllerBox(20, 20) { BackColor = Color.Yellow, Visible = false }; SetupCorner_Controller(_boxRightBottom); _boxRightBottom.MouseDrag += (s1, e1) => { OnUpdateShape(); //rotate all other control points //AbstractRectUI target1 = _boxRightBottom.TargetBox; ////update target //if (target1 != null) //{ // target1.SetLocationAndSize(_boxLeftTop.Right, // _boxLeftTop.Bottom, // _boxRightBottom.Left - _boxLeftTop.Right, // _boxRightBottom.Top - _boxLeftTop.Bottom); // //update other controllers // UpdateControllerBoxes(target1); //} }; _groundBox.Add(_boxRightBottom); //------------ }
void Init2() { YogaConfig config = new YogaConfig(); _rootNode = new YogaNode(config) { FlexDirection = YogaFlexDirection.Column, Width = _rootPanel.Width, Height = _rootPanel.Height, Padding = 20, AlignItems = YogaAlign.Stretch }; var _root_child0 = new YogaNode(config) { FlexDirection = YogaFlexDirection.Row, Width = _rootNode.Width, Height = 100, AlignItems = YogaAlign.Center, AlignSelf = YogaAlign.Center, Flex = 1, FlexShrink = 1, StyleDirection = YogaDirection.RightToLeft }; _rootNode.Insert(0, _root_child0); YogaNode c1r0_child0 = new YogaNode(config) { Width = 100, Height = 100, FlexShrink = 1 }; _root_child0.Insert(0, c1r0_child0); YogaNode c1r0_child1 = new YogaNode(config) { Width = 100, Height = 100, MarginHorizontal = 20, FlexGrow = 1, FlexShrink = 1 }; _root_child0.Insert(1, c1r0_child1); YogaNode c1r0_child2 = new YogaNode(config) { Width = 100, Height = 100, FlexShrink = 1 }; _root_child0.Insert(2, c1r0_child2); YogaNode root_child1 = new YogaNode(config) { Width = 100, Height = 100, MarginHorizontal = 20, FlexGrow = 1, FlexShrink = 1 }; _rootNode.Insert(1, root_child1); //YogaNode root_child2 = new YogaNode(config); //root_child2.Width = 100; //root_child2.Height = 100; //root_child2.FlexShrink = 1; //root.Insert(2, root_child2); _rootNode.StyleDirection = YogaDirection.LeftToRight; _rootNode.CalculateLayout(); CustomWidgets.Box fb0 = new CustomWidgets.Box(100, 100) { BackColor = PixelFarm.Drawing.Color.Yellow, LayoutInstance = _root_child0.ToLayoutInstance() }; _rootPanel.Add(fb0); CustomWidgets.Box fb0_child0 = new CustomWidgets.Box(100, 100) { BackColor = PixelFarm.Drawing.Color.Blue, LayoutInstance = c1r0_child0.ToLayoutInstance() }; fb0.Add(fb0_child0); CustomWidgets.Box fb0_child1 = new CustomWidgets.Box(100, 100) { BackColor = PixelFarm.Drawing.Color.Blue, LayoutInstance = c1r0_child1.ToLayoutInstance() }; fb0.Add(fb0_child1); CustomWidgets.Box fb0_child2 = new CustomWidgets.Box(100, 100) { BackColor = PixelFarm.Drawing.Color.Blue, LayoutInstance = c1r0_child2.ToLayoutInstance() }; fb0.Add(fb0_child2); CustomWidgets.Box fb1 = new CustomWidgets.Box(100, 100) { BackColor = PixelFarm.Drawing.Color.Red, LayoutInstance = root_child1.ToLayoutInstance() }; _rootPanel.Add(fb1); _rootPanel.UpdateLayout(); }
void Init1() { YogaConfig config = new YogaConfig(); _rootNode = new YogaNode(config) { FlexDirection = YogaFlexDirection.Row, Width = _rootPanel.Width, Height = _rootPanel.Height, Padding = 20, AlignItems = YogaAlign.Center }; YogaNode root_child0 = new YogaNode(config) { Width = 100, Height = 100, FlexShrink = 1 }; _rootNode.Insert(0, root_child0); YogaNode root_child1 = new YogaNode(config) { Width = 100, Height = 100, MarginHorizontal = 20, FlexGrow = 1, FlexShrink = 1 }; _rootNode.Insert(1, root_child1); YogaNode root_child2 = new YogaNode(config) { Width = 100, Height = 100, FlexShrink = 1 }; _rootNode.Insert(2, root_child2); _rootNode.StyleDirection = YogaDirection.LeftToRight; _rootNode.CalculateLayout(); CustomWidgets.Box fb0 = new CustomWidgets.Box(100, 100) { BackColor = PixelFarm.Drawing.Color.Blue, LayoutInstance = root_child0.ToLayoutInstance() }; _rootPanel.Add(fb0); CustomWidgets.Box fb1 = new CustomWidgets.Box(100, 100) { BackColor = PixelFarm.Drawing.Color.Red, LayoutInstance = root_child1.ToLayoutInstance() }; _rootPanel.Add(fb1); CustomWidgets.Box fb2 = new CustomWidgets.Box(100, 100) { BackColor = PixelFarm.Drawing.Color.Blue, LayoutInstance = root_child2.ToLayoutInstance() }; _rootPanel.Add(fb2); _rootPanel.UpdateLayout(); }