Ejemplo n.º 1
0
        public void BuildHeader(ImGui gui)
        {
            var spacing      = innerPadding.left + innerPadding.right;
            var x            = 0f;
            var topSeparator = gui.AllocateRect(0f, 0.1f);
            var y            = gui.statePosition.Y;

            using (var group = gui.EnterFixedPositioning(0f, 1f, innerPadding))
            {
                foreach (var column in columns)
                {
                    if (column.width < column.minWidth)
                    {
                        column.width = column.minWidth;
                    }
                    var rect = new Rect(x, y, column.width, 0f);
                    group.SetManualRectRaw(rect, RectAllocator.LeftRow);
                    gui.BuildText(column.header);
                    rect.Bottom = gui.statePosition.Y;
                    x          += column.width + spacing;

                    if (!column.isFixedSize)
                    {
                        BuildHeaderResizer(gui, column, new Rect(x - 0.7f, y, 1f, 2.2f));
                    }

                    if (column.menuBuilder != null)
                    {
                        var menuRect = new Rect(rect.Right - 1.7f, rect.Y + 0.3f, 1.5f, 1.5f);
                        if (gui.isBuilding)
                        {
                            gui.DrawIcon(menuRect, Icon.DropDown, SchemeColor.BackgroundText);
                        }
                        if (gui.BuildButton(menuRect, SchemeColor.None, SchemeColor.Grey) == ImGuiUtils.Event.Click)
                        {
                            gui.ShowDropDown(menuRect, column.menuBuilder, new Padding(1f));
                        }
                    }
                }
            }
            width = x + 0.2f - spacing;

            var separator = gui.AllocateRect(x, 0.1f);

            if (gui.isBuilding)
            {
                topSeparator.Width = separator.Width = width;
                gui.DrawRectangle(topSeparator, SchemeColor.GreyAlt);
                gui.DrawRectangle(separator, SchemeColor.GreyAlt);
                //DrawVerticalGrid(gui, topSeparator.Bottom, separator.Top, SchemeColor.GreyAlt);
            }
        }
Ejemplo n.º 2
0
        public static Event BuildRedButton(this ImGui gui, Icon icon, float size = 1.5f)
        {
            Rect iconRect;

            using (gui.EnterGroup(new Padding(0.3f)))
                iconRect = gui.AllocateRect(size, size, RectAlignment.Middle);
            var evt = gui.BuildButton(gui.lastRect, SchemeColor.None, SchemeColor.Error);

            if (gui.isBuilding)
            {
                gui.DrawIcon(iconRect, icon, gui.IsMouseOver(gui.lastRect) ? SchemeColor.ErrorText : SchemeColor.Error);
            }
            return(evt);
        }
Ejemplo n.º 3
0
        public static bool BuildSlider(this ImGui gui, float value, out float newValue, float width = 10f)
        {
            var sliderRect  = gui.AllocateRect(width, 2f, RectAlignment.Full);
            var handleStart = (sliderRect.Width - 1f) * value;
            var handleRect  = new Rect(sliderRect.X + handleStart, sliderRect.Y, 1f, sliderRect.Height);
            var update      = false;

            newValue = value;

            switch (gui.action)
            {
            case ImGuiAction.Build:
                gui.DrawRectangle(handleRect, gui.IsMouseOverOrDown(sliderRect) ? SchemeColor.Background : SchemeColor.PureBackground, RectangleBorder.Thin);
                sliderRect.Y     += (sliderRect.Height - 0.3f) / 2f;
                sliderRect.Height = 0.3f;
                gui.DrawRectangle(sliderRect, SchemeColor.Grey);
                break;

            case ImGuiAction.MouseMove:
                if (gui.IsMouseDown(sliderRect))
                {
                    update = true;
                }
                else
                {
                    gui.ConsumeMouseOver(sliderRect, RenderingUtils.cursorHand);
                }
                break;

            case ImGuiAction.MouseDown:
                if (gui.IsMouseOver(sliderRect))
                {
                    gui.ConsumeMouseDown(sliderRect);
                    update = true;
                }
                break;
            }

            if (!update)
            {
                return(false);
            }
            var positionX = (gui.mousePosition.X - sliderRect.X - 0.5f) / (sliderRect.Width - 1f);

            newValue = MathUtils.Clamp(positionX, 0f, 1f);
            gui.Rebuild();
            return(true);
        }