public void VerticalStretch_OnContainer_HeightAsBigAsParent() { IWidget c = WidgetFactory.Container(100, 120); _root !.AddChild(c); c.WithProp(PropFactory.VerticalStretch()); TreeVisitor.ApplyPropsOnTree(_root); Assert.That(c.Space, Is.EqualTo(new RectangleF(0, 0, 100, 402))); }
public void ApplyProps_WidgetTree_Applies() { IWidget root = new Widget(RectangleF.Empty); Mock <IApplicableProp> mock = new Mock <IApplicableProp>(); root.WithProp(mock.Object); TreeVisitor.ApplyPropsOnTree(root); mock.Verify(p => p.ApplyOn(It.IsAny <IWidget>()), Times.Once); }
internal WTree(IWidget widgetRoot, IDevice device) { _userInteractionHandler = new UserInteractionHandler(device, new InteractionUpdater()); Root = widgetRoot; TreeVisitor.ApplyPropsOnTree(Root); TreeVisitor.ResetApplicationDoneFlags(Root); Log.Information( "Created new WTreeManager with root starting at ({X},{Y}) for ({W},{H}) of space", Root.Space.X, Root.Space.Y, Root.Space.Width, Root.Space.Height ); }
public void SingleChildWithBothTypeStretch_ShouldGetParentSize() { _root !.Space = new RectangleF(10, 10, 380, 382); _root !.WithProp(new Row()); IWidget c1 = WidgetFactory.Container(); _root !.AddChild(c1); c1.WithProp(new VerticalStretch()); c1.WithProp(new HorizontalStretch()); TreeVisitor.ApplyPropsOnTree(_root); Assert.That(c1.Space, Is.EqualTo(new RectangleF(10, 10, 380, 382))); }
public void VerticalStretch_OnColWithSiblings_AsBigAsCanBeRespectingSiblings() { IWidget c = WidgetFactory.Container(); _root !.AddChild(c); _root.WithProp(new Column()); c.WithProp(PropFactory.VerticalStretch()); IWidget c1 = WidgetFactory.Container(100, 120); _root !.AddChild(c1); TreeVisitor.ApplyPropsOnTree(_root); Assert.That(c.Space, Is.EqualTo(new RectangleF(0, 0, 0, 282))); }
public void ApplyOn_NotTextWidget_CascadesToChildren() { // arrange var root = WidgetFactory.Container(); var testWidget = (Text)WidgetFactory.Text("Test string"); root.AddChild(testWidget); var size = 14; // act root.WithProp(new FontSize(size)); TreeVisitor.ApplyPropsOnTree(root); // assert Assert.That(testWidget.FontSize, Is.EqualTo(size)); }
public void VerticalStretch_OnBothChildrenAndParentCentered_DoesNotFuckUp() { _root !.WithProp(new Column()); IWidget c1 = WidgetFactory.Container(); IWidget c2 = WidgetFactory.Container(); _root !.AddChild(c1); _root !.AddChild(c2); c1.WithProp(new VerticalStretch()); c2.WithProp(new VerticalStretch()); _root.WithProp(new JustifyCenter()); TreeVisitor.ApplyPropsOnTree(_root); Assert.That(c1.Space, Is.EqualTo(new RectangleF(0, 0, 0, 201))); Assert.That(c2.Space, Is.EqualTo(new RectangleF(0, 201, 0, 201))); }
public void ChildWithBothStretchAndFixedSibling_ShouldTakeAsMuchSpaceWhileRespecting() { _root !.Space = new RectangleF(10, 10, 380, 382); _root !.WithProp(new Column()); IWidget c1 = WidgetFactory.Container(); IWidget c2 = WidgetFactory.Container(15, 82); _root !.AddChild(c1); _root !.AddChild(c2); c1.WithProp(new VerticalStretch()); c1.WithProp(new HorizontalStretch()); TreeVisitor.ApplyPropsOnTree(_root); Assert.That(c1.Space, Is.EqualTo(new RectangleF(10, 10, 380, 300))); Assert.That(c2.Space, Is.EqualTo(new RectangleF(10, 310, 15, 82))); }
public void VerticalStretch_OnTwoMarginChildren_ParentCentered() { _root !.Space = new RectangleF(10, 10, 380, 382); _root !.WithProp(new Column()); IWidget c1 = WidgetFactory.Container(); IWidget c2 = WidgetFactory.Container(); _root !.AddChild(c1); _root !.AddChild(c2); c1.WithProp(new VerticalStretch()); c2.WithProp(new VerticalStretch()); _root.WithProp(new JustifyCenter()); TreeVisitor.ApplyPropsOnTree(_root); Assert.That(c1.Space, Is.EqualTo(new RectangleF(10, 10, 0, 191))); Assert.That(c2.Space, Is.EqualTo(new RectangleF(10, 201, 0, 191))); }
public void TwoChildrenWithBothStretch_ShouldDivideSpaceEqually() { _root !.Space = new RectangleF(10, 10, 380, 382); _root !.WithProp(new Row()); IWidget c1 = WidgetFactory.Container(); IWidget c2 = WidgetFactory.Container(15, 82); _root !.AddChild(c1); _root !.AddChild(c2); c1.WithProp(new VerticalStretch()); c1.WithProp(new HorizontalStretch()); c2.WithProp(new VerticalStretch()); c2.WithProp(new HorizontalStretch()); TreeVisitor.ApplyPropsOnTree(_root); Assert.That(c1.Space, Is.EqualTo(new RectangleF(10, 10, 190, 382))); Assert.That(c2.Space, Is.EqualTo(new RectangleF(200, 10, 190, 382))); }
public void OnACenteredColWithThreeWidgetsOfDiffSizes_CentersCorrectly() { var c = WidgetFactory.Container(20, 20); var c1 = WidgetFactory.Container(30, 40); var c2 = WidgetFactory.Container(20, 30); _root.AddChild(c); _root.AddChild(c1); _root.AddChild(c2); ApplyCol(); _root.WithProp(new JustifyCenter()); _root.WithProp(new ItemCenter()); TreeVisitor.ApplyPropsOnTree(_root); Assert.That(c.Space, Is.EqualTo(new RectangleF(630, 315, 20, 20))); Assert.That(c1.Space, Is.EqualTo(new RectangleF(625, 335, 30, 40))); Assert.That(c2.Space, Is.EqualTo(new RectangleF(630, 375, 20, 30))); }
public void VerticalAndHorizontal_WithMarginsAndChildren_YepItWorks() { _root !.Space = new RectangleF(0, 0, 380, 382); _root !.WithProp(new Row()); IWidget c1 = WidgetFactory.Container(); IWidget c2 = WidgetFactory.Container(15, 82); _root !.AddChild(c1); _root !.AddChild(c2); c1.WithProp(new VerticalStretch()).WithProp(PropFactory.Margin(0, 0, 10, 20)); c1.WithProp(new HorizontalStretch()); c2.WithProp(new VerticalStretch()).WithProp(PropFactory.Margin(10, 15, 0, 0)); c2.WithProp(new HorizontalStretch()); TreeVisitor.ApplyPropsOnTree(_root); Assert.That(c1.Space, Is.EqualTo(new RectangleF(0, 10, 190, 352))); Assert.That(c2.Space, Is.EqualTo(new RectangleF(200, 0, 165, 382))); }
public void VerticalStretch_WithTopBottomMargin_ItJustWorks() { // arrange var container = WidgetFactory.Container(100, 100); const int topMargin = 10; const int bottomMargin = 15; const int leftMargin = 5; container.WithProp(PropFactory.VerticalStretch()) .WithProp(PropFactory.Margin(leftMargin, 0, topMargin, bottomMargin)); _root !.AddChild(container); // act TreeVisitor.ApplyPropsOnTree(_root); // assert Assert.That(container.Space, Is.EqualTo(new RectangleF(leftMargin, topMargin, 100, 402 - topMargin - bottomMargin))); }
public void HorizontalStretch_WithLeftRightMargin_ItJustWorks() { // arrange var container = WidgetFactory.Container(100, 100); const int leftMargin = 10; const int rightMargin = 15; const int topMargin = 5; container.WithProp(PropFactory.HorizontalStretch()) .WithProp(PropFactory.Margin(leftMargin, rightMargin, topMargin, 0)); _root !.AddChild(container); // act TreeVisitor.ApplyPropsOnTree(_root); // assert Assert.That(container.Space, Is.EqualTo(new RectangleF(leftMargin, topMargin, 400 - leftMargin - rightMargin, 100))); }
public void ApplyProps_Tree_StartsFromRightLeaf() { IWidget root = new Widget(RectangleF.Empty); IWidget child = new Widget(RectangleF.Empty); IWidget rightChild = new Widget(RectangleF.Empty); Mock <IApplicableProp> mockRootProp = new Mock <IApplicableProp>(); Mock <IApplicableProp> mockLeftLeaf = new Mock <IApplicableProp>(); Mock <IApplicableProp> mockRightLeaf = new Mock <IApplicableProp>(); var firstCalled = 0; var lastCalled = 0; void SetVerification(int x) { if (firstCalled == 0) { firstCalled = x; } lastCalled = x; } mockRootProp.Setup(p => p.ApplyOn(It.IsAny <IWidget>())) .Callback(() => SetVerification(1)); mockLeftLeaf.Setup(p => p.ApplyOn(It.IsAny <IWidget>())) .Callback(() => SetVerification(2)); mockRightLeaf.Setup(p => p.ApplyOn(It.IsAny <IWidget>())) .Callback(() => SetVerification(3)); root.WithProp(mockRootProp.Object); child.WithProp(mockLeftLeaf.Object); rightChild.WithProp(mockRightLeaf.Object); root.AddChild(child); root.AddChild(rightChild); TreeVisitor.ApplyPropsOnTree(root); mockRootProp.Verify(p => p.ApplyOn(It.IsAny <IWidget>()), Times.Once); mockLeftLeaf.Verify(p => p.ApplyOn(It.IsAny <IWidget>()), Times.Once); mockRightLeaf.Verify(p => p.ApplyOn(It.IsAny <IWidget>()), Times.Once); Assert.That(lastCalled, Is.EqualTo(1)); Assert.That(firstCalled, Is.EqualTo(3)); }
public void ApplyOn_NotTextWidget_CascadesToChildren() { // arrange var root = WidgetFactory.Container(); var testWidget = (Text)WidgetFactory.Text("Test string"); root.AddChild(testWidget); var mockedFont = new Mock <Font>(null); FontStore.RegisterFont("mockF2", mockedFont.Object); var font = new FontFamily("mockF2"); // act root.WithProp(font); TreeVisitor.ApplyPropsOnTree(root); // assert Assert.That(testWidget.Font, Is.EqualTo(mockedFont.Object)); }
public void ApplyOn_WidgetWithTextChildren_DoesNotOverrideTextChildWithFontFamilyProp() { // arrange var root = WidgetFactory.Text("Root string"); var testWidget = WidgetFactory.Text("Test string"); root.AddChild(testWidget); var childSize = 15; var fontsize = new FontSize(14); var fontSizeChild = new FontSize(childSize); // act root.WithProp(fontsize); testWidget.WithProp(fontSizeChild); TreeVisitor.ApplyPropsOnTree(root); // assert Assert.That(((Text)testWidget).FontSize, Is.EqualTo(childSize)); }
public void ApplyProps_Tree_StartsFromLeaf() { IWidget root = new Widget(RectangleF.Empty); IWidget child = new Widget(RectangleF.Empty); Mock <IApplicableProp> mockRootProp = new Mock <IApplicableProp>(); Mock <IApplicableProp> mockChildProp = new Mock <IApplicableProp>(); var lastCalled = 0; mockRootProp.Setup(p => p.ApplyOn(It.IsAny <IWidget>())).Callback(() => lastCalled = 1); mockChildProp.Setup(p => p.ApplyOn(It.IsAny <IWidget>())).Callback(() => lastCalled = 2); root.WithProp(mockRootProp.Object); child.WithProp(mockChildProp.Object); root.AddChild(child); TreeVisitor.ApplyPropsOnTree(root); mockRootProp.Verify(p => p.ApplyOn(It.IsAny <IWidget>()), Times.Once); mockChildProp.Verify(p => p.ApplyOn(It.IsAny <IWidget>()), Times.Once); Assert.That(lastCalled, Is.EqualTo(1)); }
public void ApplyOn_WidgetWithTextChildren_DoesNotOverrideTextChildWithFontFamilyProp() { // arrange var root = WidgetFactory.Container(); var testWidget = WidgetFactory.Text("Test string"); root.AddChild(testWidget); FontStore.RegisterFont("mockF3", new Mock <Font>(null).Object); var font = new FontFamily("mockF3"); var mockedFont = new Mock <Font>(null); FontStore.RegisterFont("mockF4", mockedFont.Object); var fontChild = new FontFamily("mockF4"); // act root.WithProp(font); testWidget.WithProp(fontChild); TreeVisitor.ApplyPropsOnTree(root); // assert Assert.That(((Text)testWidget).Font, Is.EqualTo(mockedFont.Object)); }
public static void ApplyProps(IWidget widget) => TreeVisitor.ApplyPropsOnTree(widget);
/// <summary> /// Resize the space in which the WidgetTree is located. /// </summary> /// <param name="width"></param> /// <param name="height"></param> public void Resize(int width, int height) { Root.Space = new RectangleF(Root.Space.X, Root.Space.Y, width, height); TreeVisitor.ApplyPropsOnTree(Root); }