예제 #1
0
        public void Build(ImGui gui, float height)
        {
            this.gui    = gui;
            this.height = height;
            var rect  = gui.statePosition;
            var width = rect.Width;

            if (vertical)
            {
                width -= ScrollbarSize;
            }
            if (gui.isBuilding)
            {
                var innerRect = rect;
                innerRect.Width = width;
                contentSize     = MeasureContent(innerRect, gui);
                maxScroll       = Vector2.Max(contentSize - new Vector2(innerRect.Width, height), Vector2.Zero);
                var realHeight = collapsible ? MathF.Min(contentSize.Y, height) : height;
                innerRect.Height = rect.Height = realHeight;
                if (horizontal && maxScroll.X > 0)
                {
                    realHeight      -= ScrollbarSize;
                    innerRect.Height = realHeight;
                }
                gui.EncapsulateRect(rect);
                scroll2d = Vector2.Clamp(scroll2d, Vector2.Zero, maxScroll);
                PositionContent(gui, innerRect);
            }
            else
            {
                var realHeight = collapsible ? MathF.Min(contentSize.Y, height) : height;
                if (horizontal && maxScroll.X > 0)
                {
                    realHeight -= ScrollbarSize;
                }
                rect.Height = realHeight;
                gui.EncapsulateRect(rect);
            }
            var size       = new Vector2(width, height);
            var scrollSize = (size * size) / (size + maxScroll);

            scrollSize = Vector2.Max(scrollSize, Vector2.One);
            var scrollStart = (_scroll / maxScroll) * (size - scrollSize);

            if ((gui.action == ImGuiAction.MouseDown || gui.action == ImGuiAction.MouseScroll) && rect.Contains(gui.mousePosition))
            {
                InputSystem.Instance.SetKeyboardFocus(this);
            }
            if (gui.action == ImGuiAction.MouseScroll)
            {
                if (gui.ConsumeEvent(rect))
                {
                    if (vertical && (!horizontal || !InputSystem.Instance.control))
                    {
                        scroll += gui.actionParameter * 3f;
                    }
                    else
                    {
                        scrollX += gui.actionParameter * 3f;
                    }
                }
            }
            else
            {
                if (horizontal && maxScroll.X > 0f)
                {
                    var fullScrollRect = new Rect(rect.X, rect.Bottom - ScrollbarSize, rect.Width, ScrollbarSize);
                    var scrollRect     = new Rect(rect.X + scrollStart.X, fullScrollRect.Y, scrollSize.X, ScrollbarSize);
                    BuildScrollBar(gui, 0, in fullScrollRect, in scrollRect);
                }

                if (vertical && maxScroll.Y > 0f)
                {
                    var fullScrollRect = new Rect(rect.Right - ScrollbarSize, rect.Y, ScrollbarSize, rect.Height);
                    var scrollRect     = new Rect(fullScrollRect.X, rect.Y + scrollStart.Y, ScrollbarSize, scrollSize.Y);
                    BuildScrollBar(gui, 1, in fullScrollRect, in scrollRect);
                }
            }
        }