public void OnMultipleCenteredCols_Centers() { var c = WidgetFactory.Container(1120, 20); var c1 = WidgetFactory.Container(100, 40); var c2 = WidgetFactory.Container(120, 30); _root.AddChild(c); _root.AddChild(c1); _root.AddChild(c2); ApplyCol(); ((IApplicableProp)PropFactory.JustifyCenter()).ApplyOn(_root); _itemCenter.ApplyOn(_root); Assert.That(c.Space, Is.EqualTo(new RectangleF(80, 315, 1120, 20))); Assert.That(c1.Space, Is.EqualTo(new RectangleF(590, 335, 100, 40))); Assert.That(c2.Space, Is.EqualTo(new RectangleF(580, 375, 120, 30))); }
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 PressOnWidget_ThenEnterAnother_OldDoesNotRelease() { // Press the interaction button _device.Setup(device => device.IsPressed()).Returns(true); _handler.Device = _device.Object; // Press widget _handler.UpdateAndGenerateTransitions(_widgetTree); _device.Setup(device => device.IsPressed()).Returns(false); _device.Setup(device => device.IsHeld()).Returns(true); _handler.Device = _device.Object; // Move while pressing to another widget _handler.UpdateAndGenerateTransitions(WidgetFactory.Container()); _intRun.Verify(r => r.NextState(_widgetTree, Interaction.Released), Times.Never); }
public void PressOnWidget_ThenEnterAnother_OldDoesGenerateOnExitCommands() { // Press the interaction button _device.Setup(device => device.IsPressed()).Returns(true); _handler.Device = _device.Object; _handler.Updater = new InteractionUpdater(); // Press widget _handler.UpdateAndGenerateTransitions(_widgetTree); _device.Setup(device => device.IsPressed()).Returns(false); _device.Setup(device => device.IsHeld()).Returns(true); _handler.Device = _device.Object; // Move while pressing to another widget var l = _handler.UpdateAndGenerateTransitions(WidgetFactory.Container()); Assert.That(l, Is.Empty); }
public void OnMultipleRows_OffsetsCorrectly() { _root = WidgetFactory.Container(new RectangleF(0, 0, 1280, 720)); var c = WidgetFactory.Container(800, 20); var c1 = WidgetFactory.Container(300, 40); var c2 = WidgetFactory.Container(300, 40); _root.AddChild(c); _root.AddChild(c1); _root.AddChild(c2); _root.WithProp(PropFactory.Row()); _root.WithProp(PropFactory.JustifyEnd()); _root.WithProp(PropFactory.ItemBase()); ApplyProps(_root); Assert.That(c.Space, Is.EqualTo(new RectangleF(180, 660, 800, 20))); Assert.That(c1.Space, Is.EqualTo(new RectangleF(980, 640, 300, 40))); Assert.That(c2.Space, Is.EqualTo(new RectangleF(980, 680, 300, 40))); }
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 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 ApplyOn_RowWithColWithWidgets_TotallyCentered() { IWidget col = WidgetFactory.Container(200, 600); _root.AddChild(col); var innerChild = WidgetFactory.Container(100, 300); col.AddChild(innerChild); col.WithProp(PropFactory.Column()); ApplyProps(col); ApplyRow(); _justifyCenter.ApplyOn(_root); _justifyCenter.ApplyOn(col); Assert.That(col.Space, Is.EqualTo(new RectangleF(540, 0, 200, 600))); Assert.That(innerChild.Space, Is.EqualTo(new RectangleF(540, 150, 100, 300))); }
public void ApplyOn_ThreeColumnsPlusOneWidget_TheLastOnBeginningOfColumn() { var acts = new[] { // First Col WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), // Second Col WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), // Third Col WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), // The one more widget WidgetFactory.Container(new RectangleF(0, 0, 220, 120)) }; var expects = new[] { new RectangleF(0, 30, 120, 330), new RectangleF(0, 360, 120, 330), new RectangleF(120, 30, 120, 330), new RectangleF(120, 360, 120, 330), new RectangleF(240, 30, 120, 330), new RectangleF(240, 360, 120, 330), new RectangleF(360, 30, 220, 120) }; foreach (var widget in acts) { _root.AddChild(widget); } ApplyCol(); _justifyCenter.ApplyOn(_root); for (var i = 0; i < acts.Length; i++) { Assert.That(acts[i].Space, Is.EqualTo(expects[i])); } }
public void RowWithTwoW_SpaceAround() { var child = WidgetFactory.Container(new RectangleF(0, 0, 130, 120)); var child1 = WidgetFactory.Container(new RectangleF(0, 0, 120, 110)); _root.AddChild(child); _root.AddChild(child1); _root.WithProp(PropFactory.Row()); _root.WithProp(_justifyAround); ApplyProps(_root); var exp = new RectangleF(343, 0, 130, 120); var exp1 = new RectangleF(817, 0, 120, 110); Assert.That(child.Space, Is.EqualTo(exp)); Assert.That(child1.Space, Is.EqualTo(exp1)); }
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 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 RowWithTwoW_MaximizesSpaceBetween() { var child = WidgetFactory.Container(new RectangleF(0, 0, 130, 120)); var child1 = WidgetFactory.Container(new RectangleF(0, 0, 120, 110)); _root.AddChild(child); _root.AddChild(child1); _root.WithProp(PropFactory.Row()); _root.WithProp(_justifyBetween); ApplyProps(_root); var exp = new RectangleF(0, 0, 130, 120); var exp1 = new RectangleF(1160, 0, 120, 110); Assert.That(child.Space, Is.EqualTo(exp)); Assert.That(child1.Space, Is.EqualTo(exp1)); }
public void PressOnWidget_ThenEnterAnother_OldStaysPressed() { // Press the interaction button _device.Setup(device => device.IsPressed()).Returns(true); _handler.Device = _device.Object; _handler.Updater = new InteractionUpdater(); // Press widget _handler.UpdateAndGenerateTransitions(_widgetTree); _device.Setup(device => device.IsPressed()).Returns(false); _device.Setup(device => device.IsHeld()).Returns(true); _handler.Device = _device.Object; var w = WidgetFactory.Container(); // Move while pressing to another widget _handler.UpdateAndGenerateTransitions(w); Assert.That(_widgetTree.CurrentInteraction, Is.EqualTo(Interaction.Pressed)); }
public void ApplyOn_ThreeColumnsOfWidgets_CorrectlyCentered() { var acts = new[] { // First Col WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), // Second Col WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), // Third Col WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), }; var expects = new[] { new RectangleF(0, 30, 120, 330), new RectangleF(0, 360, 120, 330), new RectangleF(120, 30, 120, 330), new RectangleF(120, 360, 120, 330), new RectangleF(240, 30, 120, 330), new RectangleF(240, 360, 120, 330), }; foreach (var widget in acts) { _root.AddChild(widget); } ApplyCol(); _justifyCenter.ApplyOn(_root); for (var i = 0; i < acts.Length; i++) { Assert.That(acts[i].Space, Is.EqualTo(expects[i])); } }
public void ApplyOn_TwoColumnsWithDifferentWidths() { var acts = new[] { WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), }; var expects = new[] { new RectangleF(0, 15, 220, 120), new RectangleF(0, 135, 120, 330), new RectangleF(0, 465, 220, 120), new RectangleF(0, 585, 220, 120), new RectangleF(220, 15, 220, 120), new RectangleF(220, 135, 220, 120), new RectangleF(220, 255, 220, 120), }; foreach (var widget in acts) { _root.AddChild(widget); } ApplyCol(); _justifyCenter.ApplyOn(_root); for (var i = 0; i < acts.Length; i++) { Assert.That(acts[i].Space, Is.EqualTo(expects[i])); } }
public void PressOnWidget_ThenEnterAnotherAndRelease_NoReleaseCommandsAreGenerated() { var thenEntered = WidgetFactory.Container(30, 30); _device.Setup(device => device.IsPressed()).Returns(true); _handler.Device = _device.Object; _handler.Updater = new InteractionUpdater(); // Press firstPressed _handler.UpdateAndGenerateTransitions(_widgetTree); // Move to thenEntered while pressing _handler.UpdateAndGenerateTransitions(thenEntered); _device.Setup(device => device.IsPressed()).Returns(false); _device.Setup(d => d.IsReleased()).Returns(true); _handler.Device = _device.Object; var l = _handler.UpdateAndGenerateTransitions(thenEntered); Assert.That(l, Is.Empty); }
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 void ApplyOn_TwoRowsWithDifferentHeights() { var acts = new[] { WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 120, 330)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), }; var expects = new[] { new RectangleF(30, 0, 220, 120), new RectangleF(250, 0, 120, 330), new RectangleF(370, 0, 220, 120), new RectangleF(590, 0, 220, 120), new RectangleF(810, 0, 220, 120), new RectangleF(1030, 0, 220, 120), new RectangleF(30, 330, 220, 120), }; foreach (var widget in acts) { _root.AddChild(widget); } ApplyRow(); _justifyCenter.ApplyOn(_root); for (var i = 0; i < acts.Length; i++) { Assert.That(acts[i].Space, Is.EqualTo(expects[i])); } }
public void BeforeEach() { _flex = new Flex(); _root = WidgetFactory.Container(); _root.WithProp(_flex); }
public ItemBaseTests() { _itemBase = new ItemBase(); _root = WidgetFactory.Container(new RectangleF(0, 0, 1280, 720)); _child = WidgetFactory.Container(20, 20); }
public void BeforeEach() { _column = new Column(); _root = WidgetFactory.Container(new RectangleF(0, 0, 1280, 720)); }
public void BeforeEach() { _justifyCenter = new JustifyCenter(); _root = WidgetFactory.Container(0, 0, 1280, 720); _child = WidgetFactory.Container(0, 0, 120, 120); }
public void ApplyOn_ThreeRowsPlusOneWidget_TheLastOnBeginningOfRow() { var acts = new[] { // First Row WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), // Second Row WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), // Third Row WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), WidgetFactory.Container(new RectangleF(0, 0, 220, 120)), // The one more widget WidgetFactory.Container(new RectangleF(0, 0, 220, 120)) }; var expects = new[] { new RectangleF(90, 0, 220, 120), // first row new RectangleF(310, 0, 220, 120), new RectangleF(530, 0, 220, 120), new RectangleF(750, 0, 220, 120), new RectangleF(970, 0, 220, 120), new RectangleF(90, 120, 220, 120), // second row new RectangleF(310, 120, 220, 120), new RectangleF(530, 120, 220, 120), new RectangleF(750, 120, 220, 120), new RectangleF(970, 120, 220, 120), new RectangleF(90, 240, 220, 120), // third row new RectangleF(310, 240, 220, 120), new RectangleF(530, 240, 220, 120), new RectangleF(750, 240, 220, 120), new RectangleF(970, 240, 220, 120), new RectangleF(90, 360, 220, 120) // new widget }; foreach (var widget in acts) { _root.AddChild(widget); } ApplyRow(); _justifyCenter.ApplyOn(_root); for (var i = 0; i < acts.Length; i++) { Assert.That(acts[i].Space, Is.EqualTo(expects[i])); } }
public void BeforeEach() { _justifyAround = new JustifyAround(); _root = WidgetFactory.Container(new RectangleF(0, 0, 1280, 720)); }
public JustifyAroundTests() { _justifyAround = new JustifyAround(); _root = WidgetFactory.Container(new RectangleF(0, 0, 1280, 720)); }
public void BeforeEach() { _itemCenter = new ItemCenter(); _root = WidgetFactory.Container(new RectangleF(0, 0, 1280, 720)); }
public ItemCenterTests() { _itemCenter = new ItemCenter(); _root = WidgetFactory.Container(new RectangleF(0, 0, 1280, 720)); }