Skip to content

Commit

Permalink
Removed SingleItemContainer for real
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Oct 26, 2023
1 parent 1a30201 commit 6163de7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 104 deletions.
14 changes: 8 additions & 6 deletions src/Myra/Graphics2D/UI/Properties/CollectionEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

namespace Myra.Graphics2D.UI.Properties
{
public class CollectionEditor : SingleItemContainer<VerticalStackPanel>
public class CollectionEditor : Widget
{
private readonly StackPanelLayout _layout = new StackPanelLayout(Orientation.Vertical);
private readonly IList _collection;
private readonly Type _type;
private readonly ListBox _listItems;
Expand All @@ -13,14 +14,15 @@ public class CollectionEditor : SingleItemContainer<VerticalStackPanel>

public CollectionEditor(IList collection, Type type)
{
ChildrenLayout = _layout;

Width = 500;
Height = 400;

_collection = collection;
_type = type;

InternalChild = new VerticalStackPanel();
InternalChild.Widgets.Add(new HorizontalSeparator());
Children.Add(new HorizontalSeparator());

var splitPanel = new HorizontalSplitPane();
StackPanel.SetProportionType(splitPanel, ProportionType.Fill);
Expand All @@ -46,8 +48,8 @@ public CollectionEditor(IList collection, Type type)
_propertyGrid.PropertyChanged += PropertyGridOnPropertyChanged;
splitPanel.Widgets.Add(_propertyGrid);

InternalChild.Widgets.Add(splitPanel);
InternalChild.Widgets.Add(new HorizontalSeparator());
Children.Add(splitPanel);
Children.Add(new HorizontalSeparator());

var buttonsGrid = new Grid
{
Expand Down Expand Up @@ -80,7 +82,7 @@ public CollectionEditor(IList collection, Type type)
_buttonMoveDown.Click += ButtonMoveDownOnUp;
buttonsGrid.Widgets.Add(_buttonMoveDown);

InternalChild.Widgets.Add(buttonsGrid);
Children.Add(buttonsGrid);

UpdateButtonsEnabled();
}
Expand Down
78 changes: 41 additions & 37 deletions src/Myra/Graphics2D/UI/Properties/PropertyGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
using System.Xml.Serialization;
using Myra.MML;
using Myra.Graphics2D.UI.File;
using Myra.Graphics2D.TextureAtlases;
using System.IO;
using Myra.Attributes;
using FontStashSharp;
using FontStashSharp.RichText;
using Myra.Graphics2D.Brushes;
using AssetManagementBase;
using System.Xml;

#if MONOGAME || FNA
using Microsoft.Xna.Framework;
Expand All @@ -32,12 +30,16 @@

namespace Myra.Graphics2D.UI.Properties
{
public class PropertyGrid : SingleItemContainer<Grid>
public class PropertyGrid : Widget
{
private readonly GridLayout _layout = new GridLayout();

private const string DefaultCategoryName = "Miscellaneous";

private class SubGrid : SingleItemContainer<Grid>
private class SubGrid : Widget
{
private readonly GridLayout _layout = new GridLayout();

private readonly ToggleButton _mark;
private readonly PropertyGrid _propertyGrid;

Expand All @@ -55,7 +57,7 @@ public Rectangle HeaderBounds
{
get
{
var headerBounds = new Rectangle(0, 0, ActualBounds.Width, InternalChild.GetRowHeight(0));
var headerBounds = new Rectangle(0, 0, ActualBounds.Width, _layout.GetRowHeight(0));

return headerBounds;
}
Expand All @@ -73,16 +75,15 @@ public bool IsEmpty

public SubGrid(PropertyGrid parent, object value, string header, string category, string filter, Record parentProperty)
{
InternalChild = new Grid
{
ColumnSpacing = 4,
RowSpacing = 4
};
ChildrenLayout = _layout;

InternalChild.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
InternalChild.ColumnsProportions.Add(new Proportion(ProportionType.Fill));
InternalChild.RowsProportions.Add(new Proportion(ProportionType.Auto));
InternalChild.RowsProportions.Add(new Proportion(ProportionType.Auto));
_layout.ColumnSpacing = 4;
_layout.RowSpacing = 4;

_layout.ColumnsProportions.Add(new Proportion(ProportionType.Auto));
_layout.ColumnsProportions.Add(new Proportion(ProportionType.Fill));
_layout.RowsProportions.Add(new Proportion(ProportionType.Auto));
_layout.RowsProportions.Add(new Proportion(ProportionType.Auto));

_propertyGrid = new PropertyGrid(parent.PropertyGridStyle, category, parentProperty, parent)
{
Expand All @@ -108,18 +109,18 @@ public SubGrid(PropertyGrid parent, object value, string header, string category
Content = markImage
};

InternalChild.Widgets.Add(_mark);
Children.Add(_mark);

_mark.PressedChanged += (sender, args) =>
{
if (_mark.IsPressed)
{
InternalChild.Widgets.Add(_propertyGrid);
Children.Add(_propertyGrid);
parent._expandedCategories.Add(category);
}
else
{
InternalChild.Widgets.Remove(_propertyGrid);
Children.Remove(_propertyGrid);
parent._expandedCategories.Remove(category);
}
};
Expand All @@ -142,7 +143,7 @@ public SubGrid(PropertyGrid parent, object value, string header, string category
Grid.SetColumn(label, 1);
label.ApplyLabelStyle(parent.PropertyGridStyle.LabelStyle);

InternalChild.Widgets.Add(label);
Children.Add(label);

HorizontalAlignment = HorizontalAlignment.Stretch;
VerticalAlignment = VerticalAlignment.Stretch;
Expand Down Expand Up @@ -264,7 +265,7 @@ public bool IsEmpty
{
get
{
return InternalChild.Widgets.Count == 0;
return Children.Count == 0;
}
}

Expand All @@ -289,12 +290,12 @@ public int FirstColumnWidth
{
get
{
return (int)InternalChild.ColumnsProportions[0].Value;
return (int)_layout.ColumnsProportions[0].Value;
}

set
{
InternalChild.ColumnsProportions[0].Value = value;
_layout.ColumnsProportions[0].Value = value;
}
}

Expand Down Expand Up @@ -345,14 +346,15 @@ public string Filter

private PropertyGrid(TreeStyle style, string category, Record parentProperty, PropertyGrid parentGrid = null)
{
ChildrenLayout = _layout;

_parentGrid = parentGrid;
InternalChild = new Grid();

_parentProperty = parentProperty;
InternalChild.ColumnSpacing = 8;
InternalChild.RowSpacing = 8;
InternalChild.ColumnsProportions.Add(new Proportion(ProportionType.Part, 1));
InternalChild.ColumnsProportions.Add(new Proportion(ProportionType.Part, 1));
_layout.ColumnSpacing = 8;
_layout.RowSpacing = 8;
_layout.ColumnsProportions.Add(new Proportion(ProportionType.Part, 1));
_layout.ColumnsProportions.Add(new Proportion(ProportionType.Part, 1));

Category = category;

Expand Down Expand Up @@ -911,7 +913,8 @@ private Grid CreateFileEditor<T>(Record record, bool hasSetter, string filter, F
if (baseObject != null)
{
baseObject.Resources.TryGetValue(record.Name, out path);
} else if (Settings.ImagePropertyValueGetter != null)
}
else if (Settings.ImagePropertyValueGetter != null)
{
path = Settings.ImagePropertyValueGetter(record.Name);
}
Expand Down Expand Up @@ -981,7 +984,8 @@ private Grid CreateFileEditor<T>(Record record, bool hasSetter, string filter, F
if (baseObject != null)
{
baseObject.Resources[record.Name] = filePath;
} else if (Settings.ImagePropertyValueSetter != null)
}
else if (Settings.ImagePropertyValueSetter != null)
{
Settings.ImagePropertyValueSetter(record.Name, filePath);
}
Expand Down Expand Up @@ -1215,10 +1219,10 @@ private void FillSubGrid(ref int y, IReadOnlyList<Record> records)
Grid.SetColumnSpan(subGrid, 2);
Grid.SetRow(subGrid, y);

InternalChild.Widgets.Add(subGrid);
Children.Add(subGrid);

rowProportion = new Proportion(ProportionType.Auto);
InternalChild.RowsProportions.Add(rowProportion);
_layout.RowsProportions.Add(rowProportion);
++y;
}

Expand Down Expand Up @@ -1258,17 +1262,17 @@ private void FillSubGrid(ref int y, IReadOnlyList<Record> records)
Grid.SetColumn(nameLabel, 0);
Grid.SetRow(nameLabel, oldY);

InternalChild.Widgets.Add(nameLabel);
Children.Add(nameLabel);

Grid.SetColumn(valueWidget, 1);
Grid.SetRow(valueWidget, oldY);
valueWidget.HorizontalAlignment = HorizontalAlignment.Stretch;
valueWidget.VerticalAlignment = VerticalAlignment.Top;

InternalChild.Widgets.Add(valueWidget);
Children.Add(valueWidget);

rowProportion = new Proportion(ProportionType.Auto);
InternalChild.RowsProportions.Add(rowProportion);
_layout.RowsProportions.Add(rowProportion);
++y;
}
}
Expand All @@ -1285,8 +1289,8 @@ public bool PassesFilter(string name)

public void Rebuild()
{
InternalChild.RowsProportions.Clear();
InternalChild.Widgets.Clear();
_layout.RowsProportions.Clear();
Children.Clear();
_records.Clear();
_expandedCategories.Clear();

Expand Down Expand Up @@ -1434,15 +1438,15 @@ public void Rebuild()
continue;
}

InternalChild.Widgets.Add(subGrid);
Children.Add(subGrid);

if (_expandedCategories.Contains(category.Key))
{
subGrid.Mark.IsPressed = true;
}

var rp = new Proportion(ProportionType.Auto);
InternalChild.RowsProportions.Add(rp);
_layout.RowsProportions.Add(rp);

y++;
}
Expand Down
61 changes: 0 additions & 61 deletions src/Myra/Graphics2D/UI/SingleItemContainer.cs

This file was deleted.

0 comments on commit 6163de7

Please sign in to comment.