Exemplo n.º 1
0
 public void OpenCentered()
 {
     if (_firstTimeOpened)
     {
         LayoutContainer.SetSize(this, CombinedMinimumSize);
         Open();
         LayoutContainer.SetPosition(this, (Parent !.Size - Size) / 2);
         _firstTimeOpened = false;
     }
     else
     {
         Open();
     }
 }
Exemplo n.º 2
0
 public void OpenToLeft()
 {
     if (_firstTimeOpened)
     {
         LayoutContainer.SetSize(this, CombinedMinimumSize);
         Open();
         LayoutContainer.SetPosition(this, (0, (Parent !.Size.Y - Size.Y) / 2));
         _firstTimeOpened = false;
     }
     else
     {
         Open();
     }
 }
Exemplo n.º 3
0
        private bool OnContinueActionDrag(float frameTime)
        {
            // stop if there's no action in the slot
            if (Locked || DragDropHelper.Dragged?.Action == null)
            {
                return(false);
            }

            // keep dragged entity centered under mouse
            LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled.Position - (32, 32));
            // we don't set this visible until frameupdate, otherwise it flickers
            _dragShadow.Visible = true;
            return(true);
        }
        public void PopupMessage(ScreenCoordinates coordinates, string message)
        {
            var label = new PopupLabel
            {
                Text         = message,
                StyleClasses = { StyleNano.StyleClassPopupMessage },
            };

            _userInterfaceManager.PopupRoot.AddChild(label);
            var minimumSize = label.CombinedMinimumSize;

            LayoutContainer.SetPosition(label, label.InitialPos = coordinates.Position - minimumSize / 2);
            _aliveLabels.Add(label);
        }
Exemplo n.º 5
0
        public AlertsUI()
        {
            IoCManager.InjectDependencies(this);
            RobustXamlLoader.Load(this);

            LayoutContainer.SetGrowHorizontal(this, LayoutContainer.GrowDirection.Begin);
            LayoutContainer.SetGrowVertical(this, LayoutContainer.GrowDirection.End);
            LayoutContainer.SetAnchorTop(this, 0f);
            LayoutContainer.SetAnchorRight(this, 1f);
            LayoutContainer.SetAnchorBottom(this, 1f);
            LayoutContainer.SetMarginBottom(this, -180);
            LayoutContainer.SetMarginTop(this, 250);
            LayoutContainer.SetMarginRight(this, -10);
        }
Exemplo n.º 6
0
        private void OnChatResized(ChatResizedEventArgs chatResizedEventArgs)
        {
            // resize us to fit just below the chatbox
            var _chatManager = IoCManager.Resolve <IChatManager>();

            if (_chatManager.CurrentChatBox != null)
            {
                LayoutContainer.SetMarginTop(this, chatResizedEventArgs.NewBottom + ChatSeparation);
            }
            else
            {
                LayoutContainer.SetMarginTop(this, 250);
            }
        }
Exemplo n.º 7
0
        public WiresMenu(WiresBoundUserInterface owner)
        {
            IoCManager.InjectDependencies(this);

            Owner = owner;
            var rootContainer = new LayoutContainer {
                Name = "WireRoot"
            };

            AddChild(rootContainer);

            MouseFilter = MouseFilterMode.Stop;

            var panelTex = _resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
            var back     = new StyleBoxTexture
            {
                Texture  = panelTex,
                Modulate = Color.FromHex("#25252A"),
            };

            back.SetPatchMargin(StyleBox.Margin.All, 10);

            var topPanel = new PanelContainer
            {
                PanelOverride = back,
                MouseFilter   = MouseFilterMode.Pass
            };
            var bottomWrap = new LayoutContainer
            {
                Name = "BottomWrap"
            };
            var bottomPanel = new PanelContainer
            {
                PanelOverride = back,
                MouseFilter   = MouseFilterMode.Pass
            };

            var shadow = new BoxContainer
            {
                Orientation = LayoutOrientation.Horizontal,
                Children    =
                {
                    new PanelContainer
                    {
                        MinSize       = (2, 0),
                        PanelOverride = new StyleBoxFlat{
                            BackgroundColor = Color.FromHex("#525252ff")
                        }
                    },
Exemplo n.º 8
0
        public DebugConsole(IClientConsole console, IResourceManager resMan)
        {
            _console         = console;
            _resourceManager = resMan;

            Visible = false;

            var styleBox = new StyleBoxFlat
            {
                BackgroundColor = Color.FromHex("#25252add"),
            };

            styleBox.SetContentMarginOverride(StyleBox.Margin.All, 3);

            AddChild(new LayoutContainer
            {
                Children =
                {
                    (MainControl                  = new VBoxContainer
                    {
                        SeparationOverride        =                    0,
                        Children                  =
                        {
                            (Output               = new OutputPanel
                            {
                                SizeFlagsVertical = SizeFlags.FillExpand,
                                StyleBoxOverride  = styleBox
                            }),
                            (CommandBar           = new HistoryLineEdit {
                                PlaceHolder       = "Command Here"
                            })
                        }
                    })
                }
            });

            LayoutContainer.SetAnchorPreset(MainControl, LayoutContainer.LayoutPreset.TopWide);
            LayoutContainer.SetAnchorBottom(MainControl, 0.35f);

            CommandBar.OnKeyBindDown    += CommandBarOnOnKeyBindDown;
            CommandBar.OnTextEntered    += CommandEntered;
            CommandBar.OnHistoryChanged += OnHistoryChanged;

            _console.AddString    += (_, args) => AddLine(args.Text, args.Color);
            _console.AddFormatted += (_, args) => AddFormattedLine(args.Message);
            _console.ClearText    += (_, args) => Clear();

            _loadHistoryFromDisk();
        }
        protected override void FrameUpdate(FrameEventArgs args)
        {
            base.FrameUpdate(args);

            _timeLeft -= args.DeltaSeconds;

            if (_timeLeft <= FadeTime)
            {
                // Update alpha if we're fading.
                Modulate = Color.White.WithAlpha(_timeLeft / FadeTime);
            }

            if (_senderEntity.Deleted || _timeLeft <= 0)
            {
                // Timer spawn to prevent concurrent modification exception.
                Timer.Spawn(0, Die);
                return;
            }

            // Lerp to our new vertical offset if it's been modified.
            if (MathHelper.CloseToPercent(_verticalOffsetAchieved - VerticalOffset, 0, 0.1))
            {
                _verticalOffsetAchieved = VerticalOffset;
            }
            else
            {
                _verticalOffsetAchieved = MathHelper.Lerp(_verticalOffsetAchieved, VerticalOffset, 10 * args.DeltaSeconds);
            }

            if (!_senderEntity.Transform.Coordinates.IsValid(_senderEntity.EntityManager))
            {
                return;
            }

            var worldPos    = _senderEntity.Transform.WorldPosition;
            var scale       = _eyeManager.MainViewport.GetRenderScale();
            var offset      = new Vector2(0, EntityVerticalOffset * EyeManager.PixelsPerMeter * scale);
            var lowerCenter = (_eyeManager.WorldToScreen(worldPos) - offset) / UIScale;

            var screenPos = lowerCenter - (Width / 2, ContentHeight + _verticalOffsetAchieved);

            // Round to nearest 0.5
            screenPos = (screenPos * 2).Rounded() / 2;
            LayoutContainer.SetPosition(this, screenPos);

            var height = MathF.Ceiling(MathHelper.Clamp(lowerCenter.Y - screenPos.Y, 0, ContentHeight));

            SetHeight = height;
        }
Exemplo n.º 10
0
 public void OpenToLeft()
 {
     if (_firstTimeOpened)
     {
         Measure(Vector2.Infinity);
         SetSize = DesiredSize;
         Open();
         LayoutContainer.SetPosition(this, (0, (Parent !.Size.Y - DesiredSize.Y) / 2));
         _firstTimeOpened = false;
     }
     else
     {
         Open();
     }
 }
Exemplo n.º 11
0
            protected override void FrameUpdate(FrameEventArgs eventArgs)
            {
                TimeLeft += eventArgs.DeltaSeconds;

                var position = Entity == null
                    ? InitialPos
                    : (_eyeManager.CoordinatesToScreen(Entity.Transform.Coordinates).Position / UIScale) - DesiredSize / 2;

                LayoutContainer.SetPosition(this, position - (0, 20 * (TimeLeft * TimeLeft + TimeLeft)));

                if (TimeLeft > 0.5f)
                {
                    Modulate = Color.White.WithAlpha(1f - 0.2f * (float)Math.Pow(TimeLeft - 0.5f, 3f));
                }
            }
        public StackContextElement(IEnumerable <IEntity> entities, StackContextElement?pre, ContextMenuPopup?parentMenu)
            : base(parentMenu)
        {
            Pre             = pre;
            ContextEntities = new(entities);
            _spriteView     = new SpriteView
            {
                Sprite = ContextEntities.First().GetComponent <ISpriteComponent>()
            };
            _label = new Label
            {
                Text         = Loc.GetString(ContextEntities.Count.ToString()),
                StyleClasses = { StyleNano.StyleClassContextMenuCount }
            };

            LayoutContainer.SetAnchorPreset(_label, LayoutContainer.LayoutPreset.BottomRight);
            LayoutContainer.SetGrowHorizontal(_label, LayoutContainer.GrowDirection.Begin);
            LayoutContainer.SetGrowVertical(_label, LayoutContainer.GrowDirection.Begin);

            AddChild(
                new BoxContainer
            {
                Orientation        = LayoutOrientation.Horizontal,
                SeparationOverride = 6,
                Children           =
                {
                    new LayoutContainer {
                        Children =      { _spriteView,_label }
                    },
                    new BoxContainer
                    {
                        Orientation        = LayoutOrientation.Horizontal,
                        SeparationOverride = 6,
                        Children           =
                        {
                            new Label
                            {
                                Text = Loc.GetString(ContextEntities.First().Name)
                            },
                            new TextureRect
                            {
                                Texture      = IoCManager.Resolve <IResourceCache>().GetTexture("/Textures/Interface/VerbIcons/group.svg.192dpi.png"),
                                TextureScale = (0.5f, 0.5f),
                                Stretch      = TextureRect.StretchMode.KeepCentered,
                            }
                        }
                    }
                }, Margin = new Thickness(0, 0, 10, 0)
Exemplo n.º 13
0
        private void PerformLayout()
        {
            Visible     = false;
            MouseFilter = MouseFilterMode.Ignore;

            var styleBox = new StyleBoxFlat
            {
                BackgroundColor = Color.FromHex("#25252add"),
            };

            styleBox.SetContentMarginOverride(StyleBox.Margin.All, 3);

            AddChild(new LayoutContainer
            {
                MouseFilter = MouseFilterMode.Ignore,
                Children    =
                {
                    (MainControl                  = new VBoxContainer
                    {
                        SeparationOverride        =                    0,
                        Children                  =
                        {
                            (Output               = new OutputPanel
                            {
                                SizeFlagsVertical = SizeFlags.FillExpand,
                                StyleBoxOverride  = styleBox
                            }),
                            (CommandBar           = new LineEdit {
                                PlaceHolder       = "Command Here"
                            })
                        }
                    })
                }
            });

            LayoutContainer.SetAnchorPreset(MainControl, LayoutContainer.LayoutPreset.TopWide);
            LayoutContainer.SetAnchorBottom(MainControl, 0.35f);

            CommandBar.OnKeyBindDown += CommandBarOnOnKeyBindDown;
            CommandBar.OnTextEntered += CommandEntered;
            CommandBar.OnTextChanged += CommandBarOnOnTextChanged;

            _console.AddString    += (_, args) => AddLine(args.Text, args.Color);
            _console.AddFormatted += (_, args) => AddFormattedLine(args.Message);
            _console.ClearText    += (_, args) => Clear();

            _loadHistoryFromDisk();
        }
Exemplo n.º 14
0
        public WiresMenu(WiresBoundUserInterface owner)
        {
            var resourceCache = IoCManager.Resolve <IResourceCache>();

            Owner = owner;
            var rootContainer = new LayoutContainer {
                Name = "WireRoot"
            };

            AddChild(rootContainer);

            MouseFilter = MouseFilterMode.Stop;

            var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
            var back     = new StyleBoxTexture
            {
                Texture  = panelTex,
                Modulate = Color.FromHex("#25252A"),
            };

            back.SetPatchMargin(StyleBox.Margin.All, 10);

            var topPanel = new PanelContainer
            {
                PanelOverride = back,
                MouseFilter   = MouseFilterMode.Pass
            };
            var bottomWrap = new LayoutContainer
            {
                Name = "BottomWrap"
            };
            var bottomPanel = new PanelContainer
            {
                PanelOverride = back,
                MouseFilter   = MouseFilterMode.Pass
            };

            var shadow = new HBoxContainer
            {
                Children =
                {
                    new PanelContainer
                    {
                        CustomMinimumSize = (2, 0),
                        PanelOverride     = new StyleBoxFlat {
                            BackgroundColor = Color.FromHex("#525252ff")
                        }
                    },
Exemplo n.º 15
0
        public override void Startup()
        {
            _gameHud = new GameHud()
            {
                Visible = false
            };
            _lobbyHud = new LobbyHud()
            {
                Visible = false
            };

            LayoutContainer.SetAnchorAndMarginPreset(_gameHud, LayoutContainer.LayoutPreset.Wide);
            LayoutContainer.SetAnchorAndMarginPreset(_lobbyHud, LayoutContainer.LayoutPreset.Wide);

            _userInterface.StateRoot.AddChild(_gameHud);
            _userInterface.StateRoot.AddChild(_lobbyHud);
        }
Exemplo n.º 16
0
 public void OpenCentered()
 {
     if (_firstTimeOpened)
     {
         LayoutContainer.SetSize(this, CombinedMinimumSize);
         Open();
         // An explaination: The BadOpenGLVersionWindow was showing up off the top-left corner of the screen.
         // Basically, if OpenCentered happens super-early, RootControl doesn't get time to layout children.
         // But we know that this is always going to be one of the roots anyway for now.
         LayoutContainer.SetPosition(this, (UserInterfaceManager.RootControl.Size - Size) / 2);
         _firstTimeOpened = false;
     }
     else
     {
         Open();
     }
 }
Exemplo n.º 17
0
        public override void Update(float frameTime)
        {
            base.Update(frameTime);
            if (_tooltips == 0)
            {
                if (_aiBoxes.Count > 0)
                {
                    foreach (var(_, panel) in _aiBoxes)
                    {
                        panel.Dispose();
                    }

                    _aiBoxes.Clear();
                }
                return;
            }

            var deletedEntities = new List <IEntity>(0);

            foreach (var(entity, panel) in _aiBoxes)
            {
                if (entity.Deleted)
                {
                    deletedEntities.Add(entity);
                    continue;
                }

                if (!_eyeManager.GetWorldViewport().Contains(entity.Transform.WorldPosition))
                {
                    panel.Visible = false;
                    continue;
                }

                var(x, y) = _eyeManager.CoordinatesToScreen(entity.Transform.Coordinates).Position;
                var offsetPosition = new Vector2(x - panel.Width / 2, y - panel.Height - 50f);
                panel.Visible = true;

                LayoutContainer.SetPosition(panel, offsetPosition);
            }

            foreach (var entity in deletedEntities)
            {
                _aiBoxes.Remove(entity);
            }
        }
Exemplo n.º 18
0
        public void TestMarginLayoutMinimumSize()
        {
            var control = new LayoutContainer {
                Size = new Vector2(100, 100)
            };
            var child = new Control
            {
                MinSize = new Vector2(50, 50),
            };

            LayoutContainer.SetMarginRight(child, 20);
            LayoutContainer.SetMarginBottom(child, 20);

            control.AddChild(child);
            control.Arrange(new UIBox2(0, 0, 100, 100));

            Assert.That(child.Size, Is.EqualTo(new Vector2(50, 50)));
        }
Exemplo n.º 19
0
        protected override void FrameUpdate(FrameEventArgs args)
        {
            base.FrameUpdate(args);

            if (Entity.Deleted ||
                _eyeManager.CurrentMap != Entity.Transform.MapID)
            {
                Visible = false;
                return;
            }

            Visible = true;

            var screenCoordinates = _eyeManager.CoordinatesToScreen(Entity.Transform.Coordinates);
            var playerPosition    = new ScreenCoordinates(screenCoordinates.X / UIScale, screenCoordinates.Y / UIScale);

            LayoutContainer.SetPosition(this, new Vector2(playerPosition.X - Width / 2, playerPosition.Y - Height - 30.0f));
        }
Exemplo n.º 20
0
        /// <summary>
        /// Positions the provided control as a tooltip within the provided screenBounds based on its current
        /// combined minimum size.
        /// Defaults to the top left corner
        /// of the control being placed at the indicated position but
        /// adjusting to a different corner if the control would go beyond the edge of the bounds.
        /// </summary>
        /// <param name="screenBounds">max x and y screen coordinates for the tooltip to occupy, tooltip
        /// will be shifted to avoid exceeding these bounds.</param>
        /// <param name="screenPosition">position to place the tooltip at, in screen coordinates</param>
        /// <param name="tooltip">control to position (current size will be used to determine bounds)</param>
        public static void PositionTooltip(Vector2 screenBounds, Vector2 screenPosition, Control tooltip)
        {
            LayoutContainer.SetPosition(tooltip, screenPosition);

            var combinedMinSize = tooltip.CombinedMinimumSize;

            var(right, bottom) = tooltip.Position + combinedMinSize;

            if (right > screenBounds.X)
            {
                LayoutContainer.SetPosition(tooltip, (screenPosition.X - combinedMinSize.X, tooltip.Position.Y));
            }

            if (bottom > screenBounds.Y)
            {
                LayoutContainer.SetPosition(tooltip, (tooltip.Position.X, screenPosition.Y - combinedMinSize.Y));
            }
        }
Exemplo n.º 21
0
        public void TestMarginLayoutMinimumSize()
        {
            var control = new LayoutContainer {
                Size = new Vector2(100, 100)
            };
            var child = new Control
            {
                CustomMinimumSize = new Vector2(50, 50),
            };

            LayoutContainer.SetMarginRight(child, 20);
            LayoutContainer.SetMarginBottom(child, 20);

            control.AddChild(child);
            control.ForceRunLayoutUpdate();

            Assert.That(child.Size, Is.EqualTo(new Vector2(50, 50)));
        }
Exemplo n.º 22
0
        private void _initializeCommon()
        {
            RootControl = new Control
            {
                Name         = "UIRoot",
                MouseFilter  = Control.MouseFilterMode.Ignore,
                IsInsideTree = true
            };
            RootControl.Size = _displayManager.ScreenSize / UIScale;
            _displayManager.OnWindowResized += args => _updateRootSize();

            StateRoot = new LayoutContainer
            {
                Name        = "StateRoot",
                MouseFilter = Control.MouseFilterMode.Ignore
            };
            RootControl.AddChild(StateRoot);

            WindowRoot = new LayoutContainer
            {
                Name        = "WindowRoot",
                MouseFilter = Control.MouseFilterMode.Ignore
            };
            RootControl.AddChild(WindowRoot);

            PopupRoot = new LayoutContainer
            {
                Name        = "PopupRoot",
                MouseFilter = Control.MouseFilterMode.Ignore
            };
            RootControl.AddChild(PopupRoot);

            ModalRoot = new LayoutContainer
            {
                Name        = "ModalRoot",
                MouseFilter = Control.MouseFilterMode.Ignore,
            };
            RootControl.AddChild(ModalRoot);

            _tooltip = new Tooltip();
            PopupRoot.AddChild(_tooltip);
            _tooltip.Visible = false;
        }
        protected override void FrameUpdate(FrameEventArgs args)
        {
            base.FrameUpdate(args);

            MoreFrameUpdate(args);

            if (_entities.Deleted(Entity) || _eyeManager.CurrentMap != _entities.GetComponent <TransformComponent>(Entity).MapID)
            {
                Visible = false;
                return;
            }

            Visible = true;

            var screenCoordinates = _eyeManager.CoordinatesToScreen(_entities.GetComponent <TransformComponent>(Entity).Coordinates);
            var playerPosition    = UserInterfaceManager.ScreenToUIPosition(screenCoordinates);

            LayoutContainer.SetPosition(this, new Vector2(playerPosition.X - Width / 2, playerPosition.Y - Height - 30.0f));
        }
Exemplo n.º 24
0
        public Unit GetAbsoluteTop(LayoutContainer layout, Unit virtualTop)
        {
            // Set value to reverted Y-Axis
            float floatValue = layout.Element.Page.Height.Points - virtualTop.Points;

            if (virtualTop.HasRelation)
            {
                if (virtualTop.Relation.From == "top")
                {
                    floatValue = virtualTop.Relation.Element.Layout.Top.Points - virtualTop.Points;
                }

                if (virtualTop.Relation.From == "bottom")
                {
                    floatValue = virtualTop.Relation.Element.Layout.Bottom.Points - virtualTop.Points;
                }
            }
            return(new Unit(floatValue));
        }
Exemplo n.º 25
0
        private void ClampSize(float?desiredLeft = null, float?desiredBottom = null)
        {
            if (Parent == null)
            {
                return;
            }

            // var top = Rect.Top;
            var right  = Rect.Right;
            var left   = desiredLeft ?? Rect.Left;
            var bottom = desiredBottom ?? Rect.Bottom;

            // clamp so it doesn't go too high or low (leave space for alerts UI)
            var maxBottom = Parent.Size.Y - MinDistanceFromBottom;

            if (maxBottom <= MinHeight)
            {
                // we can't fit in our given space (window made awkwardly small), so give up
                // and overlap at our min height
                bottom = MinHeight;
            }
            else
            {
                bottom = Math.Clamp(bottom, MinHeight, maxBottom);
            }

            var maxLeft = Parent.Size.X - MinWidth;

            if (maxLeft <= MinLeft)
            {
                // window too narrow, give up and overlap at our max left
                left = maxLeft;
            }
            else
            {
                left = Math.Clamp(left, MinLeft, maxLeft);
            }

            LayoutContainer.SetMarginLeft(this, -((right + 10) - left));
            LayoutContainer.SetMarginBottom(this, bottom);

            ChatMgr.ChatBoxOnResized(new ChatResizedEventArgs(bottom));
        }
Exemplo n.º 26
0
        public override void Startup()
        {
            base.Startup();

            _gameChat = new ChatBox();
            _userInterfaceManager.StateRoot.AddChild(_gameChat);
            LayoutContainer.SetAnchorAndMarginPreset(_gameChat, LayoutContainer.LayoutPreset.TopRight, margin: 10);
            LayoutContainer.SetAnchorAndMarginPreset(_gameChat, LayoutContainer.LayoutPreset.TopRight, margin: 10);
            LayoutContainer.SetMarginLeft(_gameChat, -475);
            LayoutContainer.SetMarginBottom(_gameChat, 235);

            _userInterfaceManager.StateRoot.AddChild(_gameHud.RootControl);
            _chatManager.SetChatBox(_gameChat);
            _gameChat.DefaultChatFormat = "say \"{0}\"";
            _gameChat.Input.PlaceHolder = Loc.GetString("Say something! [ for OOC");

            _inputManager.SetInputCommand(ContentKeyFunctions.FocusChat,
                                          InputCmdHandler.FromDelegate(s => FocusChat(_gameChat)));
        }
Exemplo n.º 27
0
        protected override void FrameUpdate(FrameEventArgs args)
        {
            base.FrameUpdate(args);

            _timeLeft -= args.DeltaSeconds;

            if (_timeLeft <= FadeTime)
            {
                // Update alpha if we're fading.
                Modulate = Color.White.WithAlpha(_timeLeft / FadeTime);
            }

            if (_senderEntity.Deleted || _timeLeft <= 0)
            {
                // Timer spawn to prevent concurrent modification exception.
                Timer.Spawn(0, Die);
                return;
            }

            // Lerp to our new vertical offset if it's been modified.
            if (MathHelper.CloseTo(_verticalOffsetAchieved - VerticalOffset, 0, 0.1))
            {
                _verticalOffsetAchieved = VerticalOffset;
            }
            else
            {
                _verticalOffsetAchieved = MathHelper.Lerp(_verticalOffsetAchieved, VerticalOffset, 10 * args.DeltaSeconds);
            }

            var worldPos = _senderEntity.Transform.WorldPosition;

            worldPos += (0, EntityVerticalOffset);

            var lowerCenter = _eyeManager.WorldToScreen(worldPos) / UIScale;
            var screenPos   = lowerCenter - (Width / 2, ContentHeight + _verticalOffsetAchieved);

            LayoutContainer.SetPosition(this, screenPos);

            var height = MathHelper.Clamp(lowerCenter.Y - screenPos.Y, 0, ContentHeight);

            LayoutContainer.SetSize(this, (Size.X, height));
        }
Exemplo n.º 28
0
        public void TestMarginAnchorLayout()
        {
            var control = new LayoutContainer {
                Size = new Vector2(100, 100)
            };
            var child = new Control();

            LayoutContainer.SetMarginRight(child, -10);
            LayoutContainer.SetMarginBottom(child, -10);
            LayoutContainer.SetMarginTop(child, 10);
            LayoutContainer.SetMarginLeft(child, 10);
            LayoutContainer.SetAnchorRight(child, 1);
            LayoutContainer.SetAnchorBottom(child, 1);

            control.AddChild(child);
            control.ForceRunLayoutUpdate();

            Assert.That(child.Position, Is.EqualTo(new Vector2(10, 10)));
            Assert.That(child.Size, Is.EqualTo(new Vector2(80, 80)));
        }
Exemplo n.º 29
0
        public void TestGrowBoth()
        {
            var parent = new LayoutContainer {
                Size = (50, 50)
            };
            var child = new Control();

            LayoutContainer.SetGrowHorizontal(child, LayoutContainer.GrowDirection.Both);
            parent.AddChild(child);
            parent.ForceRunLayoutUpdate();

            // Child should be at 0,0.
            Assert.That(child.Position, Is.EqualTo(Vector2.Zero));

            child.CustomMinimumSize = (100, 100);
            parent.ForceRunLayoutUpdate();

            Assert.That(child.Position, Is.EqualTo(new Vector2(-50, 0)));
            Assert.That(child.Size, Is.EqualTo(new Vector2(100, 100)));
        }
Exemplo n.º 30
0
        public void Test()
        {
            var wrap      = new LayoutContainer();
            var container = new PopupContainer {
                CustomMinimumSize = (100, 100)
            };

            wrap.AddChild(container);

            // Need this wrapper so that container has the correct size.
            wrap.ForceRunLayoutUpdate();

            var popup = new Control {
                CustomMinimumSize = (50, 50)
            };

            container.AddChild(popup);

            PopupContainer.SetPopupOrigin(popup, (25, 25));

            container.ForceRunLayoutUpdate();

            Assert.That(popup.Position, Is.EqualTo(new Vector2(25, 25)));
            Assert.That(popup.Size, Is.EqualTo(new Vector2(50, 50)));

            // Test that pos gets pushed back to the top left if the size + offset is too large to fit.
            PopupContainer.SetPopupOrigin(popup, (75, 75));

            container.ForceRunLayoutUpdate();

            Assert.That(popup.Position, Is.EqualTo(new Vector2(50, 50)));
            Assert.That(popup.Size, Is.EqualTo(new Vector2(50, 50)));

            // Test that pos = 0 if the popup is too large to fit.
            popup.CustomMinimumSize = (150, 150);

            container.ForceRunLayoutUpdate();

            Assert.That(popup.Position, Is.EqualTo(new Vector2(0, 0)));
            Assert.That(popup.Size, Is.EqualTo(new Vector2(150, 150)));
        }