Beispiel #1
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();
            
            buttonLeftTop2 = new Button { Padding = new Thickness(50, 50, 0, 50) };
            buttonLeftTop1 = new Button { Padding = new Thickness(50, 50, 0, 50), Content = buttonLeftTop2 };
            buttonLeftTop0 = new Button { Padding = new Thickness(50, 50, 0, 50), Content = buttonLeftTop1};

            var bottomGrid = new UniformGrid { Rows = 1, Columns = 2 };
            bottomButton = new Button { Content = bottomGrid };
            bottomButton.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            bottomButton.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);

            buttonBottomLeft1 = new Button { Margin = new Thickness(50, 50, 0, 50) };
            buttonBottomLeft0 = new Button { Margin = new Thickness(50, 0, 0, 100), Content = buttonBottomLeft1 };

            bottonBottomRight1 = new Button { Margin = new Thickness(0, 0, 50, 100) };
            buttomBottonRight0 = new Button { Margin = new Thickness(0, 0, 50, 50), Content = bottonBottomRight1 };
            buttomBottonRight0.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);

            bottomGrid.Children.Add(buttonBottomLeft0);
            bottomGrid.Children.Add(buttomBottonRight0);

            var mainGrid = new UniformGrid { Rows = 2, Columns = 2 };
            mainGrid.Children.Add(buttonLeftTop0);
            mainGrid.Children.Add(bottomButton);

            UIComponent.RootElement = mainGrid;
        }
Beispiel #2
0
        public void TestSurroudingAnchor()
        {
            var childSize1 = new Vector3(50, 150, 250);
            var childSize2 = new Vector3(100, 200, 300);
            
            var grid = new UniformGrid { Columns = 2, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center};

            var child1 = new UniformGrid { Size = childSize1 };
            var child2 = new UniformGrid { Size = childSize2 };
            child2.DependencyProperties.Set(ColumnPropertyKey, 1);
            
            grid.Children.Add(child1);
            grid.Children.Add(child2);

            grid.Measure(1000 * Vector3.One);
            grid.Arrange(1000 * Vector3.One, false);
            
            Assert.AreEqual(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, -1));
            Assert.AreEqual(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 0));
            Assert.AreEqual(new Vector2(-50, 50), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 50));
            Assert.AreEqual(new Vector2(-80, 20), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 80));
            Assert.AreEqual(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 100));
            Assert.AreEqual(new Vector2(-10, 90), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 110));
            Assert.AreEqual(new Vector2(-100, 0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 200));
            Assert.AreEqual(new Vector2(-100, 0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 300));

            Assert.AreEqual(new Vector2(0, 200), grid.GetSurroudingAnchorDistances(Orientation.Vertical, -1));
            Assert.AreEqual(new Vector2(-100, 100), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 100));
            Assert.AreEqual(new Vector2(-200, 0), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 500));

            Assert.AreEqual(new Vector2(0, 300), grid.GetSurroudingAnchorDistances(Orientation.InDepth, -1));
            Assert.AreEqual(new Vector2(-150, 150), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 150));
            Assert.AreEqual(new Vector2(-300, 0), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 500));
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var sprites = Asset.Load<SpriteSheet>("RotatedImages");
            var img1 = new ImageElement { Source = sprites["NRNR"], StretchType = StretchType.Fill };
            var img2 = new ImageElement { Source = sprites["RNR"], StretchType = StretchType.Fill };
            var img3 = new ImageElement { Source = sprites["NRR"], StretchType = StretchType.Fill };
            var img4 = new ImageElement { Source = sprites["RR"], StretchType = StretchType.Fill };

            img1.SetGridColumnSpan(2);
            img2.SetGridColumnSpan(2);
            img2.SetGridRow(1);
            img3.SetGridRowSpan(2);
            img3.SetGridColumn(2);
            img4.SetGridRowSpan(2);
            img4.SetGridColumn(3);

            var grid = new UniformGrid
            {
                Rows = 2, 
                Columns = 4,
                Children = { img1, img2, img3, img4 }
            };

            UIComponent.RootElement = grid;
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            sliderImages = Content.Load<SpriteSheet>("DebugSlider");

            slider = new Slider { TrackStartingOffsets = new Vector2(10, 6), TickOffset = 10 };
            SetSliderImages(isRotatedImages);

            grid = new UniformGrid { Children = { slider } };

            UIComponent.Page = new Engine.UIPage { RootElement = grid };
        }
