Example #1
0
        /// <summary>Reset sizes and positions for UI buttons.</summary>
        /// <returns>Visible buttons count.</returns>
        private MainMenuLayout RepositionToolButtons()
        {
            MainMenuLayout layout = new MainMenuLayout();

            // Recreate tool buttons
            float y          = ScaledSize.GetTitlebarHeight();
            float buttonSize = ScaledSize.GetButtonSize();
            float spacing    = buttonSize / 8f;

            layout.CountEnabledButtons(Buttons);

            int   placedInARow = 0;
            float x            = spacing;

            foreach (BaseMenuButton button in Buttons)
            {
                if (button.IsVisible())
                {
                    button.Show();
                    button.relativePosition = new Vector3(x, y);

                    x += buttonSize + spacing;

                    placedInARow++;
                    layout.MaxCols = Math.Max(layout.MaxCols, placedInARow);

                    if (layout.IsRowBreak(placedInARow, ScaledSize.NUM_COLS))
                    {
                        y           += buttonSize + spacing;
                        x            = spacing; // reset to the left side of the button area
                        placedInARow = 0;
                        layout.Rows++;
                    }
                }
                else
                {
                    button.Hide();
                    // to avoid window upsizing to fit an invisible button
                    button.relativePosition = Vector3.zero;
                }

                button.width  = buttonSize;
                button.height = buttonSize;
                button.Invalidate();
            } // foreach button

            // Special case when new row was broken but no buttons placed on it, reduce Rows count
            // happens when button count is even
            if (x <= 2 * spacing)
            {
                layout.Rows--;
            }

            return(layout);
        }
Example #2
0
        public override void OnRescaleRequested()
        {
            // Update size
            //--------------
            menuLayout_ = RepositionToolButtons();
            this.width  = ScaledSize.GetWidth(menuLayout_.MaxCols);
            this.height = ScaledSize.GetHeight(menuLayout_.Rows);

            // Update drag size
            //-------------------
            this.Drag.width  = this.width;
            this.Drag.height = ScaledSize.GetTitlebarHeight();
        }
Example #3
0
        public void UpdatePosition(Vector2 pos)
        {
            Rect rect = new Rect(
                pos.x,
                pos.y,
                ModUI.Instance.MainMenu.width,
                ScaledSize.GetHeight());
            Vector2 resolution = UIView.GetAView().GetScreenResolution();

            VectorUtil.ClampRectToScreen(ref rect, resolution);
            Log.Info($"Setting main menu position to [{pos.x},{pos.y}]");
            absolutePosition = rect.position;
            Invalidate();
        }