To add desiging for a new View property update the IEnumerable<Property> LoadDesignableProperties()
method.
For example:
if(View is ScrollView)
{
yield return CreateProperty(nameof(ScrollView.ContentSize));
}
Adding a new 'round trip' test to confirm that the property is serialized/loaded correctly:
[Test]
public void TestRoundTrip_PreserveContentSize()
{
var scrollViewIn = RoundTrip<ScrollView>((s) =>
s.ContentSize = new Size(10, 5)
);
Assert.AreEqual(10, scrollViewIn.ContentSize.Width);
Assert.AreEqual(5, scrollViewIn.ContentSize.Height);
}
If you need to add support for a new Type
of Property (e.g. ContentSize
property is of Type Size
) then you must do the following:
- Update Property
virtual CodeExpression GetRhs()
:
if(val is Size s)
{
return new CodeSnippetExpression(s.ToCode());
}
Provide an implementation of ToCode
as an Extension Method on the new Type
public static class SizeExtensions
{
public static string ToCode(this Size s)
{
return $"new Size({s.Width},{s.Height})";
}
}
This should make the 'round trip' test (see above) pass. But you will still need to add designer UI support for editing the Type.
Create a new Dialog
for the new Type
in TerminalGuiDesigner.UI.Windows
. Use TerminalGuiDesigner to create the form.
For example see SizeEditor.Designer.cs
/ SizeEditor.cs
Update EditDialog.cs
method GetNewValue
to call the new editor window: