Exemplo n.º 1
0
        internal static void OnProcess(string Title, float Value, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

            if (!LGuiMisc.CheckVisible(ref Rect))
            {
                return;
            }

            LGuiMisc.CheckAndSetContextID(ref Rect, ID, true);

            Value = LGuiMisc.Clamp01(Value);
            var MaskRect = new LGuiRect(Rect.X + 1, Rect.Y + 1, (Rect.Width - 2) * Value, Rect.Height - 2);

            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true, false);
            LGuiGraphics.DrawRect(MaskRect, LGuiStyleColorIndex.CheckMask, true, false);
            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false, false);

            var Text     = $"{(Value * 100):00}%";
            var TextSize = LGuiConvert.GetTextSize(Text, LGuiContext.Font);

            LGuiGraphics.DrawText(Text, new LGuiVec2(Rect.CenterX - TextSize.X / 2.0f, Rect.CenterY - TextSize.Y / 2.0f), LGuiStyleColorIndex.Text);
        }
Exemplo n.º 2
0
        internal static void OnProcess(LGuiColor Color, string Format, params object[] Args)
        {
            var Text = string.Format(Format, Args);
            var Size = LGuiConvert.GetTextSize(Text, LGuiContext.Font);
            var Rect = LGuiLayout.DoLayout(Size);

            OnProcess(Color, Text, Rect);
        }
Exemplo n.º 3
0
        internal static bool OnProcess(string Title, bool Value)
        {
            var Size = LGuiConvert.GetTextSize(Title, LGuiContext.Font).Add(LGuiStyle.GetValue(LGuiStyleValueIndex.CheckBoxSize) + 3, 2);

            Size.Y = LGuiMisc.Max(Size.Y, LGuiStyle.GetValue(LGuiStyleValueIndex.CheckBoxSize));
            var Rect = LGuiLayout.DoLayout(Size);

            return(OnProcess(Title, Value, Rect));
        }
Exemplo n.º 4
0
        internal static int OnProcess(string Title, int Index, int Value)
        {
            var Radius = LGuiStyle.GetValue(LGuiStyleValueIndex.RadioButtonRadius);
            var Size   = LGuiConvert.GetTextSize(Title, LGuiContext.Font).Add(Radius * 2 + 3, 2);

            Size.Y = LGuiMisc.Max(Size.Y, Radius);
            var Rect = LGuiLayout.DoLayout(Size);

            return(OnProcess(Title, Index, Value, Rect));
        }
Exemplo n.º 5
0
        internal static bool OnProcess(string Title, ref string Value, uint MaxLength, LGuiInputTextFlags Flags)
        {
            var TextSize = LGuiConvert.GetTextSize(Value, LGuiContext.Font);

            var Size = new LGuiVec2(LGuiStyle.GetValue(LGuiStyleValueIndex.LargeControlLength), TextSize.Y + 2);

            if ((Flags & LGuiInputTextFlags.Multiline) == LGuiInputTextFlags.Multiline)
            {
                Size.Y = LGuiStyle.GetValue(LGuiStyleValueIndex.LargeControlLength);
            }

            var Rect = LGuiLayout.DoLayout(Size);

            return(OnProcess(Title, ref Value, Rect, MaxLength, Flags));
        }
Exemplo n.º 6
0
        internal static bool OnProcess(string Title, ref int Value, int Min, int Max, int Step, bool IsHorizontal, string Format, LGuiRect Rect)
        {
            var ID = LGuiHash.CalculateID(Title);

            LGuiContext.SetPreviousControlID(ID);

            if (!LGuiMisc.CheckVisible(ref Rect))
            {
                return(false);
            }

            var NewValue = LGuiMisc.Clamp(Min, Max, Value);

            Step = LGuiMisc.Min(Max - Min, Step);

            var GrabRect = CalculateGrabRect(ref Rect,
                                             new LGuiVec2((float)Step / (float)(Max - Min) * Rect.Width, (float)Step / (float)(Max - Min) * Rect.Height),
                                             LGuiStyle.GetGrabMinSize(),
                                             (float)(NewValue - Min) / (float)(Max - Min),
                                             IsHorizontal);

            LGuiMisc.CheckAndSetContextID(ref GrabRect, ID, true);

            var GrabColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.SliderGrabActived :
                                 LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.SliderGrabHovered : LGuiStyleColorIndex.SliderGrab;

            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true);
            LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false);
            LGuiGraphics.DrawRect(GrabRect, GrabColorIndex, true);
            if (!string.IsNullOrWhiteSpace(Format))
            {
                var Text     = string.Format(Format, NewValue);
                var TextSize = LGuiConvert.GetTextSize(Text, LGuiContext.Font);
                LGuiGraphics.DrawText(Text, new LGuiVec2(Rect.X + (Rect.Width - TextSize.X) / 2.0f, Rect.Y + (Rect.Height - TextSize.Y) / 2.0f), LGuiStyleColorIndex.Text);
            }

            LGuiMisc.CheckAndSetContextID(ref Rect, ID);

            if (LGuiContext.ActiveID == ID)
            {
                NewValue = CalculateCurrentValue(ref Rect, ref GrabRect, Min, Max, Step, IsHorizontal);
            }
            else if (!IsHorizontal)
            {
                NewValue = LGuiMisc.DoMouseWheelEvent(ID, Min, Max, NewValue);
            }

            if (LGuiMisc.CheckAndSetFocusID(ID))
            {
            }

            var ValueChanged = false;

            if (NewValue != Value)
            {
                ValueChanged = true;
                Value        = NewValue;
            }

            return(ValueChanged);
        }
Exemplo n.º 7
0
        internal static bool OnProcess(string Text, bool Selected)
        {
            var Size = LGuiConvert.GetTextSize(Text, LGuiContext.Font);

            return(OnProcess(Text, Selected, Size));
        }
Exemplo n.º 8
0
        internal static bool OnProcess(string Title, LGuiButtonFlags Flags)
        {
            var Size = LGuiConvert.GetTextSize(Title, LGuiContext.Font).Add(6, 4);

            return(OnProcess(Title, Size, Flags));
        }