Ejemplo n.º 1
0
 public Button(IUIStyle style, string text = "", IUITexture iconTex = null) : base(style)
 {
     Content = new IconLabel(style)
     {
         Texture = iconTex, Text = text, Enabled = false, Anchor = AnchoredRect.CreateHorizontallyStretched()
     };
 }
Ejemplo n.º 2
0
        public static Widget CreateRootPanel(IUIStyle uiStyle)
        {
            var basicDemoPane = new BasicDemoPane(uiStyle);

            var demoPanel = new ScrollPanel(uiStyle)
            {
                VerticalScrollbarMode = ScrollbarMode.None,
                Content = basicDemoPane
            }.DoWith(d => d.AddStyleClass("DemoPanel"));

            // Splitter
            return(new Splitter(uiStyle, Direction.Left)
            {
                Anchor = AnchoredRect.CreateFull(10),
                Collapsable = true,
                Collapsed = true,
                FirstPane = new BoxGroup(uiStyle, Orientation.Vertical, 0)
                {
                    { CreateDemoButton("Basic", demoPanel, basicDemoPane), true },
                    { CreateDemoButton("Notebook", demoPanel, new NotebookPane(uiStyle)), true },
                    { CreateDemoButton("Text Area", demoPanel, new TextAreaPane(uiStyle)), true },
                    { CreateDemoButton("Custom Viewport", demoPanel, new CustomViewportPane(uiStyle)), true }
                },
                SecondPane = demoPanel,
                FirstPaneMinSize = 200
            });
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public NotebookTab(IUIStyle style) : base(style)
        {
            activationRequestedSupport = new EventSupport <EventArgs>();
            closeRequestedSupport      = new EventSupport <EventArgs>();

            emptyContent = new Label(UIStyle)
            {
                Anchor = AnchoredRect.CreateHorizontallyStretched()
            };

            closeButton = new Button(UIStyle);
            closeButton.AddStyleClass(CloseButtonStyleClass);
            closeButton.Anchor           = AnchoredRect.CreateCentered();
            closeButton.ActionPerformed += OnCloseButtonOnClicked;

            InternalContent = new DockPanel(UIStyle);
            InternalContent.LastChildFill = true;
            InternalContent.Add(closeButton, DockPanelConstraint.Right);
            InternalContent.Add(emptyContent, DockPanelConstraint.Left);

            KeyPressed   += OnKeyPressed;
            MouseClicked += OnMouseClick;

            Focusable = true;
        }
Ejemplo n.º 5
0
        public Slider(IUIStyle style) : base(style)
        {
            valueChangedSupport = new EventSupport <EventArgs>();

            sliderHandle = new Button(UIStyle);
            sliderHandle.AddStyleClass(SliderHandleStyleClass);
            sliderHandle.Anchor        = AnchoredRect.CreateLeftAnchored();
            sliderHandle.MouseUp      += OnMouseUp;
            sliderHandle.MouseDown    += OnMouseDown;
            sliderHandle.MouseDragged += OnMouseDragged;

            sliderTrack        = new SliderTrack(UIStyle);
            sliderTrack.Anchor = AnchoredRect.Full;

            Group elements = new Group(UIStyle);

            elements.Anchor = AnchoredRect.Full;
            elements.Add(sliderTrack);
            elements.Add(sliderHandle);

            InternalContent = elements;
            Focusable       = true;

            MinValue = 0;
            MaxValue = 10;
            Step     = 1;
            Value    = 0;
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        NotebookTab CreateHomeTab()
        {
            void CreateNewTab(object sender, EventArgs args)
            {
                tabCounter += 1;
                var tab = new NotebookTab(UIStyle)
                {
                    Tag           = "Tab Content for " + tabCounter,
                    HeaderContent = new Label(UIStyle, $"Tab {tabCounter}"),
                    Content       = new Label(UIStyle, "Tab Content for " + tabCounter)
                };

                Content.Tabs.Add(tab);
            }

            return(new NotebookTab(UIStyle)
            {
                Content = new Button(UIStyle, "CreatePopup tab")
                {
                    Anchor = AnchoredRect.CreateFull(10),
                    OnActionPerformed = CreateNewTab
                },
                HeaderContent = new Label(UIStyle, "Home"),
                IsPinned = true,
                Tag = "Home"
            });
        }
Ejemplo n.º 8
0
            IWidget Create(AnchoredRect r)
            {
                var widget = Substitute.For <IWidget>();

                widget.Anchor.Returns(r);
                widget.Parent.ReturnsNull();
                return(widget);
            }
Ejemplo n.º 9
0
            public Rectangle ValidateFixedSizeChildSmall(AnchoredRect rect)
            {
                var widget = StubParent();

                widget.DesiredSize.Returns(new Size(50, 40));
                widget.Anchor.Returns(rect);

                return(widget.ArrangeChild(new Rectangle(10, 20, 0, 0)));
            }
Ejemplo n.º 10
0
        public void Arrange_2()
        {
            var tooltip = CreateTooltip("4");

            tooltip.Anchor = AnchoredRect.CreateTopLeftAnchored(200, 19);

            tooltip.Measure(new Size(float.PositiveInfinity, float.PositiveInfinity));
            tooltip.Arrange(tooltip.ArrangeChild(new Rectangle(10, 20, 200, 20)));
            tooltip.LayoutRect.Should().Be(new Rectangle(210, 39, 31, 35));
        }
Ejemplo n.º 11
0
            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));
            }
