Last active
April 21, 2020 21:57
-
-
Save se5a/b66b9d3cd86992c4cae38888c97ff9c7 to your computer and use it in GitHub Desktop.
Nested BorderGroup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BorderGroup | |
{ | |
private static Vector2[] _startPos = new Vector2[8]; | |
private static Vector2[] _labelSize = new Vector2[8]; | |
private static uint[] _colour = new uint[8]; | |
private static byte _nestIndex = 0; | |
private static float _dentMulitpier = 3; | |
public static void BeginBorder(string label, uint colour) | |
{ | |
ImGui.PushID(label); | |
_colour[_nestIndex] = colour; | |
_startPos[_nestIndex] = ImGui.GetCursorScreenPos(); | |
_startPos[_nestIndex].X -= 3; | |
_startPos[_nestIndex].Y += ImGui.GetTextLineHeight() * 0.5f; | |
ImGui.Text(label); | |
_labelSize[_nestIndex] = ImGui.GetItemRectSize(); | |
_nestIndex++; | |
ImGui.Indent(_dentMulitpier * _nestIndex); | |
} | |
public static void BeginBorder(string label) | |
{ | |
BeginBorder(label, ImGui.GetColorU32(ImGuiCol.Border)); | |
} | |
public static void BeginBorder(string label, ImGuiCol colorIdx) | |
{ | |
BeginBorder(label, ImGui.GetColorU32(colorIdx)); | |
} | |
public static void EndBoarder() | |
{ | |
ImGui.Unindent(_dentMulitpier * _nestIndex); | |
_nestIndex--; | |
Vector2 size = new Vector2(ImGui.GetContentRegionAvail().X, ImGui.GetCursorScreenPos().Y - _startPos[_nestIndex].Y); | |
//ImGui.get | |
ImDrawListPtr wdl = ImGui.GetWindowDrawList(); | |
float by = _startPos[_nestIndex].Y + size.Y -_dentMulitpier * _nestIndex; | |
float rx = _startPos[_nestIndex].X + size.X - _dentMulitpier * _nestIndex; | |
Vector2[] pts = new Vector2[6]; | |
pts[0] = new Vector2(_startPos[_nestIndex].X + _dentMulitpier, _startPos[_nestIndex].Y); | |
pts[1] = _startPos[_nestIndex]; //top left | |
pts[2] = new Vector2(_startPos[_nestIndex].X, by); //bottom left | |
pts[3] = new Vector2(rx, by); //bottom right | |
pts[4] = new Vector2(rx, _startPos[_nestIndex].Y); //top right | |
pts[5] = new Vector2(_startPos[_nestIndex].X + _labelSize[_nestIndex].X + _dentMulitpier, _startPos[_nestIndex].Y); | |
wdl.AddPolyline(ref pts[0], pts.Length, _colour[_nestIndex], false, 1.0f); | |
ImGui.PopID(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment