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 void RenderHueArrow(LGuiRect HueRect, float Hue) { var ArrowX = HueRect.X + HueRect.Width * Hue; var ArrowY1 = HueRect.Y; var ArrowY2 = HueRect.Bottom; LGuiGraphics.DrawTriangle( new LGuiVec2(ArrowX, ArrowY1 + 5), new LGuiVec2(ArrowX - 5, ArrowY1), new LGuiVec2(ArrowX + 5, ArrowY1), LGuiColor.White, true); LGuiGraphics.DrawTriangle( new LGuiVec2(ArrowX, ArrowY2 - 5), new LGuiVec2(ArrowX - 5, ArrowY2), new LGuiVec2(ArrowX + 5, ArrowY2), LGuiColor.White, 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 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); }