Skip to content

Commit

Permalink
Fixes #428
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Nov 3, 2023
1 parent 7267612 commit 359b1b2
Show file tree
Hide file tree
Showing 9 changed files with 831 additions and 56 deletions.
128 changes: 105 additions & 23 deletions samples/Myra.Samples.AllWidgets/AllWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,115 @@ public AllWidgets()
messageBox.ShowModal(Desktop);
};

var tree = new Tree
{
HasRoot = false
};
var tree = new TreeView();
Grid.SetColumn(tree, 1);
Grid.SetRow(tree, 12);
Grid.SetColumnSpan(tree, 2);

var node1 = tree.AddSubNode("node1");
var node2 = node1.AddSubNode("node2");
var node3 = node2.AddSubNode("node3");
node3.AddSubNode("node4");
node3.AddSubNode("node5");
node3.AddSubNode("node7");
node3.AddSubNode("node8");
node3.AddSubNode("node9");
node3.AddSubNode("node10");

var node4 = node2.AddSubNode("node6");
node4.AddSubNode("node11");
node4.AddSubNode("node12");
node4.AddSubNode("node13");
node4.AddSubNode("node14");
node4.AddSubNode("node15");
node4.AddSubNode("node16");
node4.AddSubNode("node17");
node4.AddSubNode("node18");
var node1 = tree.AddSubNode(new Label
{
Text = "node1"
});
var node2 = node1.AddSubNode(new Label
{
Text = "node2"
});

var node4 = node2.AddSubNode(new Label
{
Text = "node6"
});
node4.AddSubNode(new Label
{
Text = "node11"
});
node4.AddSubNode(new Label
{
Text = "node12"
});
node4.AddSubNode(new Label
{
Text = "node13"
});
node4.AddSubNode(new Label
{
Text = "node14"
});
node4.AddSubNode(new Label
{
Text = "node15"
});
node4.AddSubNode(new Label
{
Text = "node16"
});
node4.AddSubNode(new Label
{
Text = "node17"
});
node4.AddSubNode(new Label
{
Text = "node18"
});

var node3 = node2.AddSubNode(new CheckButton
{
Content = new Label
{
Text = "CheckButton node"
}
});
node3.AddSubNode(new Label
{
Text = "node4"
});
node3.AddSubNode(new CheckButton
{
Content = new Label { Text = "CheckButton node2" },
CheckPosition = CheckPosition.Right,
CheckContentSpacing = 8
});

var imageButtonContent = new HorizontalStackPanel
{
Spacing = 4
};

imageButtonContent.Widgets.Add(new Image
{
Renderable = DefaultAssets.UITextureRegionAtlas["icon-star"]
});

imageButtonContent.Widgets.Add(new Label
{
Text = "Button node"
});
node3.AddSubNode(new Button
{
Content = imageButtonContent
});
node3.AddSubNode(new HorizontalSlider());
node3.AddSubNode(new SpinButton());

var imageButtonContent2 = new HorizontalStackPanel
{
Spacing = 4
};

imageButtonContent2.Widgets.Add(new Label
{
Text = "ToggleButton node"
});
imageButtonContent2.Widgets.Add(new Image
{
Renderable = DefaultAssets.UITextureRegionAtlas["icon-star"]
});

node3.AddSubNode(new ToggleButton
{
Content = imageButtonContent2
});

_gridRight.Widgets.Add(tree);
}

Expand Down
127 changes: 104 additions & 23 deletions samples/Myra.Samples.CustomUIStylesheet/AllWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,113 @@ public AllWidgets()
debugWindow.ShowModal(Desktop);
};

var tree = new Tree
{
HasRoot = false,
};
var tree = new TreeView();
Grid.SetColumn(tree, 1);
Grid.SetRow(tree, 8);

var node1 = tree.AddSubNode("node1");
var node2 = node1.AddSubNode("node2");
var node3 = node2.AddSubNode("node3");
node3.AddSubNode("node4");
node3.AddSubNode("node5");
node3.AddSubNode("node7");
node3.AddSubNode("node8");
node3.AddSubNode("node9");
node3.AddSubNode("node10");

var node4 = node2.AddSubNode("node6");
node4.AddSubNode("node11");
node4.AddSubNode("node12");
node4.AddSubNode("node13");
node4.AddSubNode("node14");
node4.AddSubNode("node15");
node4.AddSubNode("node16");
node4.AddSubNode("node17");
node4.AddSubNode("node18");
var node1 = tree.AddSubNode(new Label
{
Text = "node1"
});
var node2 = node1.AddSubNode(new Label
{
Text = "node2"
});

var node4 = node2.AddSubNode(new Label
{
Text = "node6"
});
node4.AddSubNode(new Label
{
Text = "node11"
});
node4.AddSubNode(new Label
{
Text = "node12"
});
node4.AddSubNode(new Label
{
Text = "node13"
});
node4.AddSubNode(new Label
{
Text = "node14"
});
node4.AddSubNode(new Label
{
Text = "node15"
});
node4.AddSubNode(new Label
{
Text = "node16"
});
node4.AddSubNode(new Label
{
Text = "node17"
});
node4.AddSubNode(new Label
{
Text = "node18"
});

var node3 = node2.AddSubNode(new CheckButton
{
Content = new Label
{
Text = "CheckButton node"
}
});
node3.AddSubNode(new Label
{
Text = "node4"
});
node3.AddSubNode(new CheckButton
{
Content = new Label { Text = "CheckButton node2" },
CheckPosition = CheckPosition.Right,
CheckContentSpacing = 8
});

var imageButtonContent = new HorizontalStackPanel
{
Spacing = 4
};

imageButtonContent.Widgets.Add(new Image
{
Renderable = DefaultAssets.UITextureRegionAtlas["icon-star"]
});

imageButtonContent.Widgets.Add(new Label
{
Text = "Button node"
});
node3.AddSubNode(new Button
{
Content = imageButtonContent
});
node3.AddSubNode(new HorizontalSlider());

var imageButtonContent2 = new HorizontalStackPanel
{
Spacing = 4
};

imageButtonContent2.Widgets.Add(new Label
{
Text = "ToggleButton node"
});
imageButtonContent2.Widgets.Add(new Image
{
Renderable = DefaultAssets.UITextureRegionAtlas["icon-star"]
});

node3.AddSubNode(new ToggleButton
{
Content = imageButtonContent2
});

_gridRight.Widgets.Add(tree);
}
}
Expand Down
35 changes: 25 additions & 10 deletions samples/Myra.Samples.GridContainer/GridGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,34 @@ protected override void LoadContent()

grid.Widgets.Add(vsliderValue);

var tree = new Tree
{
HasRoot = false,
};
var tree = new TreeView();
Grid.SetColumn(tree, 3);
Grid.SetRow(tree, 4);

var node1 = tree.AddSubNode("node1");
var node2 = node1.AddSubNode("node2");
var node3 = node2.AddSubNode("node3");
node3.AddSubNode("node4");
node3.AddSubNode("node5");
node2.AddSubNode("node6");
var node1 = tree.AddSubNode(new Label
{
Text = "node1"
});
var node2 = node1.AddSubNode(new Label
{
Text = "node2"
});
var node3 = node2.AddSubNode(new Label
{
Text = "node3"
});
node3.AddSubNode(new Label
{
Text = "node4"
});
node3.AddSubNode(new Label
{
Text = "node5"
});
node2.AddSubNode(new Label
{
Text = "node6"
});

grid.Widgets.Add(tree);

Expand Down
2 changes: 2 additions & 0 deletions src/Myra/Graphics2D/UI/Containers/StackPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ protected StackPanel()
_proportions.CollectionChanged += (s, e) => InvalidateChildren();
}

public int GetCellSize(int index) => _layout.GetCellSize(index);

private void InvalidateChildren()
{
_childrenDirty = true;
Expand Down
5 changes: 5 additions & 0 deletions src/Myra/Graphics2D/UI/Layouts/StackPanelLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,10 @@ public void Arrange(IEnumerable<Widget> widgets, Rectangle bounds)
UpdateWidgets(widgets);
_layout.Arrange(widgets, bounds);
}

public int GetCellSize(int index)
{
return Orientation == Orientation.Horizontal ? _layout.GetColumnWidth(index) : _layout.GetRowHeight(index);
}
}
}
1 change: 1 addition & 0 deletions src/Myra/Graphics2D/UI/Misc/Tree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace Myra.Graphics2D.UI
{
[Obsolete("Use TreeView")]
public class Tree : TreeNode
{
private readonly List<TreeNode> _allNodes = new List<TreeNode>();
Expand Down
1 change: 1 addition & 0 deletions src/Myra/Graphics2D/UI/Misc/TreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Myra.Graphics2D.UI
{
[Obsolete("Use TreeView")]
public class TreeNode : Widget
{
private readonly SingleItemLayout<Grid> _layout;
Expand Down
Loading

0 comments on commit 359b1b2

Please sign in to comment.