Created
July 25, 2020 22:18
-
-
Save se5a/840872fc46d8a01ffeaa3fed59c40446 to your computer and use it in GitHub Desktop.
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 bool Switch2State(string label, ref bool state, string leftState = "Off", string rightState = "On") | |
{ | |
int intState = Convert.ToInt32(state); | |
string strstate = leftState; | |
if (state == true) | |
strstate = rightState; | |
var txtWid = Math.Max(ImGui.CalcTextSize(leftState).X, ImGui.CalcTextSize(rightState).X); | |
ImGui.PushItemWidth(txtWid * 3); | |
var cpos = ImGui.GetCursorPos(); | |
if(ImGui.SliderInt(label,ref intState, 0, 1, "" )) | |
{ | |
state = Convert.ToBoolean(intState); | |
return true; | |
} | |
Vector2 recSize = ImGui.GetItemRectSize(); | |
float x = cpos.X + (intState * txtWid * 2); | |
float y = (float)(cpos.Y + recSize.Y * 0.5 - ImGui.GetTextLineHeight() * 0.5); | |
ImGui.SetCursorPos(new Vector2(x, y)); | |
ImGui.Text(strstate); | |
ImGui.PopItemWidth(); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment