Exemple #1
0
        public void StackPanel_NormalHorizontal_Works()
        {
            var renderer = new MockRenderer(10, 20);

            renderer.MeasureTextReturn = new Vector2(1, 3);

            var layoutText =
                @"<Grid  ContentAlignment=""Left,Top"">
                    <StackPanel Name=""panel"" Orientation=""Horizontal"" >
                        <Grid Size=""2,5""  Name=""gridChild"" />
                        <Label Content=""Hi"" Name=""labelChild""/>
                    </StackPanel>
                   </Grid>";

            var target = TestUtils.LoadFromText(renderer, layoutText, "Target");

            target.Prepare(new Dictionary <string, VarmintWidgetStyle>());
            target.UpdateFormatting(renderer.ScreenSize);


            var panel      = target.FindWidgetByName("panel");
            var gridChild  = target.FindWidgetByName("gridChild");
            var labelChild = target.FindWidgetByName("labelChild");

            // Should size to children
            Assert.AreEqual(new Vector2(3, 5), panel.Size);
            Assert.AreEqual(new Vector2(0, 0), panel.Offset);

            // children should have correct size and offset
            Assert.AreEqual(new Vector2(2, 5), gridChild.Size);
            Assert.AreEqual(new Vector2(0, 0), gridChild.Offset);
            Assert.AreEqual(new Vector2(1, 3), labelChild.Size);
            Assert.AreEqual(new Vector2(2, 0), labelChild.Offset);
        }
Exemple #2
0
        public void Format_ImageAlignment_Works()
        {
            var mockRenderer = new MockRenderer(10, 20);

            mockRenderer.MeasureTextReturn = new Vector2(1, 1);
            var layoutText = @"
                <Grid>
                    <Image
                        Name=""TextLogo""
                        Margin = ""0,6""
                        Size = ""6,2""
                        ContentAlignment = ""Left,""
                        Content = ""TextLogo"" >
                        <Label Content=""foo"" />
                    </Image> 
                </Grid>
                ";
            var target     = (VarmintWidgetGrid)TestUtils.LoadFromText(mockRenderer, layoutText, "(root)");
            var image      = target.FindWidgetByName("TextLogo");

            target.Prepare(null);
            target.UpdateFormatting(new Vector2(20, 40));
            Assert.AreEqual(new Vector2(6, 2), image.Size);
            Assert.AreEqual(new Vector2(0, 6), image.Offset);
        }
Exemple #3
0
        public void Format_Label_Autosizes_ToText()
        {
            var layoutText = @"
                <TestWidget MyAlignment=""Stretch,Stretch"" >
                    <Grid Name=""TheGrid"">
                        <Label Name=""TheLabel"" Content=""Hi"" />
                    </Grid>
                </TestWidget>";
            var target     = (TestWidget)TestUtils.LoadFromText(this, layoutText, "(root)");
            var label      = (VarmintWidgetLabel)target.FindWidgetByName("TheLabel");

            var renderer = new MockRenderer(10, 10);

            renderer.MeasureTextReturn = new Vector2(.5f, .2f);
            label.Renderer             = renderer;
            target.Prepare(null);
            target.UpdateFormatting(new Vector2(5, 8));
            Assert.AreEqual(new Vector2(5, 8), label.Size);
            Assert.AreEqual(new Vector2(0, 0), label.Offset);

            label.MyAlignment = new AlignmentTuple(Alignment.Center, Alignment.Center);
            target.Prepare(null);
            target.UpdateFormatting(new Vector2(5, 8));
            Assert.AreEqual(new Vector2(.5f, .2f), label.Size);
            Assert.AreEqual(new Vector2(2.25f, 3.9f), label.Offset);
        }
Exemple #4
0
        public void Format_ContentIsPreserved()
        {
            var mockRenderer = new MockRenderer(10, 20);

            mockRenderer.MeasureTextReturn = new Vector2(1, 1);
            var layoutText = @"<Label Content=""Free Balloons"" />";
            var target     = (VarmintWidgetLabel)TestUtils.LoadFromText(mockRenderer, layoutText, "(root)");

            target.Prepare(null);
            target.UpdateFormatting(new Vector2(20, 40));
            Assert.AreEqual("Free Balloons", target.Content);
        }
Exemple #5
0
        public void StackPanel_NormalHorizontal_AlignedContent_Works()
        {
            var renderer = new MockRenderer(10, 20);

            renderer.MeasureTextReturn = new Vector2(1, 3);

            var layoutText =
                @"<Grid  ContentAlignment=""Left,Top"">
                    <StackPanel Name=""FirstPanel"">
                        <StackPanel Name=""panel1"" Orientation=""Horizontal"" ContentAlignment=""Center"">
                            <Grid Size=""2,5""  Name=""grid1"" />
                            <Grid  Name=""gridStretched1"" MyAlignment=""Stretch"" />
                            <Label Content=""Hi"" Name=""labelChild1"" Margin=""1""/>
                            <Grid  Name=""gridStretched2"" MyAlignment=""Stretch"" />
                       </StackPanel>
                    </StackPanel>
                   </Grid>";

            var target = TestUtils.LoadFromText(renderer, layoutText, "Target");

            target.Prepare(new Dictionary <string, VarmintWidgetStyle>());
            target.UpdateFormatting(renderer.ScreenSize);

            var panel  = target.FindWidgetByName("panel1");
            var child1 = target.FindWidgetByName("grid1");
            var child2 = target.FindWidgetByName("gridStretched1");
            var child3 = target.FindWidgetByName("labelChild1");
            var child4 = target.FindWidgetByName("gridStretched2");

            // Should size to children, which will push it to the max extent
            Assert.AreEqual(new Vector2(10, 20), panel.Size);
            Assert.AreEqual(new Vector2(0, 0), panel.Offset);

            // children should have correct size and offset
            Assert.AreEqual(new Vector2(2, 5), child1.Size);
            Assert.AreEqual(new Vector2(2.5f, 20), child2.Size);
            Assert.AreEqual(new Vector2(1, 3), child3.Size);
            Assert.AreEqual(new Vector2(2.5f, 20), child4.Size);

            Assert.AreEqual(new Vector2(0, 7.5f), child1.Offset);
            Assert.AreEqual(new Vector2(2, 0), child2.Offset);
            Assert.AreEqual(new Vector2(5.5f, 8.5f), child3.Offset);
            Assert.AreEqual(new Vector2(7.5f, 0), child4.Offset);
        }