Ejemplo n.º 12
0
            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));
            }
Ejemplo n.º 13
0
        protected TextWidgetBase(IUIStyle style, IDocumentEditor <TView, TDocument> editor) : base(style)
        {
            textStyles = StyleSystem.StylesFor <TextStyleDefinition>();

            ChildrenChanged += HandleOnChildrenChanged;

            DocumentEditor = editor;
            Content        = DocumentEditor.CreateDocumentView(AnchoredRect.CreateTopAnchored());

            WrapText = WrapText.Auto;
        }
Ejemplo n.º 14
0
            public IPopUp <TContent> CreatePopup <TContent>(Point location, TContent content = null) where TContent : class, IWidget
            {
                var popUp = new PopUp <TContent>(rootPane.UIStyle)
                {
                    Anchor = AnchoredRect.CreateTopLeftAnchored(location.X, location.Y), Content = content
                };

                popUp.Closed += HandlePopUpClosed;
                rootPane.Screen.InvokeAfterEvents(() => { rootPane.AddPopUp(popUp); });
                return(popUp);
            }
Ejemplo n.º 15
0
        IWidget SetupUi()
        {
            var styleSystem = uiManager.UIStyle;

            var mapX = new TextField(styleSystem);

            mapX.Anchor = AnchoredRect.CreateCentered(100);
            mapX.Content.Document.DocumentModified += (_, _) => navModel.MapXText = mapX.Text;

            var mapY = new TextField(styleSystem);

            mapY.Anchor = AnchoredRect.CreateCentered(100);
            mapY.Content.Document.DocumentModified += (_, _) => navModel.MapYText = mapY.Text;

            var button = new Button(styleSystem, "Go!");

            button.ActionPerformed   += (_, _) => navModel.TryNavigate(GameRendering);
            navModel.PropertyChanged += (_, _) => button.Enabled = navModel.Valid;

            var rotateLeftButton = new Button(styleSystem, "Left");

            rotateLeftButton.ActionPerformed         +=
                (_, _) => GameRendering.RotationSteps = (GameRendering.RotationSteps + 1) % 4;

            var rotateRightButton = new Button(styleSystem, "Right");

            rotateRightButton.ActionPerformed        +=
                (_, _) => GameRendering.RotationSteps = (GameRendering.RotationSteps - 1) % 4;

            var hbox = new BoxGroup(styleSystem, Orientation.Horizontal, 5);

            hbox.Anchor = AnchoredRect.CreateBottomLeftAnchored();
            hbox.AddStyleClass("opaque-root");
            hbox.Add(new Label(styleSystem, "Move to: X: "));
            hbox.Add(mapX);
            hbox.Add(new Label(styleSystem, "Y: "));
            hbox.Add(mapY);
            hbox.Add(button);
            hbox.Add(rotateLeftButton);
            hbox.Add(rotateRightButton);

            group = new Group(styleSystem);
            group.Add(hbox);
            group.Focusable     = true;
            group.MouseDragged += OnMouseDragged;
            group.MouseDown    += OnMouseDragStarted;
            group.MouseUp      += OnMouseDragFinished;
            group.KeyReleased  += Root_KeyReleased;
            group.MouseMoved   += OnMouseMoved;
            group.Focused       = true;
            group.Anchor        = AnchoredRect.Full;
            return(group);
        }
Ejemplo n.º 16
0
            public void TestArrange()
            {
                var g = new Group(LayoutTestStyle.Create());

                g.Add(Create(AnchoredRect.Full));
                g.Add(Create(AnchoredRect.CreateFixed(200, 300, 400, 500)));

                g.Arrange(new Rectangle(0, 0, 500, 400));
                g.LayoutRect.Should().Be(new Rectangle(0, 0, 500, 400));

                g[0].Received().Arrange(new Rectangle(0, 0, 500, 400));
                g[1].Received().Arrange(new Rectangle(200, 300, 400, 500));
            }