Beispiel #5
0
        public void TestBasicInvalidations()
        {
            var grid = new UniformGrid { Rows = 2, Columns = 2, Layers = 2 };
            var child = new UniformGrid();
            grid.Children.Add(child);

            // - test the properties that are not supposed to invalidate the object layout state
            UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(ColumnPropertyKey, 2));
            UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(RowPropertyKey, 2));
            UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(LayerPropertyKey, 2));
            UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(ColumnSpanPropertyKey, 2));
            UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(RowSpanPropertyKey, 2));
            UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(LayerSpanPropertyKey, 2));
        }
Beispiel #6
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            // build the randomStackPanel elements
            randomStackPanel = new StackPanel { Orientation = Orientation.Vertical };
            for (int i = 0; i < 30; i++)
                randomStackPanel.Children.Add(CreateButton(0, i, 50, 1200, true));

            // build the randomStackPanel elements
            virtualizedStackPanel = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true };
            for (int i = 0; i < 30; i++)
                virtualizedStackPanel.Children.Add(CreateButton(0, i, 75, 1200));

            // build the uniform grid
            uniformGrid = new UniformGrid { Columns = 15, Rows = 20 };
            for (int c = 0; c < uniformGrid.Columns; ++c)
            {
                for (int r = 0; r < uniformGrid.Rows; ++r)
                    uniformGrid.Children.Add(CreateButton(c,r, 175, 300));
            }
                
            // build the grid
            const int gridColumns = 10;
            const int gridRows = 10;
            grid = new Grid();
            grid.LayerDefinitions.Add(new StripDefinition(StripType.Auto));
            for (int i = 0; i < gridColumns; i++)
                grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            for (int i = 0; i < gridRows; i++)
                grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            for (int c = 0; c < gridColumns; ++c)
            {
                for (int r = 0; r < gridRows; ++r)
                    grid.Children.Add(CreateButton(c, r, 50 + r * 30, 100 + c * 40));
            }

            // build the scroll viewer
            scrollViewer = new TestScrollViewer { Name = "sv", Content = randomStackPanel, ScrollMode = ScrollingMode.HorizontalVertical, SnapToAnchors = true };

            // set the scroll viewer as the root
            UIComponent.RootElement = scrollViewer;
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var imgElt = new ImageElement { Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")), StretchType = StretchType.Fill };
            imgElt.DependencyProperties.Set(GridBase.RowSpanPropertyKey, 2);
            imgElt.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            imgElt.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            imgElt.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);

            var button1 = new Button();
            ApplyButtonDefaultStyle(button1);
            button1.DependencyProperties.Set(GridBase.RowPropertyKey, 3);
            button1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);

            var button2 = new Button();
            ApplyButtonDefaultStyle(button2);
            button2.DependencyProperties.Set(GridBase.RowPropertyKey, 3);
            button2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 3);

            var text = new TextBlock
            {
                Text = "Test Uniform Grid", 
                Font = Content.Load<SpriteFont>("MicrosoftSansSerif15"), 
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };
            ApplyTextBlockDefaultStyle(text);
            text.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            text.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            text.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);

            var grid = new UniformGrid { Rows = 4, Columns = 4};
            grid.Children.Add(imgElt);
            grid.Children.Add(button1);
            grid.Children.Add(button2);
            grid.Children.Add(text);

            UIComponent.Page = new Engine.UIPage { RootElement = grid };
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var sprites = Content.Load<SpriteSheet>("UIImages");

            var img1 = new ImageElement { Name = "UV 1 stack panel", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            var img2 = new ImageElement { Name = "UV 2 stack panel", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            img3 = new ImageElement { Name = "UV 3 stack panel", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };

            stackPanel = new StackPanel { Orientation = Orientation.Vertical };
            stackPanel.Children.Add(img1);
            stackPanel.Children.Add(img2);
            stackPanel.Children.Add(img3);

            var img4 = new ImageElement { Name = "UV grid", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            var img5 = new ImageElement { Name = "UV grid 2", Source = (SpriteFromTexture)new Sprite(Content.Load<Texture>("uv")) };
            var img6 = new ImageElement { Name = "Game screen grid", Source = SpriteFromSheet.Create(sprites, "GameScreen") };

            img4.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            img4.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            img5.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            img5.DependencyProperties.Set(GridBase.RowPropertyKey, 0);
            img6.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            img6.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            img6.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);

            grid = new UniformGrid { Columns = 2, Rows = 2 };
            grid.Children.Add(img4);
            grid.Children.Add(img5);
            grid.Children.Add(img6);

            scrollViewer = new ScrollViewer { Content = grid, ScrollMode = ScrollingMode.HorizontalVertical};

            contentDecorator = new ContentDecorator { Content = scrollViewer };

            UIComponent.Page = new Engine.UIPage { RootElement = contentDecorator };
        }
        public void TestScrollOwner()
        {
            var grid = new UniformGrid();
            Assert.AreEqual(null, grid.ScrollOwner);

            var scrollViewer = new ScrollViewer { Content = grid };
            Assert.AreEqual(scrollViewer, grid.ScrollOwner);

            scrollViewer.Content = null;
            Assert.AreEqual(null, grid.ScrollOwner);

            var scrollViewer2 = new ScrollViewer { Content = grid };
            Assert.AreEqual(scrollViewer2, grid.ScrollOwner);
        }
Beispiel #10
0
        public void TestSurroudingAnchor()
        {
            var childSize1 = new Vector3(50, 150, 250);
            var childSize2 = new Vector3(100, 200, 300);

            var grid = new Grid { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 100));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 200));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.LayerDefinitions.Add(new StripDefinition(StripType.Star));
            grid.LayerDefinitions.Add(new StripDefinition(StripType.Star));

            var child1 = new UniformGrid { Size = childSize1 };
            var child2 = new UniformGrid { Size = childSize2 };
            child2.DependencyProperties.Set(GridBase.RowPropertyKey, 1);

            grid.Children.Add(child1);
            grid.Children.Add(child2);

            grid.Measure(1000 * Vector3.One);
            grid.Arrange(1000 * Vector3.One, false);
            
            Assert.AreEqual(new Vector2(   0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, -1));
            Assert.AreEqual(new Vector2(   0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 0));
            Assert.AreEqual(new Vector2( -50,  50), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 50));
            Assert.AreEqual(new Vector2( -80,  20), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 80));
            Assert.AreEqual(new Vector2(   0, 200), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 100));
            Assert.AreEqual(new Vector2( -10, 190), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 110));
            Assert.AreEqual(new Vector2(-200,   0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 300));
            Assert.AreEqual(new Vector2(-200,   0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 500));
            
            Assert.AreEqual(new Vector2(   0, 150), grid.GetSurroudingAnchorDistances(Orientation.Vertical, -1));
            Assert.AreEqual(new Vector2(   0, 150), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 0));
            Assert.AreEqual(new Vector2( -50, 100), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 50));
            Assert.AreEqual(new Vector2( -80,  70), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 80));
            Assert.AreEqual(new Vector2(   0, 200), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 150));
            Assert.AreEqual(new Vector2( -10, 190), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 160));
            Assert.AreEqual(new Vector2(-200,   0), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 350));
            Assert.AreEqual(new Vector2(-200,   0), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 500));
            
            Assert.AreEqual(new Vector2(   0, 300), grid.GetSurroudingAnchorDistances(Orientation.InDepth, -1));
            Assert.AreEqual(new Vector2(   0, 300), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 0));
            Assert.AreEqual(new Vector2( -50, 250), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 50));
            Assert.AreEqual(new Vector2( -80, 220), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 80));
            Assert.AreEqual(new Vector2(   0, 300), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 300));
            Assert.AreEqual(new Vector2( -10, 290), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 310));
            Assert.AreEqual(new Vector2(-300,   0), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 600));
            Assert.AreEqual(new Vector2(-300,   0), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 900));
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            sprites = Content.Load<SpriteSheet>("UIImages");

            var lifeBar = new ImageElement { Source = SpriteFromSheet.Create(sprites, "Logo"), HorizontalAlignment = HorizontalAlignment.Center };
            lifeBar.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3);

            var quitText = new TextBlock { Text = "Quit Game", Font = Content.Load<SpriteFont>("MicrosoftSansSerif15") };
            ApplyTextBlockDefaultStyle(quitText);
            var quitGameButton = new Button
            {
                Content = quitText,
                VerticalAlignment = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Left,
                Padding = Thickness.UniformRectangle(10),
            };
            ApplyButtonDefaultStyle(quitGameButton);
            quitGameButton.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            quitGameButton.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            quitGameButton.Click += (sender, args) => Exit();

            modalButton1Text = new TextBlock { Text = "Close Modal window 1", Font = Content.Load<SpriteFont>("MicrosoftSansSerif15") };
            ApplyTextBlockDefaultStyle(modalButton1Text);
            var modalButton1 = new Button
            {
                Name = "Button Modal 1",
                Content = modalButton1Text,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Padding = Thickness.UniformRectangle(10),
            };
            ApplyButtonDefaultStyle(modalButton1);
            modalButton1.Click += ModalButton1OnClick;
            modal1 = new ModalElement { Content = modalButton1, Name = "Modal 1"};
            modal1.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);
            modal1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            modal1.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            modal1.OutsideClick += Modal1OnOutsideClick;

            modalButton2Text = new TextBlock { Text = "Close Modal window 2", Font = Content.Load<SpriteFont>("MicrosoftSansSerif15") };
            ApplyTextBlockDefaultStyle(modalButton2Text);
            var modalButton2 = new Button
            {
                Name = "Button Modal 2",
                Content = modalButton2Text,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Padding = Thickness.UniformRectangle(10),
            };
            ApplyButtonDefaultStyle(modalButton2);
            modalButton2.Click += ModalButton2OnClick;
            modal2 = new ModalElement { Content = modalButton2, Name = "Modal 2" };
            modal2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2);
            modal2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            modal2.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            modal2.OutsideClick += Modal2OnOutsideClick;

            uniformGrid = new UniformGrid { Columns = 3, Rows = 3 };
            uniformGrid.Children.Add(modal1);
            uniformGrid.Children.Add(modal2);
            uniformGrid.Children.Add(lifeBar);
            uniformGrid.Children.Add(quitGameButton);
            
            UIComponent.Page = new Engine.UIPage { RootElement = uniformGrid };
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var resolution = (Vector3)UIComponent.VirtualResolution;

            var canvas = new Canvas();
            var imgElt = new ImageElement { Name = "UV image", Source = new Sprite(Asset.Load<Texture>("uv")), Width = resolution.X / 5, Height = resolution.Y / 5, StretchType = StretchType.Fill };
            imgElt.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One);
            imgElt.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(resolution.X / 10, resolution.Y / 10, 0));
            imgElt.DependencyProperties.Set(Panel.ZIndexPropertyKey, -1);

            stackPanel = new StackPanel { Orientation = Orientation.Vertical };

            scrollViewer = new ScrollViewer { ScrollMode = ScrollingMode.Vertical };
            scrollViewer.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(resolution.X / 4, resolution.Y / 10, 0));
            scrollViewer.Content = stackPanel;

            var button1 = new Button { Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5), LocalMatrix = Matrix.Scaling(2, 2, 2) };
            var textOnly = new TextBlock { Text = "Text only button", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextColor = new Color(1f, 0, 0, 0.5f) };
            button1.Content = textOnly;

            var button2 = new Button { Name = "Button2", Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5) };
            var imageContent = new ImageElement { Name = "Image Button2", Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch, MaximumHeight = 50 };
            button2.Content = imageContent;

            var button3 = new Button { Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5) };
            var stackContent = new StackPanel { Orientation = Orientation.Horizontal };
            var stackImage = new ImageElement { Name = "Image stack panel", Source = new Sprite(Asset.Load<Texture>("uv")), MaximumHeight = 50 };
            var stackText = new TextBlock { Text = "button text", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), Margin = Thickness.UniformRectangle(5) };
            stackContent.Children.Add(stackImage);
            stackContent.Children.Add(stackText);
            button3.Content = stackContent;

            var button4 = new Button { Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Right, Padding = Thickness.UniformRectangle(5) };
            var imageContent2 = new ImageElement { Name = "button 4 uv image", Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch, MaximumHeight = 40, Opacity = 0.5f };
            button4.Content = imageContent2;

            var button5 = new Button { Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Left, Padding = Thickness.UniformRectangle(5) };
            var textOnly2 = new TextBlock { Text = "Left aligned", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") };
            button5.Content = textOnly2;

            var button6 = new ImageButton
            {
                Height = 50,
                Margin = Thickness.UniformRectangle(5),
                HorizontalAlignment = HorizontalAlignment.Center,
                PressedImage = new Sprite(Asset.Load<Texture>("ImageButtonPressed")),
                NotPressedImage = new Sprite(Asset.Load<Texture>("ImageButtonNotPressed")),
            };

            toggle = new ToggleButton
            {
                Content = new TextBlock { Text = "Toggle button test", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") },
                IsThreeState = true
            };

            scrollingText = new ScrollingText { Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), Text = "<<<--- Scrolling text in a button ", IsEnabled = IsUpdateAutomatic };
            var button7 = new Button { Margin = Thickness.UniformRectangle(5), Content = scrollingText };

            var uniformGrid = new UniformGrid { Rows = 2, Columns = 2 };
            var gridText = new TextBlock { Text = "Uniform grid", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center};
            gridText.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            var buttonLeft = new Button { Content = new TextBlock { Text = "unif-grid left", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center } };
            buttonLeft.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            var buttonRight = new Button { Content = new TextBlock { Text = "unif-grid right", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center } };
            buttonRight.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            buttonRight.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            uniformGrid.Children.Add(gridText);
            uniformGrid.Children.Add(buttonLeft);
            uniformGrid.Children.Add(buttonRight);

            stackPanel.Children.Add(button1);
            stackPanel.Children.Add(button2);
            stackPanel.Children.Add(button3);
            stackPanel.Children.Add(button4);
            stackPanel.Children.Add(button5);
            stackPanel.Children.Add(button6);
            stackPanel.Children.Add(toggle);
            stackPanel.Children.Add(button7);
            stackPanel.Children.Add(uniformGrid);

            canvas.Children.Add(imgElt);
            canvas.Children.Add(scrollViewer);

            UIComponent.RootElement = canvas;
        }
