Esempio n. 1
0
        public static bool BuildRadioGroup(this ImGui gui, IReadOnlyList <string> options, int selected, out int newSelected, SchemeColor color = SchemeColor.None)
        {
            newSelected = selected;
            for (var i = 0; i < options.Count; i++)
            {
                if (BuildRadioButton(gui, options[i], selected == i, color))
                {
                    newSelected = i;
                }
            }

            return(newSelected != selected);
        }
Esempio n. 2
0
 public static bool BuildContextMenuButton(this ImGui gui, string text, string rightText = null)
 {
     using (gui.EnterGroup(DefaultButtonPadding, RectAllocator.LeftRow, SchemeColor.BackgroundText))
     {
         gui.BuildText(text, Font.text, wrap: true);
         if (rightText != null)
         {
             gui.allocator = RectAllocator.RightRow;
             gui.BuildText(rightText, align: RectAlignment.MiddleRight);
         }
     }
     return(gui.BuildButton(gui.lastRect, SchemeColor.None, SchemeColor.Grey) == Event.Click);
 }
Esempio n. 3
0
 internal InlineGridBuilder(ImGui gui, float elementWidth, float spacing, int elementsPerRow)
 {
     savedContext        = default;
     this.gui            = gui;
     this.spacing        = spacing;
     gui.allocator       = RectAllocator.LeftAlign;
     this.elementWidth   = MathF.Min(elementWidth, gui.width);
     this.elementsPerRow = elementsPerRow == 0 ? MathUtils.Floor((gui.width + spacing) / (elementWidth + spacing)) : elementsPerRow;
     currentRowIndex     = -1;
     if (elementWidth <= 0)
     {
         this.elementsPerRow = 1;
     }
 }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public static Event BuildRedButton(this ImGui gui, string text)
        {
            Rect      textRect;
            TextCache cache;

            using (gui.EnterGroup(DefaultButtonPadding))
                textRect = gui.AllocateTextRect(out cache, text, align: RectAlignment.Middle);
            var evt = gui.BuildButton(gui.lastRect, SchemeColor.None, SchemeColor.Error);

            if (gui.isBuilding)
            {
                gui.DrawRenderable(textRect, cache, gui.IsMouseOver(gui.lastRect) ? SchemeColor.ErrorText : SchemeColor.Error);
            }
            return(evt);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public static bool DoListReordering <T>(this ImGui gui, Rect moveHandle, Rect contents, T index, out T moveFrom, SchemeColor backgroundColor = SchemeColor.PureBackground, bool updateDraggingObject = true)
        {
            var result = false;

            moveFrom = index;
            if (!gui.InitiateDrag(moveHandle, contents, index, backgroundColor) && gui.action == ImGuiAction.MouseDrag && gui.ConsumeDrag(contents.Center, index))
            {
                moveFrom = gui.GetDraggingObject <T>();
                if (updateDraggingObject)
                {
                    gui.UpdateDraggingObject(index);
                }
                result = true;
            }
            return(result);
        }
Esempio n. 8
0
        public static bool BuildCheckBox(this ImGui gui, string text, bool value, out bool newValue, SchemeColor color = SchemeColor.None, RectAllocator allocator = RectAllocator.LeftRow)
        {
            using (gui.EnterRow(allocator: allocator))
            {
                gui.BuildIcon(value ? Icon.CheckBoxCheck : Icon.CheckBoxEmpty, 1.5f, color);
                gui.BuildText(text, Font.text, color: color);
            }

            if (gui.OnClick(gui.lastRect))
            {
                newValue = !value;
                return(true);
            }

            newValue = value;
            return(false);
        }
Esempio n. 9
0
        public static bool BuildErrorRow(this ImGui gui, string text)
        {
            var closed = false;

            using (gui.EnterRow(allocator: RectAllocator.RightRow, textColor: SchemeColor.ErrorText))
            {
                if (gui.BuildButton(Icon.Close, size: 1f, over: SchemeColor.ErrorAlt))
                {
                    closed = true;
                }
                gui.RemainingRow().BuildText(text, align: RectAlignment.Middle);
            }
            if (gui.isBuilding)
            {
                gui.DrawRectangle(gui.lastRect, SchemeColor.Error);
            }
            return(closed);
        }
Esempio n. 10
0
 public static InlineGridBuilder EnterHorizontalSplit(this ImGui gui, int elementCount, float spacing = 0f)
 {
     return(new InlineGridBuilder(gui, (gui.width + spacing) / elementCount - spacing, spacing, elementCount));
 }
Esempio n. 11
0
 public static InlineGridBuilder EnterInlineGrid(this ImGui gui, float elementWidth, float spacing = 0f, int maxElemCount = 0)
 {
     return(new InlineGridBuilder(gui, elementWidth, spacing, maxElemCount));
 }
Esempio n. 12
0
 public static void ShowTooltip(this ImGui gui, GuiBuilder builder, float width = 20f) => gui.window?.ShowTooltip(gui, gui.lastRect, builder, width);
Esempio n. 13
0
 public static void ShowTooltip(this ImGui gui, Rect rect, string text, float width          = 20f) => gui.window?.ShowTooltip(gui, rect, x => x.BuildText(text, wrap: true), width);
Esempio n. 14
0
 public static void ShowDropDown(this ImGui gui, Rect rect, SimpleDropDown.Builder builder, Padding padding, float width = 20f) => gui.window?.ShowDropDown(gui, rect, builder, padding, width);
Esempio n. 15
0
 public static bool BuildButton(this ImGui gui, Icon icon, SchemeColor normal = SchemeColor.None, SchemeColor over = SchemeColor.Grey, SchemeColor down = SchemeColor.None, float size = 1.5f)
 {
     using (gui.EnterGroup(new Padding(0.3f)))
         gui.BuildIcon(icon, size);
     return(gui.BuildButton(gui.lastRect, normal, over, down) == Event.Click);
 }
Esempio n. 16
0
 protected override void BuildContents(ImGui gui)
 {
     BuildContent(gui);
     gui.SetContextRect(new Rect(default, size));
Esempio n. 17
0
 public static void ShowDropDown(this ImGui gui, SimpleDropDown.Builder builder, float width = 20f) => gui.window?.ShowDropDown(gui, gui.lastRect, builder, new Padding(1f), width);