public void SetUp() { // This test uses a 11x16 font. styleSystem = LayoutTestStyle.CreateStyleSystem(); textStyleDefinition = styleSystem.StylesFor <TextStyleDefinition>(); textStyle = LayoutTestStyle.CreateTextStyle(styleSystem); }
public void PopUpsHaveHighestPriorityInHitTestZOrder() { var popUp1 = new PopUp <IWidget>(LayoutTestStyle.Create()) { Padding = new Insets(10), Content = LayoutTestWidget.FixedSize(500, 300) }; popUp1.Anchor = AnchoredRect.CreateTopLeftAnchored(10, 20); var popUp2 = new PopUp <IWidget>(LayoutTestStyle.Create()) { Padding = new Insets(10), Content = LayoutTestWidget.FixedSize(500, 300) }; popUp2.Anchor = AnchoredRect.CreateTopLeftAnchored(10, 20); var screen = Substitute.For <IScreenService>(); var root = new RootPane(screen, LayoutTestStyle.Create()); root.UIStyle.StyleResolver.AddRoot(root); root.Content = LayoutTestWidget.FixedSize(400, 400).WithAnchorRect(AnchoredRect.Full); root.AddPopUp(popUp1); root.AddPopUp(popUp2); root.Arrange(new Rectangle(0, 0, 1270, 770)); root.Content.PerformHitTest(new Point(100, 100)).ShouldBeSameObjectReference(root.Content); popUp1.PerformHitTest(new Point(100, 100)).ShouldBeSameObjectReference(popUp1.Content); popUp2.PerformHitTest(new Point(100, 100)).ShouldBeSameObjectReference(popUp2.Content); root.PerformHitTest(new Point(100, 100)).ShouldBeSameObjectReference(popUp2.Content); }
public void Nested_Widgets_Revalidate_Styles() { var style = LayoutTestStyle.Create(); var b = new StyleBuilder(style.StyleSystem); var widgetStyles = b.StyleSystem.StylesFor <TestStyleDefinition>(); style.StyleResolver.StyleRules.Add( b.CreateRule(b.SelectForType <Button>().WithCondition(StyleBuilderExtensions.HasClass("Test")), b.CreateStyle().WithValue(widgetStyles.Inherited, "FromButton-With-Test"))); style.StyleResolver.StyleRules.Add(b.CreateRule(b.SelectForType <Button>(), b.CreateStyle().WithValue(widgetStyles.Inherited, "FromButton"))); var button = new Button(style); style.StyleResolver.AddRoot(button); button.ValidateStyle(); button.Content.Style.GetValue(widgetStyles.Inherited).Should().Be("FromButton"); button.AddStyleClass("Test"); button.ValidateStyle(); button.Style.GetValue(widgetStyles.Inherited).Should().Be("FromButton-With-Test"); button.Content.Style.GetValue(widgetStyles.Inherited).Should().Be("FromButton-With-Test"); button.ValidateStyle(); }
public void Arrange_Empty() { var textField = new TextField(LayoutTestStyle.Create()); textField.Arrange(new Rectangle(10, 20, 300, 100)); textField.LayoutRect.Should().Be(new Rectangle(10, 20, 300, 100)); }
public void ChildPropertyDoesNotCrashOnSelf() { var p = new ScrollPanel(LayoutTestStyle.Create()); p.Content = new LayoutTestWidget(); p.Content = p.Content; }
public void TestImplicitConstraintsOnMinSpaceChild() { var g = new Grid(LayoutTestStyle.Create()); g.AddChildAt(new LayoutTestWidget { MeasureOverrideFunc = s => new Size(100, 50) }, 0, 0); g.AddChildAt(new LayoutTestWidget { MeasureOverrideFunc = s => new Size(200, 100) }, 1, 1); g.Measure(new Size(float.PositiveInfinity, float.PositiveInfinity)); g[0].DesiredSize.Should().Be(new Size(100, 50)); g[1].DesiredSize.Should().Be(new Size(200, 100)); g.DesiredSize.Should().Be(new Size(300, 150)); g.Arrange(new Rectangle(10, 20, 400, 300)); g[0].DesiredSize.Should().Be(new Size(100, 50)); g[1].DesiredSize.Should().Be(new Size(200, 100)); g[0].LayoutInvalid.Should().Be(false); g[1].LayoutInvalid.Should().Be(false); g[0].LayoutRect.Should().Be(new Rectangle(10, 20, 100, 50)); g[1].LayoutRect.Should().Be(new Rectangle(110, 70, 200, 100)); g.LayoutRect.Should().Be(new Rectangle(10, 20, 300, 150)); }
public void WriteDescendantRule() { var uiStyle = LayoutTestStyle.Create(); var b = new StyleBuilder(uiStyle.StyleSystem); var widgetStyles = b.StyleSystem.StylesFor <WidgetStyleDefinition>(); var rules = b.CreateRule( b.SelectForType("Button") .WithCondition(StyleBuilderExtensions.HasAttribute("name", "button")) .WithDirectChild(b.SelectForType("IconLabel").WithCondition(StyleBuilderExtensions.HasAttribute("name", "iconlabel"))) .WithDirectChild(b.SelectForType("Label").WithCondition(StyleBuilderExtensions.HasAttribute("name", "label"))), b.CreateStyle().WithBox(widgetStyles.FrameTexture, "texture-on-label")); var styleWriter = uiStyle.StyleSystem.CreateWriter(); var document = styleWriter.Write(new List <IStyleRule> { rules }); var w = new StringWriter(); document.Save(w); File.WriteAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "style-descendand-rule.xml"), w.ToString()); var p = uiStyle.StyleSystem.CreateParser(); var parsed = p.Read(document); parsed.Count.Should().Be(1); parsed[0].Weight.Should().Be(rules.Weight); parsed[0].Selector.ToString().Should().Be(rules.Selector.ToString()); }
public void TooltipUpdatesChangeVisibilityWhenDelay() { var style = LayoutTestStyle.Create(); var tooltip = new Tooltip <Label>(style); tooltip.TooltipDelay = 1; tooltip.TooltipDisplayTime = 5; var gameTime = new GameTime(TimeSpan.FromDays(1), TimeSpan.Zero); tooltip.Update(gameTime); tooltip.Visibility.Should().Be(Visibility.Collapsed); gameTime = new GameTime(TimeSpan.FromDays(1), TimeSpan.FromSeconds(1)); tooltip.Update(gameTime); tooltip.Visibility.Should().Be(Visibility.Visible); gameTime = new GameTime(TimeSpan.FromDays(1), TimeSpan.FromSeconds(4)); // at 5 seconds tooltip.Update(gameTime); tooltip.Visibility.Should().Be(Visibility.Visible); gameTime = new GameTime(TimeSpan.FromDays(1), TimeSpan.FromSeconds(0.99)); // at 5.999 tooltip.Update(gameTime); tooltip.Visibility.Should().Be(Visibility.Visible); gameTime = new GameTime(TimeSpan.FromDays(1), TimeSpan.FromSeconds(0.01)); // at 6 tooltip.Update(gameTime); tooltip.Visibility.Should().Be(Visibility.Collapsed); gameTime = new GameTime(TimeSpan.FromDays(1), TimeSpan.FromSeconds(0.01)); // at 6.01 tooltip.Update(gameTime); tooltip.Visibility.Should().Be(Visibility.Collapsed); }
public void Arrange_Ignores_AnchorRects() { var p = new TestScrollPanel(LayoutTestStyle.Create()) { // CornerSize = 10, Padding = new Insets(10), VerticalScrollbarMode = ScrollbarMode.Always, Content = LayoutTestWidget.FixedSize(500, 300).WithAnchorRect(AnchoredRect.CreateFull(40)) }; p.UIStyle.StyleResolver.AddRoot(p); p.Arrange(new Rectangle(10, 20, 300, 200)); WidgetVisitor.PrintLayoutVisitor().Visit(p); p.DesiredSize.Should().Be(new Size(610, 400)); p.Content.DesiredSize.Should().Be(new Size(500, 300)); p.LayoutRect.Should().Be(new Rectangle(10, 20, 300, 200)); // width = 300 - 2*40 (anchor) - 2*10 (padding) - 10 (scrollbar) p.Content.LayoutRect.Should().Be(new Rectangle(20, 30, 270, 300)); p.TestScrollbar.LayoutRect.Should().Be(new Rectangle(290, 30, 10, 180)); // height = 300 + 2*40 from anchor p.TestScrollbar.ScrollContentHeight.Should().Be(300); }
public void DragAnDrop_Inside_Arrange_Far_Right() { var style = LayoutTestStyle.Create(); var tab1 = new NotebookTab(style, new Label(style, "Tab 1"), null) { Tag = "Tab 1" }; var tab2 = new NotebookTab(style, new Label(style, "Tab 2"), null) { Tag = "Tab 2" }; var tab3 = new NotebookTab(style, new Label(style, "Tab 3"), null) { Tag = "Tab 3" }; var b = new DnDNoteBookTab(style) { tab1, tab2, tab3 }; style.StyleResolver.AddRoot(b); b.Arrange(new Rectangle(10, 20, 600, 40)); b[1].DispatchMouseDown(MouseButton.Left, 20, 30); b.Arrange(new Rectangle(10, 20, 600, 40)); b[1].DispatchMouseDrag(MouseButton.Left, 500, 30); b.Arrange(new Rectangle(10, 20, 600, 40)); // The dragged element floating range is limited to the visible space. b[0].LayoutRect.Should().Be(new Rectangle(30, 25, 155, 35)); b[1].LayoutRect.Should().Be(new Rectangle(325, 25, 155, 35)); b[2].LayoutRect.Should().Be(new Rectangle(170, 25, 155, 35)); }
public void TestBuildComplexRule() { var b = new StyleBuilder(LayoutTestStyle.CreateStyleSystem()); var step2 = b.SelectForType <Button>().WithDirectChild(b.SelectForType <IconLabel>()).WithDirectChild(b.SelectForType <Label>()); step2.ToString().Should().Be("Button > IconLabel > Label"); }
public void MeasureEmptyMustNotCrash() { var g = new BoxGroup(LayoutTestStyle.Create()); g.Measure(Size.Auto); g.DesiredSize.Should().Be(new Size()); }
public void Measure_Empty() { var style = LayoutTestStyle.Create(); var textField = new TextField(style); style.StyleResolver.AddRoot(textField); textField.Measure(Size.Auto); textField.DesiredSize.Should().Be(new Size(30, 30 + 16)); }
public void HandlePositionAtZero() { var s = new Slider(LayoutTestStyle.Create(), 10, 60, 0, 5); s.UIStyle.StyleResolver.AddRoot(s); s.Arrange(new Rectangle(10, 20, 400, 100)); s.LayoutRect.Should().Be(new Rectangle(10, 20, 400, 100)); s[0][1].LayoutRect.Should().Be(new Rectangle(10, 20, 40, 100)); }
public void TestMeasureEmptyString() { var l = new Label(LayoutTestStyle.Create()); l.Padding = new Insets(); l.Font = LayoutTestStyle.CreateFont(); l.Measure(Size.Auto); l.DesiredSize.Should().Be(new Size(0, 12)); }
public void StyleOverlapIsAppliedToNotebookTabList() { var style = LayoutTestStyle.Create(); var b = new NotebookTabList(style); style.StyleResolver.AddRoot(b); b.Measure(Size.Auto); b.NotebookTabOverlapX.Should().Be(15); }
public void ArrangeEmptyMustNotCrash() { var g = new BoxGroup(LayoutTestStyle.Create()); g.Arrange(new Rectangle(10, 20, 400, 300)); g.DesiredSize.Should().Be(new Size()); g.LayoutRect.Should().Be(new Rectangle(10, 20, 0, 0)); }
public void LayoutEmptyContainer() { var p = new DockPanel(LayoutTestStyle.Create()); p.Measure(Size.Auto); p.DesiredSize.Should().Be(new Size(0, 0)); p.Arrange(new Rectangle(10, 20, 500, 300)); p.LayoutRect.Should().Be(new Rectangle(10, 20, 500, 300)); }
public void TestMeasureInfinity() { var g = new Group(LayoutTestStyle.Create()); g.Add(Create(AnchoredRect.Full)); g.Add(Create(AnchoredRect.CreateFixed(200, 300, 400, 500))); g.Measure(new Size(float.PositiveInfinity, float.PositiveInfinity)); g.DesiredSize.Should().Be(new Size(600, 800)); }
public void Mouse_Clicks_in_label_Activate_Tab() { var activationRequested = false; var tab = new NotebookTab(LayoutTestStyle.Create(), LayoutTestWidget.FixedSize(100, 20), LayoutTestWidget.FixedSize(500, 400)); tab.ActivationRequested += (s, e) => activationRequested = true; tab[0][1].DispatchMouseClick(MouseButton.Left, 10, 20); activationRequested.Should().Be(true); }
public void IsPinned_InitialState() { var tab = new NotebookTab(LayoutTestStyle.Create(), LayoutTestWidget.FixedSize(100, 20), LayoutTestWidget.FixedSize(500, 400)); tab.IsClosable.Should().Be(true); tab.IsPinned.Should().Be(false); tab[0][0].Should().BeAssignableTo <Button>(); tab[0][0].Visibility.Should().Be(Visibility.Visible); }
public void CloseButton_Triggers_Close_Request() { var closeRequested = false; var tab = new NotebookTab(LayoutTestStyle.Create(), LayoutTestWidget.FixedSize(100, 20), LayoutTestWidget.FixedSize(500, 400)); tab.CloseRequested += (s, e) => closeRequested = true; tab[0][0].DispatchMouseClick(MouseButton.Left, 10, 20); closeRequested.Should().Be(true); }
public void TestZero() { var g = new Group(LayoutTestStyle.Create()); g.Add(Create(AnchoredRect.Full)); g.Add(Create(AnchoredRect.CreateFixed(200, 300, 400, 500))); g.Measure(new Size(0, 0)); g.DesiredSize.Should().Be(new Size(600, 800)); }
public void TestBuildSimple() { var b = new StyleBuilder(LayoutTestStyle.CreateStyleSystem()); var step2 = b.SelectForType <Button>().WithDirectChild(b.SelectForType <IconLabel>()); step2.Should().BeAssignableTo <DescendantSelector>().Which.Selector.ToString().Should().Be("IconLabel"); step2.Should().BeAssignableTo <DescendantSelector>().Which.AnchestorSelector.ToString().Should().Be("Button"); step2.ToString().Should().Be("Button > IconLabel"); }
public void TestMeasureStringPadded() { var l = new Label(LayoutTestStyle.Create()); l.Padding = new Insets(1, 2, 3, 4); l.Font = LayoutTestStyle.CreateFont(); l.Text = "Test"; l.Measure(Size.Auto); l.DesiredSize.Should().Be(new Size(50, 19)); }
public void EstablishRendererSize() { var style = LayoutTestStyle.Create(); var renderer = ListView.DefaultCreateRenderer(style, "Test"); style.StyleResolver.AddRoot(renderer); renderer.Measure(Size.Auto); renderer.DesiredSize.Should().Be(new Size(64, 35)); }
public void TestImplicitConstraintsAdded() { var g = new Grid(LayoutTestStyle.Create()); g.AddChildAt(new LayoutTestWidget(), 0, 0); g.AddChildAt(new LayoutTestWidget(), 1, 1); g.Measure(new Size(float.PositiveInfinity, float.PositiveInfinity)); g.RowConstraints.Should().BeEquivalentTo(LengthConstraint.Auto, LengthConstraint.Auto); g.ColumnConstraints.Should().BeEquivalentTo(LengthConstraint.Auto, LengthConstraint.Auto); }
public void Arrange_Zero() { var style = LayoutTestStyle.Create(); var textField = new TextField(style); style.StyleResolver.AddRoot(textField); textField.Padding = new Insets(); textField.Arrange(new Rectangle(10, 20, 0, 0)); textField.LayoutRect.Should().Be(new Rectangle(10, 20, 0, 0)); }
public void Input_In_Middle() { var eb = new TextField(LayoutTestStyle.Create()); eb.Text = "Hello World"; eb.Caret.MoveTo(6); eb.DispatchEvent(new KeyEventArgs(new KeyEventData(KeyEventType.KeyTyped, TimeSpan.Zero, 0, InputFlags.None, 'a'))); eb.Text.Should().Be("Hello aWorld"); eb.Caret.SelectionStartOffset.Should().Be(7); eb.Caret.SelectionEndOffset.Should().Be(7); }
public void Initial_text_moves_caret_to_End() { var style = LayoutTestStyle.Create(); var textField = new TextField(style); style.StyleResolver.AddRoot(textField); textField.Text = "Hello World"; textField.Caret.SelectionStartOffset.Should().Be(11); textField.Caret.SelectionEndOffset.Should().Be(11); }