Beispiel #13
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            const float relativeSize = 1 / 6f;

            var canvas = new Canvas();
            canvas.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1);

            // left/top
            var image1 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image1.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image1.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(0, 0, 0));
            image1.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 0, 0));
            canvas.Children.Add(image1);

            // right/top
            var image2 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image2.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image2.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1, 0, 0));
            image2.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(1, 0, 0));
            canvas.Children.Add(image2);

            // left/bottom
            var image3 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image3.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image3.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(0, 1, 0));
            image3.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 1, 0));
            canvas.Children.Add(image3);

            // 1/3 right/bottom
            var image4 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image4.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image4.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1, 1, 0));
            image4.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(1, 1, 0));
            canvas.Children.Add(image4);

            // 1/3 left/top middle centered
            var image5 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image5.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image5.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1/3f, 1/3f, 0));
            image5.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 0.5f, 0));
            canvas.Children.Add(image5);

            // 1/3 right/top right aligned 
            var image6 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image6.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image6.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(2 / 3f, 1 / 3f, 0));
            image6.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 0.5f, 0));
            canvas.Children.Add(image6);

            // 1/3 left/bottom bottom aligned
            var image7 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image7.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image7.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1/3f, 2/3f, 0));
            image7.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 0, 0));
            canvas.Children.Add(image7);

            // 1/3 right/bottom top aligned
            var image8 = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch };
            image8.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One);
            image8.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(2/3f, 2/3f, 0));
            image8.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 1, 0));
            canvas.Children.Add(image8);
            
            var grid = new UniformGrid { Rows = 3, Columns = 3 };
            for (int c = 0; c < 3; c++)
                for (int r = 0; r < 3; r++)
                    CreateAndInsertButton(grid, c, r);

            var baseGrid = new UniformGrid();
            baseGrid.Children.Add(grid);
            baseGrid.Children.Add(canvas);

            UIComponent.RootElement = baseGrid;
        }
Beispiel #14
0
 private void CreateAndInsertButton(UniformGrid grid, int c, int r)
 {
     var button = new Button();
     button.DependencyProperties.Set(GridBase.RowPropertyKey, r);
     button.DependencyProperties.Set(GridBase.ColumnPropertyKey, c);
     grid.Children.Add(button);
 }