Ejemplo n.º 17
0
        public void MeasureCheckMark()
        {
            var style = LayoutTestStyle.Create();

            var checkMark = new Button(style)
            {
                Anchor = AnchoredRect.CreateCentered()
            };

            style.StyleResolver.AddRoot(checkMark);
            checkMark.Measure(Size.Auto);
            checkMark.DesiredSize.Should().Be(new Size(40, 40));
        }
Ejemplo n.º 18
0
        public void MeasureNoScrollTopLeft()
        {
            var p = new PopUp <IWidget>(LayoutTestStyle.Create())
            {
                Padding = new Insets(10),
                Content = LayoutTestWidget.FixedSize(500, 300).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(40, 50))
            };

            p.Measure(Size.Auto);

            p.DesiredSize.Should().Be(new Size(520, 320));
            p.Content.DesiredSize.Should().Be(new Size(500, 300));
        }
Ejemplo n.º 19
0
        public void ArrangeVertical()
        {
            var g = new BoxGroup(LayoutTestStyle.Create());

            g.Spacing = 5;
            g.Add(LayoutTestWidget.FixedSize(200, 100).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(0, 0)));
            g.Add(LayoutTestWidget.FixedSize(150, 50).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(0, 0)));

            g.Arrange(new Rectangle(10, 20, 400, 300));

            g.LayoutRect.Should().Be(new Rectangle(10, 20, 400, 155));
            g[0].LayoutRect.Should().Be(new Rectangle(10, 20, 200, 100));
            g[1].LayoutRect.Should().Be(new Rectangle(10, 125, 150, 50));
        }
Ejemplo n.º 20
0
        public void ArrangeHorizontal()
        {
            var g = new BoxGroup(LayoutTestStyle.Create());

            g.Spacing     = 5;
            g.Orientation = Orientation.Horizontal;
            g.Add(LayoutTestWidget.FixedSize(200, 100).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(0, 0)));
            g.Add(LayoutTestWidget.FixedSize(150, 50).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(0, 0)));

            g.Arrange(new Rectangle(10, 20, 400, 300));

            g.LayoutRect.Should().Be(new Rectangle(10, 20, 355, 300));
            g[0].LayoutRect.Should().Be(new Rectangle(10, 20, 200, 100));
            g[1].LayoutRect.Should().Be(new Rectangle(215, 20, 150, 50));
        }
Ejemplo n.º 21
0
        public ListDataItemRenderer(IUIStyle style) : base(style)
        {
            selectionChangedSupport = new EventSupport <ListSelectionEventArgs>();
            Anchor          = AnchoredRect.CreateHorizontallyStretched();
            FocusedChanged += (s, e) =>
            {
                if (Focused)
                {
                    selectionChangedSupport.Raise(this, ListSelectionEventArgs.Adjusted);
                }
            };

            MouseClicked += OnMouseClick;
            KeyPressed   += OnKeyPressed;
        }
Ejemplo n.º 22
0
        public TextArea(IUIStyle style, IDocumentEditor <DocumentView <PlainTextDocument>, PlainTextDocument> editor) : base(style, editor)
        {
            ActionMap.Register(new KeyStroke(Keys.Enter), OnEnterPressed);
            ActionMap.Register(new KeyStroke(Keys.PageUp), OnPageUpPressed);
            ActionMap.Register(new KeyStroke(Keys.PageDown), OnPageDownPressed);

            lineNumberRenderer = new LineNumberWidget(UIStyle);
            lineNumberRenderer.AddNotify(this);
            lineNumberRenderer.Anchor       = AnchoredRect.CreateLeftAnchored();
            lineNumberRenderer.DocumentView = Content;
            RaiseChildAdded(0, lineNumberRenderer);

            DisplayLineNumbers  = true;
            Caret.CaretChanged += OnCaretChanged;
        }
Ejemplo n.º 23
0
        public void MeasureNoScroll()
        {
            var p = new ScrollPanel(LayoutTestStyle.Create())
            {
                // CornerSize = 10,
                Padding = new Insets(10),
                VerticalScrollbarMode = ScrollbarMode.None,
                Content = LayoutTestWidget.FixedSize(500, 300).WithAnchorRect(AnchoredRect.CreateFull(40))
            };

            p.UIStyle.StyleResolver.AddRoot(p);
            p.Measure(Size.Auto);

            p.DesiredSize.Should().Be(new Size(600, 400));
        }
Ejemplo n.º 24
0
        public Playing(IUIStyle s, Game1 parent, GraphicsDeviceManager man) : base(s)
        {
            mapWidget = new MapWidget(s);
            var exit = new Button(s, "Exit")
            {
                Anchor            = AnchoredRect.CreateFixed(0, 0, 100, 60),
                Color             = Color.Aquamarine,
                OnActionPerformed = (se, a) =>
                {
                    parent.State = Game1.GameState.MainMenu;
                }
            };

            this.Add(mapWidget);
            this.Add(exit);
        }