Exemple #6
0
        public void Format_NonStretchedAlignments_SizeToChildren_WhenSizeIsMissing()
        {
            var mockRenderer = new MockRenderer(10, 20);

            mockRenderer.MeasureTextReturn = new Vector2(1, 1);
            var layoutText = @"
                <Grid ContentAlignment=""Left,Top"">
                    <Grid Name=""CheckMe"">
                        <Grid Size=""5,4"" Margin=""1"">
                            <Grid Size=""2,2"">
                            </Grid>
                        </Grid>
                    </Grid>
                </Grid>
                ";
            var target     = (VarmintWidgetGrid)TestUtils.LoadFromText(mockRenderer, layoutText, "(root)");
            var checkMe    = target.FindWidgetByName("CheckMe");

            target.Prepare(null);
            target.UpdateFormatting(new Vector2(20, 40));
            Assert.AreEqual(new Vector2(20, 40), target.Size);
            Assert.AreEqual(new Vector2(7, 6), checkMe.Size);
        }
Exemple #7
0
        public void StackPanel_NormalVerical_StretchedContent_Works()
        {
            var renderer = new MockRenderer(10, 20);

            renderer.MeasureTextReturn = new Vector2(4, 1);

            var layoutText =
                @"<Grid  ContentAlignment=""Left,Top"">
                    <StackPanel>
                        <StackPanel Name=""panel1"" Orientation=""Vertical"" ContentAlignment=""Left,"">
                            <Grid Size=""6,1""  Name=""gridChild1"" />
                            <Label Content=""Hi"" Name=""labelChild1""/>
                        </StackPanel>
                        <StackPanel Name=""panel2"" Orientation=""Vertical"" ContentAlignment=""Center,"">
                            <Grid Size=""6,1""  Name=""gridChild2"" />
                            <Label Content=""Hi"" Name=""labelChild2""/>
                        </StackPanel>
                        <StackPanel Name=""panel3"" Orientation=""Vertical"" ContentAlignment=""Right,"">
                            <Grid Size=""6,1""  Name=""gridChild3"" />
                            <Label Content=""Hi"" Name=""labelChild3""/>
                        </StackPanel>
                    </StackPanel>
                   </Grid>";

            var target = TestUtils.LoadFromText(renderer, layoutText, "Target");

            target.Prepare(new Dictionary <string, VarmintWidgetStyle>());
            target.UpdateFormatting(renderer.ScreenSize);


            var panel      = target.FindWidgetByName("panel1");
            var gridChild  = target.FindWidgetByName("gridChild1");
            var labelChild = target.FindWidgetByName("labelChild1");

            // Should size to children
            Assert.AreEqual(new Vector2(6, 2), panel.Size);
            Assert.AreEqual(new Vector2(0, 0), panel.Offset);

            // children should have correct size and offset
            Assert.AreEqual(new Vector2(6, 1), gridChild.Size);
            Assert.AreEqual(new Vector2(0, 0), gridChild.Offset);
            Assert.AreEqual(new Vector2(4, 1), labelChild.Size);
            Assert.AreEqual(new Vector2(0, 1), labelChild.Offset);


            panel      = target.FindWidgetByName("panel2");
            gridChild  = target.FindWidgetByName("gridChild2");
            labelChild = target.FindWidgetByName("labelChild2");

            // Should size to children
            Assert.AreEqual(new Vector2(6, 2), panel.Size);
            Assert.AreEqual(new Vector2(0, 2), panel.Offset);

            // children should have correct size and offset
            Assert.AreEqual(new Vector2(6, 1), gridChild.Size);
            Assert.AreEqual(new Vector2(0, 0), gridChild.Offset);
            Assert.AreEqual(new Vector2(4, 1), labelChild.Size);
            Assert.AreEqual(new Vector2(1, 1), labelChild.Offset);


            panel      = target.FindWidgetByName("panel3");
            gridChild  = target.FindWidgetByName("gridChild3");
            labelChild = target.FindWidgetByName("labelChild3");

            // Should size to children
            Assert.AreEqual(new Vector2(6, 2), panel.Size);
            Assert.AreEqual(new Vector2(0, 4), panel.Offset);

            // children should have correct size and offset
            Assert.AreEqual(new Vector2(6, 1), gridChild.Size);
            Assert.AreEqual(new Vector2(0, 0), gridChild.Offset);
            Assert.AreEqual(new Vector2(4, 1), labelChild.Size);
            Assert.AreEqual(new Vector2(2, 1), labelChild.Offset);
        }