private static void HandleMouseMsg(ref LGuiRect Rect) { if (LGuiContext.IO.IsMouseClick(LGuiMouseButtons.Left) && LGuiMisc.Contains(ref Rect, ref LGuiContext.IO.MousePos)) { if (CurrentWindow_ != FocusWindow_ && WindowList_[CurrentWindow_].Focusable) { FocusWindow_ = CurrentWindow_; WindowList_[FocusWindow_].Order = FocusOrder++; SortWindowList(); } WindowList_[CurrentWindow_].MoveOriginPos = Rect.Pos; } if (WindowList_[FocusWindow_].Moveable) { LGuiMisc.CheckAndSetContextID(ref Rect, CurrentWindow_); if (LGuiContext.ActiveID == CurrentWindow_ && LGuiContext.IO.IsMouseDown(LGuiMouseButtons.Left)) { var MoveOriginPos = WindowList_[CurrentWindow_].MoveOriginPos; var MovePos = LGuiContext.IO.GetMouseMovePos(); WindowList_[CurrentWindow_].Rect.Pos = MoveOriginPos + MovePos; } } }
internal static bool OnProcess(string Title, ref string Value, LGuiRect Rect, uint MaxLength, LGuiInputTextFlags Flags) { var ID = LGuiHash.CalculateID(Title); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } LGuiMisc.CheckAndSetContextID(ref Rect, ID); LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true); LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false); if (LGuiMisc.CheckAndSetFocusID(ID)) { } var ValueChanged = false; if (LGuiContext.FocusID == ID || LGuiContext.ActiveID == ID) { ValueChanged = LGuiTextFieldController.OnProcess(ID, ref Value, Rect, MaxLength, Flags, null); } else { LGuiTextFieldController.OnProcess(ID, ref Value, Rect, MaxLength, Flags | LGuiInputTextFlags.OnlyDisplay, null); } return(ValueChanged); }
internal static void OnProcess(int TextureID, LGuiRect SrcRect, LGuiVec2 DstSize) { var ID = LGuiHash.CalculateID(LGuiSettings.DefaultTextureTitle + TextureID); LGuiContext.SetPreviousControlID(ID); if (SrcRect.Width == 0 || SrcRect.Height == 0) { SrcRect.Size = LGuiConvert.GetTextureIDSize(TextureID); } if (DstSize.X == 0 || DstSize.Y == 0) { DstSize = LGuiConvert.GetTextureIDSize(TextureID); } var DstRect = LGuiLayout.DoLayout(DstSize); if (!LGuiMisc.CheckVisible(ref DstRect)) { return; } LGuiMisc.CheckAndSetContextID(ref DstRect, ID, true); LGuiGraphics.DrawTexture(TextureID, SrcRect, DstRect); }
internal static bool Begin(string Title, LGuiRect Rect) { var ID = LGuiHash.CalculateID(Title); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } var IsOpen = LGuiContextCache.GetPopupOpen(Title); if (IsOpen) { if (LGuiContext.IO.IsMouseClick(LGuiMouseButtons.Left) && !LGuiMisc.Contains(ref Rect, ref LGuiContext.IO.MousePos)) { LGuiContextCache.SetPopupOpen(Title, false); return(false); } LGuiGraphics.SetCurrentLevel(LGuiCommandLevel.Popup); LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true); LGuiFrame.Begin(Title, Rect, false); } return(IsOpen); }
internal static bool OnProcess(string Title, bool Value, LGuiRect Rect) { var ID = LGuiHash.CalculateID(Title); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(Value); } var BoxSize = LGuiStyle.GetValue(LGuiStyleValueIndex.CheckBoxSize); var BoxRect = new LGuiRect(new LGuiVec2(Rect.X, Rect.Y + (Rect.Height - BoxSize) / 2.0f), new LGuiVec2(BoxSize, BoxSize)); LGuiMisc.CheckAndSetContextID(ref Rect, ID); var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.FrameActived : LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.FrameHovered : LGuiStyleColorIndex.Frame; LGuiGraphics.DrawRect(BoxRect, BgColorIndex, true); LGuiGraphics.DrawRect(BoxRect, LGuiStyleColorIndex.Border, false); if (Value) { LGuiGraphics.DrawRect(new LGuiRect(BoxRect.X + 2, BoxRect.Y + 2, BoxRect.Width - 4, BoxRect.Height - 4), LGuiStyleColorIndex.CheckMask, true); } LGuiGraphics.DrawText(Title, new LGuiVec2(Rect.X + BoxSize + 3, Rect.Y + 1), LGuiStyleColorIndex.Text); if (LGuiMisc.CheckAndSetFocusID(ID)) { Value = !Value; } return(Value); }
internal static int OnProcess(string Title, int Index, int Value, LGuiRect Rect) { var ID = LGuiHash.CalculateID(Title); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(Value); } LGuiMisc.CheckAndSetContextID(ref Rect, ID); var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.FrameActived : LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.FrameHovered : LGuiStyleColorIndex.Frame; var Radius = LGuiStyle.GetValue(LGuiStyleValueIndex.RadioButtonRadius); var RadioCenter = new LGuiVec2(Rect.X + Radius, Rect.Y + Rect.Height / 2.0f); LGuiGraphics.DrawCircle(RadioCenter, Radius, BgColorIndex, true); LGuiGraphics.DrawCircle(RadioCenter, Radius, LGuiStyleColorIndex.Border, false); if (Index == Value) { LGuiGraphics.DrawCircle(RadioCenter, Radius - 3, LGuiStyleColorIndex.CheckMask, true); } LGuiGraphics.DrawText(Title, new LGuiVec2(Rect.X + Radius * 2 + 3, Rect.Y + 1), LGuiStyleColorIndex.Text); if (LGuiMisc.CheckAndSetFocusID(ID)) { Value = Index; } return(Value); }
internal static bool OnProcess(string Text, bool Selected, LGuiRect Rect) { var ID = LGuiHash.CalculateID(Text); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } LGuiMisc.CheckAndSetContextID(ref Rect, ID); var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.HeaderActive : LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.HeaderHovered : Selected ? LGuiStyleColorIndex.Header : LGuiStyleColorIndex.Frame; LGuiGraphics.DrawRect(Rect, BgColorIndex, true, false); LGuiGraphics.DrawText(Text, new LGuiVec2(Rect.X, Rect.Y), LGuiStyleColorIndex.Text); if (LGuiMisc.CheckAndSetFocusID(ID)) { return(true); } return(false); }
internal static void Begin(string Title, LGuiRect Rect, bool IsChild = true) { var FullTitle = $"{LGuiContext.GetCurrentFrame().Title}/{Title}"; var ID = LGuiHash.CalculateID(FullTitle); LGuiContext.SetPreviousControlID(ID); var Offset = LGuiContextCache.GetFrameOffset(FullTitle); var Context = new LGuiFrameContext(FullTitle, Rect); Context.Size = LGuiContextCache.GetFrameContextSize(FullTitle); if (!LGuiMisc.CheckVisible(ref Context.Rect)) { Context.Visibled = false; } else { LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false); } LGuiMisc.CheckAndSetContextID(ref Rect, ID, true); LGuiContext.BeginFrame(Context, IsChild); LGuiLayout.BeginLayout(LGuiLayout.GetCurrentLayoutMode(), new LGuiVec2( Rect.X + LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingX) - Offset.X, Rect.Y + LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingY) - Offset.Y), false); }
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); }
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)); }
internal static bool Begin(string Title) { var FullTitle = $"{LGuiContext.GetCurrentFrame().Title}/{Title}"; var ID = LGuiHash.CalculateID(FullTitle); LGuiContext.SetPreviousControlID(ID); var Rect = LGuiLayout.DoLayout(new LGuiVec2(LGuiStyle.GetValue(LGuiStyleValueIndex.LargeControlLength), LGuiStyle.GetValue(LGuiStyleValueIndex.HeaderSize))); if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } LGuiMisc.CheckAndSetContextID(ref Rect, ID); var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.GroupActived : LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.GroupHovered : LGuiStyleColorIndex.Group; LGuiGraphics.DrawRect(Rect, BgColorIndex, true); LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false); LGuiGraphics.DrawText(Title, new LGuiVec2(Rect.X + LGuiStyle.GetValue(LGuiStyleValueIndex.GroupChildSpacing), Rect.Y), LGuiStyleColorIndex.Text); var Expand = LGuiContextCache.GetGroupExpand(FullTitle); if (Expand) { LGuiGraphics.DrawTriangle( new LGuiVec2(Rect.X + 5, Rect.Y + 3), new LGuiVec2(Rect.X + 15, Rect.Y + 3), new LGuiVec2(Rect.X + 10, Rect.Bottom - 3), LGuiStyle.GetColor(LGuiStyleColorIndex.Text), true); } else { LGuiGraphics.DrawTriangle( new LGuiVec2(Rect.X + 5, Rect.Y + 3), new LGuiVec2(Rect.X + 15, Rect.CenterY), new LGuiVec2(Rect.X + 5, Rect.Bottom - 3), LGuiStyle.GetColor(LGuiStyleColorIndex.Text), true); } if (LGuiMisc.CheckAndSetFocusID(ID)) { Expand = !Expand; LGuiContextCache.SetGroupExpand(FullTitle, Expand); } if (Expand) { LGuiContext.BeginGroup(FullTitle, Rect.X + LGuiStyle.GetValue(LGuiStyleValueIndex.GroupChildSpacing)); } return(Expand); }
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)); }
private static LGuiRect CalculateGrabRect(ref LGuiRect Rect, LGuiVec2 GrabSize, LGuiVec2 MinSize, float Percent, bool IsHorizontal) { var GrabWidth = IsHorizontal ? LGuiMisc.Max(MinSize.X, GrabSize.X) : Rect.Width - 4; var GrabHeight = IsHorizontal ? Rect.Height - 4 : LGuiMisc.Max(MinSize.Y, GrabSize.Y); var GrabCenterX = IsHorizontal ? LGuiMisc.Lerp(Rect.Left + GrabWidth / 2.0f + 2, Rect.Right - GrabWidth / 2.0f - 2, Percent) : Rect.CenterX; var GrabCenterY = IsHorizontal ? Rect.CenterY : LGuiMisc.Lerp(Rect.Top + GrabHeight / 2.0f + 2, Rect.Bottom - GrabHeight / 2.0f - 2, Percent); var GrabRect = LGuiRect.CreateWithCenter(GrabCenterX, GrabCenterY, GrabWidth, GrabHeight); return(GrabRect); }
private static int CalculateCurrentValue(ref LGuiRect Rect, ref LGuiRect GrabRect, int Min, int Max, int Step, bool IsHorizontal) { var NewValue = LGuiMisc.Lerp(Min, Max, IsHorizontal ? (LGuiContext.IO.MousePos.X - (Rect.X + GrabRect.Width / 2.0f + 2)) / (Rect.Width - GrabRect.Width - 4) : (LGuiContext.IO.MousePos.Y - (Rect.Y + GrabRect.Height / 2.0f + 2)) / (Rect.Height - GrabRect.Height - 4)); if (NewValue > Min && NewValue < Max) { return(LGuiMisc.GetStepValue(NewValue, Step)); } return(NewValue); }
internal static void OnProcess(LGuiColor Color, string Text, LGuiRect Rect) { var ID = LGuiHash.CalculateID(Text); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return; } LGuiMisc.CheckAndSetContextID(ref Rect, ID); LGuiGraphics.DrawText(Text, Rect.Pos, Color, LGuiContext.Font); }
internal static bool Begin(LGuiVec2 Size) { if (!LGuiMisc.PreviousControlIsHovered()) { return(false); } var Pos = LGuiContext.IO.MousePos + new LGuiVec2(20, 5); var Rect = new LGuiRect(Pos, Size); LGuiGraphics.SetCurrentLevel(LGuiCommandLevel.Tips); LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true); LGuiFrame.Begin(LGuiSettings.DefaultToolTipsTitle, Rect, false); return(true); }
internal static bool OnProcess(string Title, LGuiRect Rect, LGuiButtonFlags Flags) { var ID = LGuiHash.CalculateID(Title); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } LGuiMisc.CheckAndSetContextID(ref Rect, ID); if ((Flags & LGuiButtonFlags.Invisible) == LGuiButtonFlags.Invisible) { } else { var BgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.ButtonActived : LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.ButtonHovered : LGuiStyleColorIndex.Button; LGuiGraphics.DrawRect(Rect, BgColorIndex, true); LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false); LGuiGraphics.DrawText(Title, new LGuiVec2(Rect.X + 3, Rect.Y + 2), LGuiStyleColorIndex.Text); } if ((Flags & LGuiButtonFlags.Repeat) == LGuiButtonFlags.Repeat) { if (LGuiContext.ActiveID == ID) { return(true); } } else if (LGuiMisc.CheckAndSetFocusID(ID)) { return(true); } return(false); }
private static int LayoutRow(LGuiTextFieldState State, LGuiFont Font, int StartIndex, ref LGuiVec2 TextSize) { var Index = StartIndex; var LineWidth = 0.0f; TextSize.X = 0; TextSize.Y = 0; while (Index < State.TextLength) { var Ch = State.GetCharacter(Index++); if (Ch == '\n') { TextSize.X = LGuiMisc.Max(TextSize.X, LineWidth); TextSize.Y = TextSize.Y + Font.FontHeight + State.Spacing.Y; LineWidth = 0.0f; break; } if (Ch == '\r') { continue; } LineWidth = LineWidth + Font.FontWidth + State.Spacing.X; } if (TextSize.X < LineWidth) { TextSize.X = LineWidth; } if (LineWidth > 0 || TextSize.Y == 0.0f) { TextSize.Y = TextSize.Y + Font.FontHeight + State.Spacing.Y; } return(Index - StartIndex); }
internal static bool OnProcess(string Title, LGuiColor Color, LGuiRect Rect) { var ID = LGuiHash.CalculateID(Title); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } LGuiMisc.CheckAndSetContextID(ref Rect, ID); LGuiGraphics.DrawRect(Rect, Color, true); LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false); if (LGuiMisc.CheckAndSetFocusID(ID)) { return(true); } return(false); }
internal static bool CurrentWindowCanHandleMouseMsg(bool NeedContainerMousePos) { if (CurrentWindow_ == 0) { return(true); } for (var Index = SortedWindowID_.Count - 1; Index >= 0; --Index) { var CurrentID = SortedWindowID_[Index]; if (CurrentID == CurrentWindow_) { return(!NeedContainerMousePos || LGuiMisc.Contains(ref WindowList_[CurrentID].Rect, ref LGuiContext.IO.MousePos)); } if (LGuiMisc.Contains(ref WindowList_[CurrentID].Rect, ref LGuiContext.IO.MousePos)) { return(false); } } return(true); }
internal static bool OnProcess(string Title, ref int ItemIndex, string[] Items, LGuiRect Rect) { var ID = LGuiHash.CalculateID(Title); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } LGuiMisc.CheckAndSetContextID(ref Rect, ID, true); LGuiFrame.Begin(Title, Rect); var NewIndex = ItemIndex; var ItemWidth = Rect.Width - LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingX) * 2.0f - LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize); for (var Index = 0; Index < Items.Length; ++Index) { if (LGuiSelectable.OnProcess(Items[Index], ItemIndex == Index, ItemWidth)) { NewIndex = Index; } } LGuiFrame.End(); if (ItemIndex != NewIndex) { ItemIndex = NewIndex; return(true); } return(false); }
internal static bool OnProcess(int ID, ref string Text, LGuiRect Rect, uint MaxLength, LGuiInputTextFlags Flags, Func <char, bool> Callback) { var RenderPos = new LGuiVec2(Rect.X + 3, Rect.Y + 1); var Info = new LGuiTextRenderInfo(); Info.TextColor = LGuiStyle.GetColor(LGuiStyleColorIndex.Text); Info.Font = LGuiContext.Font; Info.IsHidden = (Flags & LGuiInputTextFlags.Password) == LGuiInputTextFlags.Password; Info.HiddenChar = '*'; Info.CountX = (uint)LGuiMisc.Floor((Rect.Width - 6) / Info.Font.FontWidth); Info.CountY = (Flags & LGuiInputTextFlags.Multiline) == LGuiInputTextFlags.Multiline ? (uint)LGuiMisc.Floor((Rect.Height - 2) / Info.Font.FontHeight) : 1u; Info.OnlyShowText = false; if ((Flags & LGuiInputTextFlags.OnlyDisplay) == LGuiInputTextFlags.OnlyDisplay) { Info.Text = Text; Info.OnlyShowText = true; LGuiTextRenderer.Render(Info, RenderPos); return(false); } if (CurrentState == null || CurrentState.ID != ID) { CurrentState = new LGuiTextFieldState(ID, Text, (Flags & LGuiInputTextFlags.Multiline) != LGuiInputTextFlags.Multiline); if ((Flags & LGuiInputTextFlags.AutoSelectAll) == LGuiInputTextFlags.AutoSelectAll) { CurrentState.SelectAll(); } } HandleKeyEvent(CurrentState, Flags, Callback); HandleMouseEvent(CurrentState, Info.Font, RenderPos); CurrentState.MaxLength = MaxLength; Info.CursorColor = Info.TextColor; if ((Flags & LGuiInputTextFlags.InsertMode) == LGuiInputTextFlags.InsertMode) { CurrentState.InsertMode = true; Info.CursorWidth = 1u; Info.CursorColor.A = 0.5f; } else { Info.CursorWidth = 0u; } var Cursor = (uint)CurrentState.GetCursor(); if (Cursor < CurrentState.OffsetX) { CurrentState.OffsetX = Cursor; } else if (Cursor > CurrentState.OffsetX + Info.CountX) { CurrentState.OffsetX = Cursor - Info.CountX; } Info.Text = CurrentState.Text; Info.SelectStart = (uint)CurrentState.GetSelectStart(); Info.SelectEnd = (uint)CurrentState.GetSelectEnd(); Info.SelectColor = LGuiColor.Blue; Info.Spacing = CurrentState.Spacing; Info.Cursor = Cursor; Info.OffsetX = CurrentState.OffsetX; Info.OffsetY = CurrentState.OffsetY; LGuiTextRenderer.Render(Info, RenderPos); if ((Flags & LGuiInputTextFlags.EnterReturnsTrue) == LGuiInputTextFlags.EnterReturnsTrue) { Text = CurrentState.Text; var ValueChanged = LGuiContext.IO.IsKeyPressed(LGuiKeys.Enter); if (ValueChanged) { LGuiContext.FocusID = 0; } return(ValueChanged); } else { var NewText = CurrentState.Text; var ValueChanged = NewText != Text; Text = NewText; return(ValueChanged); } }
internal static bool BeginWindow(string Title, LGuiRect InitRect, LGuiWindowFlags Flags) { if (CurrentWindow_ != 0) { return(false); } var ID = LGuiHash.Calculate(Title); if (!WindowList_.ContainsKey(ID)) { WindowList_.Add(ID, new LGuiWindowContext(Title, ID, WindowList_.Count, InitRect, (Flags & LGuiWindowFlags.NoMove) != LGuiWindowFlags.NoMove, (Flags & LGuiWindowFlags.NoFocus) != LGuiWindowFlags.NoFocus)); FocusOrder++; } var Rect = WindowList_[ID].Rect; if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } CurrentWindow_ = ID; if (FocusWindow_ == 0) { FocusWindow_ = CurrentWindow_; WindowList_[FocusWindow_].Order = FocusOrder; } LGuiGraphics.SetTargetCommandList(WindowList_[ID].DrawList); if ((Flags & LGuiWindowFlags.NoTitle) != LGuiWindowFlags.NoTitle) { var TitleRect = new LGuiRect(Rect.Pos, new LGuiVec2(Rect.Width, LGuiContext.Font.FontHeight)); var NoCollapse = ((Flags & LGuiWindowFlags.NoCollapse) == LGuiWindowFlags.NoCollapse); var Expand = LGuiContextCache.GetWindowExpand(Title); var TitleTextOffset = NoCollapse ? 5.0f : 20.0f; if (Expand) { LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true); } LGuiGraphics.DrawRect(TitleRect, LGuiStyleColorIndex.HeaderActive, true); LGuiGraphics.DrawText(Title, new LGuiVec2(TitleRect.X + TitleTextOffset, TitleRect.Y), LGuiStyleColorIndex.Text); if (!NoCollapse) { if (Expand) { LGuiGraphics.DrawTriangle( new LGuiVec2(TitleRect.X + 5, TitleRect.Top + 5), new LGuiVec2(TitleRect.X + 15, TitleRect.Top + 5), new LGuiVec2(TitleRect.X + 10, TitleRect.Bottom - 5), LGuiStyle.GetColor(LGuiStyleColorIndex.Text), true); } else { LGuiGraphics.DrawTriangle( new LGuiVec2(TitleRect.X + 5, TitleRect.Top + 5), new LGuiVec2(TitleRect.X + 15, TitleRect.CenterY), new LGuiVec2(TitleRect.X + 5, TitleRect.Bottom - 5), LGuiStyle.GetColor(LGuiStyleColorIndex.Text), true); } var ArrowRect = new LGuiRect(TitleRect.X, TitleRect.Y, 20.0f, 20.0f); LGuiMisc.CheckAndSetContextID(ref ArrowRect, ID); if (LGuiMisc.CheckAndSetFocusID(ID)) { Expand = !Expand; LGuiContextCache.SetWindowExpand(Title, Expand); } if (!Expand) { HandleMouseMsg(ref TitleRect); CurrentWindow_ = 0; LGuiGraphics.SetTargetCommandList(null); return(false); } } LGuiGraphics.DrawRect(TitleRect, LGuiStyleColorIndex.Border, false); var ContextRect = new LGuiRect(Rect.X, TitleRect.Bottom, Rect.Width, Rect.Height - TitleRect.Height); LGuiFrame.Begin(Title, ContextRect, false); } else { LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Frame, true); LGuiFrame.Begin(Title, Rect, false); } return(true); }
internal static bool OnProcess(string Title, ref int ItemIndex, string[] Items, LGuiRect Rect, float PopupHeight) { var ID = LGuiHash.CalculateID(Title); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } var TitleBgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.FrameActived : LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.FrameHovered : LGuiStyleColorIndex.Frame; LGuiMisc.CheckAndSetContextID(ref Rect, ID); LGuiGraphics.DrawRect(Rect, TitleBgColorIndex, true); LGuiGraphics.DrawText(Items[ItemIndex], Rect.Pos + new LGuiVec2(LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingX), 0), LGuiStyleColorIndex.Text); var GrabRect = new LGuiRect(Rect.Right - LGuiContext.Font.FontHeight, Rect.Y, LGuiContext.Font.FontHeight, LGuiContext.Font.FontHeight); var GrabBgColorIndex = LGuiContext.ActiveID == ID ? LGuiStyleColorIndex.ButtonActived : LGuiContext.HoveredID == ID ? LGuiStyleColorIndex.ButtonHovered : LGuiStyleColorIndex.Button; LGuiGraphics.DrawRect(GrabRect, GrabBgColorIndex, true); LGuiGraphics.DrawTriangle( new LGuiVec2(GrabRect.Left + 4, GrabRect.Top + 4), new LGuiVec2(GrabRect.Right - 4, GrabRect.Top + 4), new LGuiVec2(GrabRect.CenterX, GrabRect.Bottom - 4), LGuiStyle.GetColor(LGuiStyleColorIndex.Text), true); LGuiGraphics.DrawRect(Rect, LGuiStyleColorIndex.Border, false); var PopupID = $"{Title}_ItemPopup"; if (LGuiMisc.CheckAndSetFocusID(ID)) { LGuiPopup.Open(PopupID); } var NewIndex = ItemIndex; if (LGuiPopup.Begin(PopupID, new LGuiRect(Rect.X, Rect.Bottom + 1, Rect.Width, PopupHeight))) { var ItemWidth = Rect.Width - LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingX) * 2.0f - LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize); for (var Index = 0; Index < Items.Length; ++Index) { if (LGuiSelectable.OnProcess(Items[Index], ItemIndex == Index, ItemWidth)) { NewIndex = Index; LGuiPopup.Close(PopupID); } } LGuiPopup.End(); } if (ItemIndex != NewIndex) { ItemIndex = NewIndex; return(true); } return(false); }
internal static bool OnProcess(string Title, LGuiRect Rect, ref LGuiColor Color) { LGuiFrame.Begin(Title, Rect); var ID = LGuiHash.CalculateID(Title); LGuiContext.SetPreviousControlID(ID); if (!LGuiMisc.CheckVisible(ref Rect)) { return(false); } var Hsv = LGuiContextCache.GetColorPickerHsv(Title); var FrameSpacing = LGuiStyle.GetFrameChildSpacing(); var SpacingY = LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingY); var SliderSize = LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize); var ColorRect = new LGuiRect(Rect.Pos + FrameSpacing, new LGuiVec2(Rect.Width - FrameSpacing.X * 2.0f, Rect.Height - (SliderSize + SpacingY) * 4.0f - SpacingY * 3.0f - 20)); RenderColorRect(ColorRect, Hsv.R); RenderColorCross(ColorRect, Hsv.G, Hsv.B); var IDColor = LGuiHash.CalculateID($"{Title}_ColorSelector"); LGuiMisc.CheckAndSetContextID(ref ColorRect, IDColor); var HsvValueChanged = false; if (LGuiContext.ActiveID == IDColor) { var X = LGuiMisc.Lerp(0.0f, 1.0f, (LGuiContext.IO.MousePos.X - ColorRect.X) / ColorRect.Width); var Y = LGuiMisc.Lerp(0.0f, 1.0f, (ColorRect.Height - (LGuiContext.IO.MousePos.Y - ColorRect.Y)) / ColorRect.Height); if (X != Hsv.G || Y != Hsv.B) { HsvValueChanged = true; Hsv.G = X; Hsv.B = Y; } } var HueRect = new LGuiRect(Rect.X + FrameSpacing.X, ColorRect.Bottom + FrameSpacing.Y, ColorRect.Width, 20); RenderHueRect(HueRect); RenderHueArrow(HueRect, Hsv.R); var IDHue = LGuiHash.CalculateID($"{Title}_HueSelector"); LGuiMisc.CheckAndSetContextID(ref HueRect, IDHue); if (LGuiContext.ActiveID == IDHue) { var Hue = LGuiMisc.Lerp(0.0f, 1.0f, (LGuiContext.IO.MousePos.X - HueRect.X) / HueRect.Width); if (Hue != Hsv.R) { HsvValueChanged = true; Hsv.R = Hue; } } HsvValueChanged |= HandleHsvSlider(Title, ref Hsv, new LGuiVec2(HueRect.X, HueRect.Bottom + SpacingY), HueRect.Width / 2.0f); if (HsvValueChanged) { Color = LGuiColor.Hsv2Rgb(Hsv); LGuiContextCache.SetColorPickerHsv(Title, Hsv); } var RgbValueChanged = false; if (HandleRgbSlider(Title, ref Color, new LGuiVec2(HueRect.X + HueRect.Width / 2.0f + 2.5f, HueRect.Bottom + SpacingY), HueRect.Width / 2.0f)) { RgbValueChanged = true; LGuiContextCache.SetColorPickerHsv(Title, LGuiColor.Rgb2Hsv(Color)); } var CurrentTitleWidth = LGuiContext.Font.FontWidth * 8.5f; LGuiGraphics.DrawText("Current:", new LGuiVec2(HueRect.X, HueRect.Bottom + SpacingY + (SliderSize + SpacingY) * 3.0f), LGuiStyleColorIndex.Text); LGuiGraphics.DrawRect(new LGuiRect(HueRect.X + CurrentTitleWidth, HueRect.Bottom + SpacingY + (SliderSize + SpacingY) * 3.0f, HueRect.Width / 2.0f - CurrentTitleWidth, SliderSize), Color, true, false); LGuiFrame.End(); return(HsvValueChanged | RgbValueChanged); }
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); }
internal static void Render(LGuiTextRenderInfo Info, LGuiVec2 RenderPos) { var FontWidth = Info.Font.FontWidth + Info.Spacing.X; var FontHeight = Info.Font.FontHeight + Info.Spacing.Y; var Padding = new LGuiVec2(Info.Spacing.X / 2.0f, Info.Spacing.Y / 2.0f); var SelectRects = new List <LGuiRect>(); var HasSelect = Info.SelectStart != Info.SelectEnd && !Info.OnlyShowText; var SelectStart = LGuiMisc.Min(Info.SelectStart, Info.SelectEnd); var SelectEnd = LGuiMisc.Min((uint)Info.Text.Length, LGuiMisc.Max(Info.SelectStart, Info.SelectEnd)); var InSelect = false; var BeginPos = RenderPos - new LGuiVec2(Info.OffsetX * FontWidth, Info.OffsetY * FontHeight); var Pos = BeginPos; var CursorPos = Pos; var SelectPos = Pos; var TextCmdList = LGuiGraphics.CreateCommandList(); var CharX = 0u; var CharY = 0u; var Index = 0u; foreach (var Ch in Info.Text) { if (Index == Info.Cursor) { CursorPos = Pos; } if (HasSelect) { if (Index == SelectStart) { SelectPos = Pos; InSelect = true; } if (Index == SelectEnd) { SelectRects.Add(new LGuiRect(SelectPos, new LGuiVec2(Pos.X - SelectPos.X, FontHeight))); InSelect = false; HasSelect = false; } if (InSelect && Ch == '\n') { SelectRects.Add(new LGuiRect(SelectPos, new LGuiVec2(Pos.X - SelectPos.X + FontWidth, FontHeight))); SelectPos = new LGuiVec2(BeginPos.X, Pos.Y + FontHeight); } } if (CharX >= Info.OffsetX && CharY >= Info.OffsetY && CharX < (Info.OffsetX + Info.CountX) && CharY < (Info.OffsetY + Info.CountY)) { TextCmdList.DrawText((Info.IsHidden ? Info.HiddenChar : Ch).ToString(), Pos + Padding, Info.TextColor, Info.Font); } if (Ch == '\n') { Pos.X = BeginPos.X; Pos.Y = Pos.Y + FontHeight; CharX = 0u; CharY++; } else { Pos.X = Pos.X + FontWidth; CharX++; } Index++; } if (InSelect) { if (Info.Text[Info.Text.Length - 1] != '\n') { SelectRects.Add(new LGuiRect(SelectPos, new LGuiVec2(Pos.X - SelectPos.X, FontHeight))); } } var ViewRect = new LGuiRect(RenderPos, new LGuiVec2(Info.CountX * FontWidth + 1.0f, Info.CountY * FontHeight)); var SelectResult = LGuiRect.Zero; foreach (var Rect in SelectRects) { if (!LGuiMisc.IntersectRect(Rect, ViewRect, ref SelectResult)) { continue; } LGuiGraphics.DrawRect(SelectResult, Info.SelectColor, true, false); } LGuiGraphics.AddCommandList(TextCmdList); if (!Info.OnlyShowText && ((LGuiContext.FrameCount >> 4) & 1) == 1) { if (Info.Cursor == Info.Text.Length) { CursorPos = Pos; } if (Info.CursorWidth > 0) { var CursorRect = new LGuiRect(CursorPos, new LGuiVec2(Info.CursorWidth * FontWidth, FontHeight)); if (LGuiMisc.Overlaps(ref ViewRect, ref CursorRect)) { LGuiGraphics.DrawRect(CursorRect, Info.CursorColor, true, false); } } else if (LGuiMisc.Contains(ref ViewRect, ref CursorPos)) { LGuiGraphics.DrawLine(CursorPos, CursorPos + new LGuiVec2(0, FontHeight), Info.CursorColor); } } }
internal static void End() { var FrameContext = LGuiContext.GetCurrentFrame(); FrameContext.Size = FrameContext.Rect.Size - LGuiStyle.GetFrameChildSpacing() * 2.0f; if (FrameContext.Visibled) { var LayoutContext = LGuiLayout.GetCurrentLayoutContext(); var Width = LayoutContext.ChildSize.X - FrameContext.Rect.Width + LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingX); var Height = LayoutContext.ChildSize.Y - FrameContext.Rect.Height + LGuiStyle.GetValue(LGuiStyleValueIndex.FrameChildSpacingY); var SliderSize = LGuiStyle.GetValue(LGuiStyleValueIndex.SliderSize); var Offset = LGuiContextCache.GetFrameOffset(FrameContext.Title); if (Width > 0) { LGuiSlider.OnProcess( $"{FrameContext.Title}_hsbar", ref Offset.X, 0.0f, Width, LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingX), true, string.Empty, new LGuiRect(FrameContext.Rect.X, FrameContext.Rect.Bottom - SliderSize, FrameContext.Rect.Width - SliderSize, SliderSize)); FrameContext.Size.Y -= SliderSize; } else { Offset.X = 0; } if (Height > 0) { LGuiSlider.OnProcess( $"{FrameContext.Title}_vsbar", ref Offset.Y, 0.0f, Height, LGuiStyle.GetValue(LGuiStyleValueIndex.ControlSpacingY), false, string.Empty, new LGuiRect(FrameContext.Rect.Right - SliderSize, FrameContext.Rect.Y, SliderSize, FrameContext.Rect.Height)); FrameContext.Size.X -= SliderSize; var ID = LGuiHash.CalculateID(FrameContext.Title); LGuiMisc.CheckAndSetContextID(ref FrameContext.Rect, ID, true); Offset.Y = LGuiMisc.DoMouseWheelEvent(ID, 0.0f, Height, Offset.Y); } else { Offset.Y = 0; } LGuiContextCache.SetFrameOffset(FrameContext.Title, Offset); } LGuiContextCache.SetFrameContextSize(FrameContext.Title, FrameContext.Size); LGuiLayout.EndLayout(); LGuiContext.EndFrame(); }