Ejemplo n.º 25
0
        public void ArrangeHugeAnchored()
        {
            var g = new BoxGroup(LayoutTestStyle.Create());

            g.Spacing     = 5;
            g.Orientation = Orientation.Horizontal;
            g.Add(LayoutTestWidget.FixedSize(2000, 1000).WithAnchorRect(AnchoredRect.CreateCentered(500, 500)));
            g.Add(LayoutTestWidget.FixedSize(150, 50).WithAnchorRect(AnchoredRect.CreateFull(10)));

            g.Arrange(new Rectangle(10, 20, 400, 300));

            g.DesiredSize.Should().Be(new Size(675, 500)); // 500 + 150 + 20 (from full-anchor) + 5
            g[0].DesiredSize.Should().Be(new Size(2000, 1000));
            g[1].DesiredSize.Should().Be(new Size(150, 50));

            g.LayoutRect.Should().Be(new Rectangle(10, 20, 675, 300));
            g[0].LayoutRect.Should().Be(new Rectangle(10, -80, 500, 500));
            g[1].LayoutRect.Should().Be(new Rectangle(525, 30, 150, 280));
        }
Ejemplo n.º 26
0
        public void PopUpLayoutTest()
        {
            var p = new PopUp <IWidget>(LayoutTestStyle.Create())
            {
                Padding = new Insets(10), Content = LayoutTestWidget.FixedSize(500, 300)
            };

            p.Anchor = AnchoredRect.CreateTopLeftAnchored(10, 20);

            var screen = Substitute.For <IScreenService>();

            var root = new RootPane(screen, LayoutTestStyle.Create());

            root.UIStyle.StyleResolver.AddRoot(root);
            root.AddPopUp(p);

            root.Arrange(new Rectangle(0, 0, 1270, 770));

            p.LayoutRect.Should().Be(new Rectangle(10, 20, 520, 320));
        }
Ejemplo n.º 27
0
        public MainMenu(IUIStyle s, Game1 parent) : base(s)
        {
            var lab = new Label(s, "Welcome to the game")
            {
                Anchor = AnchoredRect.CreateCentered()
            };

            var play = new Button(s, "Play")
            {
                Anchor            = AnchoredRect.CreateFixed(0, 0, 100, 60),
                Color             = Color.Aquamarine,
                OnActionPerformed = (se, a) =>
                {
                    parent.State = Game1.GameState.Playing;
                }
            };

            this.Add(lab);
            this.Add(play);
        }
Ejemplo n.º 28
0
        public void InsertOrderTest()
        {
            var p = new PopUp <IWidget>(LayoutTestStyle.Create())
            {
                Padding = new Insets(10), Content = LayoutTestWidget.FixedSize(500, 300)
            };

            p.Anchor = AnchoredRect.CreateTopLeftAnchored(10, 20);

            var screen = Substitute.For <IScreenService>();

            var root = new RootPane(screen, LayoutTestStyle.Create());

            root.Content = LayoutTestWidget.FixedSize(400, 400).WithAnchorRect(AnchoredRect.Full);
            root.AddPopUp(p);

            root.Count.Should().Be(3); // glasspane
            root[0].Should().BeSameAs(root.Content);
            root[1].Should().BeAssignableTo <GlassPane>();
            root[2].Should().BeSameAs(p);
        }
Ejemplo n.º 29
0
        public CheckBox(IUIStyle style) : base(style)
        {
            label = new Label(UIStyle)
            {
                Enabled = false
            };
            label.AddStyleClass(CheckBoxLabelStyleClass);

            checkMark = new Button(UIStyle)
            {
                Anchor = AnchoredRect.CreateCentered()
            };
            checkMark.AddStyleClass(CheckBoxButtonStyleClass);
            checkMark.ActionPerformed += OnActionPerformed;
            Content = new DockPanel(style)
            {
                { checkMark, DockPanelConstraint.Left }, { label, DockPanelConstraint.Left }
            };

            Selected = SelectionState.Selected;
        }
Ejemplo n.º 30
0
        IWidget CreateContent(IUIStyle style)
        {
            var btSelectDungeonDemo = new Button(style, "Dungeon Game Demo");

            btSelectDungeonDemo.ActionPerformed += OnDungeonDemoSelected;

            var btSelectStrategyDemo = new Button(style, "Strategy Game Demo");

            btSelectStrategyDemo.ActionPerformed += OnStrategyDemoSelected;

            var g = new Group(style)
            {
                new BoxGroup(style, Orientation.Vertical, 5)
                {
                    btSelectDungeonDemo,
                    btSelectStrategyDemo
                }
            };

            g.Anchor = AnchoredRect.CreateCentered();
            return(g);
        }