Created
April 29, 2020 02:28
-
-
Save se5a/d6783dfdb0fddfc9b50a2db96b52bb34 to your computer and use it in GitHub Desktop.
BorderGroup, and BorderListOptions
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 static class BorderListOptions | |
{ | |
private static Vector2 _labelSize = new Vector2(); | |
private static float _xleft; | |
private static float _xcentr; | |
private static float _xright; | |
private static float _ytop; | |
private static float _yctr1; | |
private static float _yctr2; | |
private static float _ybot; | |
private static uint _colour; | |
private static float _dentMulitpier = 3; | |
public static void Begin(string id, string[] list, ref int selected, float width) | |
{ | |
ImGui.PushID(id); | |
_colour = ImGui.GetColorU32(ImGuiCol.Border); | |
_labelSize = new Vector2( width, ImGui.GetTextLineHeight()); | |
ImGui.Columns(2, id, false); | |
ImGui.SetColumnWidth(0, width); | |
_xleft = ImGui.GetCursorScreenPos().X; | |
_ytop = ImGui.GetCursorScreenPos().Y; | |
_xcentr = _xleft + width; | |
ImGui.Indent(_dentMulitpier); | |
//display the list of items: | |
for (int i = 0; i < list.Length; i++) | |
{ | |
var pos = ImGui.GetCursorScreenPos(); | |
ImGui.Text(list[i]); | |
if (ImGui.IsItemClicked()) | |
selected = i; | |
if(i == selected) | |
{ | |
_yctr1 = pos.Y; | |
_yctr2 = ImGui.GetCursorScreenPos().Y; | |
} | |
} | |
_ybot = ImGui.GetCursorScreenPos().Y; | |
//if nothing is selected we'll draw a line at the bottom instead of around one of the items: | |
if(selected < 0) | |
{ | |
_yctr1 = _ybot; | |
_yctr2 = _ybot; | |
} | |
ImGui.NextColumn(); //set nextColomn so the imgui.items placed after this get put into the righthand side | |
ImGui.Indent(_dentMulitpier); | |
} | |
/* | |
public static void Begin(string id, ref int selected, string[] list) | |
{ | |
Begin(id, list, ref selected, ImGui.GetColorU32(ImGuiCol.Border)); | |
} | |
public static void Begin(string id, string[] list, ref int selected, ImGuiCol colorIdx) | |
{ | |
Begin(id, list, ref selected, ImGui.GetColorU32(colorIdx)); | |
} | |
*/ | |
public static void End(int width2ndColomn) | |
{ | |
ImGui.NextColumn(); | |
ImGui.Columns(0); | |
ImGui.Unindent(_dentMulitpier); | |
_xright = _xcentr + width2ndColomn; | |
float boty = Math.Max(_ybot, ImGui.GetCursorScreenPos().Y); //is the list bigger, or the items drawn after it. | |
ImDrawListPtr wdl = ImGui.GetWindowDrawList(); | |
Vector2[] pts = new Vector2[9]; | |
pts[0] = new Vector2(_xleft, _yctr1); //topleft of the selected item | |
pts[1] = new Vector2(_xleft, _yctr2); //botomleft of the selected item | |
pts[2] = new Vector2(_xcentr, _yctr2); //bottom rigth of selected item | |
pts[3] = new Vector2(_xcentr, boty); //bottom left of rh colomn | |
pts[4] = new Vector2(_xright, boty); //bottom Right | |
pts[5] = new Vector2(_xright, _ytop); //top righht | |
pts[6] = new Vector2(_xcentr, _ytop); //top mid | |
pts[7] = new Vector2(_xcentr, _yctr1); //selected top right | |
pts[8] = pts[0]; //selected top left | |
wdl.AddPolyline(ref pts[0], pts.Length, _colour, false, 1.0f); | |
ImGui.PopID(); | |
} | |
} | |
public static 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 Begin(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 Begin(string label) | |
{ | |
Begin(label, ImGui.GetColorU32(ImGuiCol.Border)); | |
} | |
public static void Begin(string label, ImGuiCol colorIdx) | |
{ | |
Begin(label, ImGui.GetColorU32(colorIdx)); | |
} | |
public static void End() | |
{ | |
ImGui.Unindent(_dentMulitpier * _nestIndex); | |
_nestIndex--; | |
var pos = ImGui.GetCursorScreenPos(); | |
var regionAvail = ImGui.GetContentRegionAvail(); | |
Vector2 size = new Vector2(regionAvail.X, pos.Y - _startPos[_nestIndex].Y); | |
ImDrawListPtr wdl = ImGui.GetWindowDrawList(); | |
float by = _startPos[_nestIndex].Y + size.Y + _dentMulitpier -_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