Skip to content

Commit

Permalink
WPF layout (space-wizards#1581)
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 authored Feb 21, 2021
1 parent 771a256 commit 583b7eb
Show file tree
Hide file tree
Showing 87 changed files with 1,699 additions and 835 deletions.
4 changes: 2 additions & 2 deletions Robust.Client.Injectors/MathParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public static class MathParsing
public static Parser<char, float[]> Thickness { get; }
= SkipWhitespaces.Then(
OneOf(
Try(Single1.Select(c => new[] {c})),
Try(Single4.Select(c => new[] {c.Item1, c.Item2, c.Item3, c.Item4})),
Try(Single2.Select(c => new[] {c.Item1, c.Item2})),
Try(Single4.Select(c => new[] {c.Item1, c.Item2, c.Item3, c.Item4}))
Try(Single1.Select(c => new[] {c}))
));
}
}
32 changes: 32 additions & 0 deletions Robust.Client.Injectors/RXamlColorAstNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Reflection.Emit;
using XamlX.Ast;
using XamlX.Emit;
using XamlX.IL;
using XamlX.TypeSystem;

namespace Robust.Build.Tasks
{
internal class RXamlColorAstNode
: XamlAstNode, IXamlAstValueNode, IXamlAstILEmitableNode
{
private readonly IXamlMethod _method;
private readonly string _color;

public RXamlColorAstNode(IXamlLineInfo lineInfo, RXamlWellKnownTypes types, string color) : base(lineInfo)
{
_color = color;
Type = new XamlAstClrTypeReference(lineInfo, types.Color, false);
_method = types.ColorFromXaml;
}

public IXamlAstTypeReference Type { get; }

public XamlILNodeEmitResult Emit(XamlEmitContext<IXamlILEmitter, XamlILNodeEmitResult> context, IXamlILEmitter codeGen)
{
codeGen.Ldstr(_color);
codeGen.EmitCall(_method);

return XamlILNodeEmitResult.Type(0, Type.GetClrType());
}
}
}
11 changes: 11 additions & 0 deletions Robust.Client.Injectors/RXamlWellKnownTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class RXamlWellKnownTypes
public IXamlConstructor Vector2ConstructorFull { get; }
public IXamlType Vector2i { get; }
public IXamlConstructor Vector2iConstructorFull { get; }
public IXamlType Thickness { get; }
public IXamlConstructor ThicknessConstructorFull { get; }
public IXamlType Color { get; }
public IXamlMethod ColorFromXaml { get; }

public RXamlWellKnownTypes(TransformerConfiguration cfg)
{
Expand All @@ -23,6 +27,7 @@ public RXamlWellKnownTypes(TransformerConfiguration cfg)

(Vector2, Vector2ConstructorFull) = GetNumericTypeInfo("Robust.Shared.Maths.Vector2", Single, 2);
(Vector2i, Vector2iConstructorFull) = GetNumericTypeInfo("Robust.Shared.Maths.Vector2i", Int32, 2);
(Thickness, ThicknessConstructorFull) = GetNumericTypeInfo("Robust.Shared.Maths.Thickness", Single, 4);

(IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount)
{
Expand All @@ -31,6 +36,12 @@ public RXamlWellKnownTypes(TransformerConfiguration cfg)

return (type, ctor);
}

Color = cfg.TypeSystem.GetType("Robust.Shared.Maths.Color");
ColorFromXaml = Color.GetMethod(new FindMethodMethodSignature("FromXaml", Color, XamlIlTypes.String)
{
IsStatic = true
});
}
}

Expand Down
71 changes: 71 additions & 0 deletions Robust.Client.Injectors/XamlCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,77 @@ private static bool CustomValueConverter(
return true;
}

if (type.Equals(types.Thickness))
{
var foo = MathParsing.Thickness.Parse(text);

if (!foo.Success)
throw new XamlLoadException($"Unable to parse \"{text}\" as a Thickness", node);

var val = foo.Value;
float[] full;
if (val.Length == 1)
{
var u = val[0];
full = new[] {u, u, u, u};
}
else if (val.Length == 2)
{
var h = val[0];
var v = val[1];
full = new[] {h, v, h, v};
}
else // 4
{
full = val;
}

result = new RXamlSingleVecLikeConstAstNode(
node,
types.Thickness, types.ThicknessConstructorFull,
types.Single, full);
return true;
}

if (type.Equals(types.Thickness))
{
var foo = MathParsing.Thickness.Parse(text);

if (!foo.Success)
throw new XamlLoadException($"Unable to parse \"{text}\" as a Thickness", node);

var val = foo.Value;
float[] full;
if (val.Length == 1)
{
var u = val[0];
full = new[] {u, u, u, u};
}
else if (val.Length == 2)
{
var h = val[0];
var v = val[1];
full = new[] {h, v, h, v};
}
else // 4
{
full = val;
}

result = new RXamlSingleVecLikeConstAstNode(
node,
types.Thickness, types.ThicknessConstructorFull,
types.Single, full);
return true;
}

if (type.Equals(types.Color))
{
// TODO: Interpret these colors at XAML compile time instead of at runtime.
result = new RXamlColorAstNode(node, types, text);
return true;
}

result = null;
return false;
}
Expand Down
31 changes: 28 additions & 3 deletions Robust.Client/Console/Commands/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
{
_writeNode(root, 0, writer);
}

shell.WriteLine("Saved guidump");
}

private static void _writeNode(Control control, int indents, TextWriter writer)
Expand Down Expand Up @@ -542,7 +544,7 @@ internal class UITestCommand : IConsoleCommand

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var window = new SS14Window { CustomMinimumSize = (500, 400)};
var window = new SS14Window { MinSize = (500, 400)};
var tabContainer = new TabContainer();
window.Contents.AddChild(tabContainer);
var scroll = new ScrollContainer();
Expand All @@ -562,7 +564,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
optionButton.OnItemSelected += eventArgs => optionButton.SelectId(eventArgs.Id);
vBox.AddChild(optionButton);

var tree = new Tree { SizeFlagsVertical = Control.SizeFlags.FillExpand };
var tree = new Tree { VerticalExpand = true };
var root = tree.CreateItem();
root.Text = "Honk!";
var child = tree.CreateItem();
Expand Down Expand Up @@ -599,7 +601,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
{
grid.AddChild(new Button
{
CustomMinimumSize = (50, 50),
MinSize = (50, 50),
Text = $"{x}, {y}"
});
}
Expand Down Expand Up @@ -631,6 +633,29 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
}
});

tabContainer.AddChild(new HSplitContainer
{
Children =
{
new PanelContainer
{
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.Red},
Children =
{
new Label{ Text = "FOOBARBAZ"},
}
},
new PanelContainer
{
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.Blue},
Children =
{
new Label{ Text = "FOOBARBAZ"},
}
},
}
});

window.OpenCentered();
}
}
Expand Down
14 changes: 7 additions & 7 deletions Robust.Client/Console/WatchWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class WatchWindow : SS14Window
{
private readonly IReflectionManager _reflectionManager;

protected override Vector2? CustomSize => (300, 300);

private readonly VBoxContainer _watchesVBox;
private readonly LineEdit _addWatchEdit;
private readonly Button _addWatchButton;
Expand All @@ -37,20 +35,20 @@ public WatchWindow()

var mainVBox = new VBoxContainer
{
CustomMinimumSize = (500, 300),
MinSize = (500, 300),
Children =
{
(_watchesVBox = new VBoxContainer
{
SizeFlagsVertical = SizeFlags.FillExpand
VerticalExpand = true
}),
new HBoxContainer
{
Children =
{
(_addWatchEdit = new HistoryLineEdit
{
SizeFlagsHorizontal = SizeFlags.FillExpand,
HorizontalExpand = true,
PlaceHolder = Loc.GetString("Add watch (C# interactive)")
}),
(_addWatchButton = new Button
Expand All @@ -66,6 +64,8 @@ public WatchWindow()
_addWatchEdit.OnTextEntered += _ => AddWatch();

Contents.AddChild(mainVBox);

SetSize = (300, 300);
}

private void AddWatch()
Expand Down Expand Up @@ -113,7 +113,7 @@ public WatchControl(ScriptRunner<object> runner)
{
(_outputLabel = new Label
{
SizeFlagsHorizontal = SizeFlags.FillExpand,
HorizontalExpand = true,
ClipText = true
}),
(delButton = new Button
Expand Down Expand Up @@ -176,7 +176,7 @@ public CompilationErrorControl(string message)
{
Text = message,
ClipText = true,
SizeFlagsHorizontal = SizeFlags.FillExpand
HorizontalExpand = true
},
(delButton = new Button {Text = Loc.GetString("Remove")})
}
Expand Down
Loading

0 comments on commit 583b7eb

Please sign in to comment.