Created
July 19, 2020 05:44
-
-
Save moebiussurfing/7750fd1ffba40a0ac33aa5879fc93363 to your computer and use it in GitHub Desktop.
openframeworks / ofxImGui / my custom ImGui helpers: big button and big toggle for bool parameters
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
//AddBigButton(bRandomizeIndex, 25);//index | |
AddBigButton(bRandomizeEditor, 25);//preset | |
AddBigToggle(PLAY_RandomizeTimer, 30); | |
//-- | |
//my custom ImGui helpers | |
////toggle ImGui button | |
////https://github.com/ocornut/imgui/issues/1537 | |
//-------------------------------------------------------------- | |
bool AddBigButton(ofParameter<bool>& parameter, float h)//button but using a bool not void param | |
{ | |
auto tmpRef = parameter.get(); | |
auto name = ofxImGui::GetUniqueName(parameter); | |
float w; | |
w = ImGui::GetWindowWidth()*0.9f; | |
ImGuiStyle *style = &ImGui::GetStyle(); | |
const ImVec4 colorButton = style->Colors[ImGuiCol_Button];//better for my theme | |
const ImVec4 colorHover = style->Colors[ImGuiCol_Button]; | |
const ImVec4 colorActive = style->Colors[ImGuiCol_ButtonActive]; | |
//const ImVec4 colorButton = style->Colors[ImGuiCol_ButtonHovered];//better for default theme | |
//const ImVec4 colorHover = style->Colors[ImGuiCol_ButtonHovered]; | |
//const ImVec4 colorActive = style->Colors[ImGuiCol_ButtonActive]; | |
ImGui::PushID(name); | |
ImGui::PushStyleColor(ImGuiCol_Button, colorButton); | |
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colorHover); | |
ImGui::PushStyleColor(ImGuiCol_ButtonActive, colorActive); | |
if (ImGui::Button((name), ImVec2(w, h))) | |
{ | |
ofLogNotice(__FUNCTION__) << name << ": BANG"; | |
tmpRef = true; | |
parameter.set(tmpRef); | |
} | |
ImGui::PopStyleColor(3); | |
ImGui::PopID(); | |
} | |
//-------------------------------------------------------------- | |
bool AddBigToggle(ofParameter<bool>& parameter, float h) | |
{ | |
auto tmpRef = parameter.get(); | |
auto name = ofxImGui::GetUniqueName(parameter); | |
//static float b = 1.0f; | |
//static float c = 0.5f; | |
//static int i = 3;// hue colors are from 0 to 7 | |
//ImVec4 _color1 = (ImVec4)ImColor::HSV(i / 7.0f, b, b); | |
//ImVec4 _color2 = (ImVec4)ImColor::HSV(i / 7.0f, c, c); | |
//-- | |
//button toggle | |
float w; | |
//float h; | |
//h = 30; | |
//w = 200; | |
w = ImGui::GetWindowWidth()*0.9f; | |
static bool _boolToggle = tmpRef; // default value, the button is disabled | |
if (_boolToggle == true)//enabled | |
{ | |
ImGuiStyle *style = &ImGui::GetStyle(); | |
const ImVec4 colorButton = style->Colors[ImGuiCol_Button];//better for my theme | |
const ImVec4 colorHover = style->Colors[ImGuiCol_Button]; | |
const ImVec4 colorActive = style->Colors[ImGuiCol_ButtonActive]; | |
//const ImVec4 colorButton = style->Colors[ImGuiCol_ButtonHovered];//better for default theme | |
//const ImVec4 colorHover = style->Colors[ImGuiCol_ButtonHovered]; | |
//const ImVec4 colorActive = style->Colors[ImGuiCol_ButtonActive]; | |
ImGui::PushID(name); | |
ImGui::PushStyleColor(ImGuiCol_Button, colorButton); | |
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colorHover); | |
ImGui::PushStyleColor(ImGuiCol_ButtonActive, colorActive); | |
ImGui::Button(name, ImVec2(w, h)); | |
if (ImGui::IsItemClicked(0)) | |
{ | |
_boolToggle = !_boolToggle; | |
tmpRef = _boolToggle; | |
parameter.set(tmpRef); | |
} | |
ImGui::PopStyleColor(3); | |
ImGui::PopID(); | |
} | |
else//disabled | |
{ | |
ImGuiStyle *style = &ImGui::GetStyle(); | |
const ImVec4 colorButton = style->Colors[ImGuiCol_Button];//better for my theme | |
const ImVec4 colorHover = style->Colors[ImGuiCol_ButtonHovered]; | |
const ImVec4 colorActive = style->Colors[ImGuiCol_ButtonActive]; | |
//const ImVec4 colorButton = style->Colors[ImGuiCol_ButtonHovered];//better for default theme | |
//const ImVec4 colorHover = style->Colors[ImGuiCol_Button]; | |
//const ImVec4 colorActive = style->Colors[ImGuiCol_ButtonActive]; | |
ImGui::PushStyleColor(ImGuiCol_Button, colorHover); | |
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colorHover); | |
ImGui::PushStyleColor(ImGuiCol_ButtonActive, colorActive); | |
if (ImGui::Button(name, ImVec2(w, h))) { | |
_boolToggle = true; | |
tmpRef = _boolToggle; | |
parameter.set(tmpRef); | |
} | |
ImGui::PopStyleColor(3); | |
} | |
//-- | |
//checkbox | |
//ImGui::PushID(name); | |
//ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(i / 7.0f, b, b)); | |
//ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(i / 7.0f, b, b)); | |
//ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(i / 7.0f, c, c)); | |
//if (ImGui::Checkbox(name, (bool *)&tmpRef)) | |
// //if (ImGui::Checkbox(ofxImGui::GetUniqueName(parameter), (bool *)&tmpRef)) | |
//{ | |
// parameter.set(tmpRef); | |
// ImGui::PopStyleColor(3); | |
// ImGui::PopID(); | |
// return true; | |
//} | |
//ImGui::PopStyleColor(3); | |
//ImGui::PopID(); | |
//return false; | |
} |
Author
moebiussurfing
commented
Jul 19, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment