1- #include " Helpers .h"
1+ #include " ImHelpers .h"
22
33// --------------------------------------------------------------
44ofxImGui::Settings::Settings ()
@@ -74,7 +74,7 @@ bool ofxImGui::BeginWindow(const std::string& name, Settings& settings, bool col
7474
7575ImGui::SetNextWindowPos (settings.windowPos , settings.lockPosition ? ImGuiCond_Always : ImGuiCond_Appearing);
7676ImGui::SetNextWindowSize (settings.windowSize , ImGuiCond_Appearing);
77- ImGui::SetNextWindowCollapsed (collapse, ImGuiCond_Appearing);
77+ // ImGui::SetNextWindowCollapsed(collapse, ImGuiCond_Appearing);
7878return ImGui::Begin (name.c_str (), open, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize | (collapse ? 0 : ImGuiWindowFlags_NoCollapse));
7979}
8080
@@ -165,7 +165,7 @@ bool ofxImGui::BeginTree(const std::string& name, Settings& settings)
165165void ofxImGui::EndTree (Settings& settings)
166166{
167167ImGui::TreePop ();
168-
168+
169169settings.treeLevel = std::max (0 , settings.treeLevel - 1 );
170170
171171// Clear the list of names from the stack.
@@ -439,9 +439,9 @@ bool ofxImGui::AddParameter(ofParameter<std::string>& parameter, size_t maxChars
439439}
440440
441441// --------------------------------------------------------------
442- bool ofxImGui::AddParameter (ofParameter<void >& parameter)
442+ bool ofxImGui::AddParameter (ofParameter<void >& parameter, float width )
443443{
444- if (ImGui::Button (GetUniqueName (parameter)))
444+ if (ImGui::Button (GetUniqueName (parameter), glm::vec2 (width, 0 . 0f )))
445445{
446446parameter.trigger ();
447447return true ;
@@ -516,6 +516,18 @@ bool ofxImGui::AddStepper(ofParameter<int>& parameter, int step, int stepFast)
516516return false ;
517517}
518518
519+ // --------------------------------------------------------------
520+ bool ofxImGui::AddSlider (ofParameter<float >& parameter, const char * format, float power)
521+ {
522+ auto tmpRef = parameter.get ();
523+ if (ImGui::SliderFloat (GetUniqueName (parameter), (float *)&tmpRef, parameter.getMin (), parameter.getMax (), format, power))
524+ {
525+ parameter.set (tmpRef);
526+ return true ;
527+ }
528+ return false ;
529+ }
530+
519531// --------------------------------------------------------------
520532bool ofxImGui::AddRange (const std::string& name, ofParameter<int >& parameterMin, ofParameter<int >& parameterMax, int speed)
521533{
@@ -638,7 +650,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::tvec2<int>>&
638650for (size_t i = 0 ; i < values.size (); ++i)
639651{
640652const auto iname = name + " " + ofToString (i);
641- result |= ImGui::SliderInt2 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
653+ if (minValue == 0 && maxValue == 0 )
654+ {
655+ result |= ImGui::DragInt2 (GetUniqueName (iname), glm::value_ptr (values[i]));
656+ }
657+ else
658+ {
659+ result |= ImGui::SliderInt2 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
660+ }
642661}
643662return result;
644663}
@@ -650,7 +669,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::tvec3<int>>&
650669for (size_t i = 0 ; i < values.size (); ++i)
651670{
652671const auto iname = name + " " + ofToString (i);
653- result |= ImGui::SliderInt3 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
672+ if (minValue == 0 && maxValue == 0 )
673+ {
674+ result |= ImGui::DragInt3 (GetUniqueName (iname), glm::value_ptr (values[i]));
675+ }
676+ else
677+ {
678+ result |= ImGui::SliderInt3 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
679+ }
654680}
655681return result;
656682}
@@ -662,7 +688,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::tvec4<int>>&
662688for (size_t i = 0 ; i < values.size (); ++i)
663689{
664690const auto iname = name + " " + ofToString (i);
665- result |= ImGui::SliderInt4 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
691+ if (minValue == 0 && maxValue == 0 )
692+ {
693+ result |= ImGui::DragInt4 (GetUniqueName (iname), glm::value_ptr (values[i]));
694+ }
695+ else
696+ {
697+ result |= ImGui::SliderInt4 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
698+ }
666699}
667700return result;
668701}
@@ -674,7 +707,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::vec2>& values
674707for (size_t i = 0 ; i < values.size (); ++i)
675708{
676709const auto iname = name + " " + ofToString (i);
677- result |= ImGui::SliderFloat2 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
710+ if (minValue == 0 && maxValue == 0 )
711+ {
712+ result |= ImGui::DragFloat2 (GetUniqueName (iname), glm::value_ptr (values[i]));
713+ }
714+ else
715+ {
716+ result |= ImGui::SliderFloat2 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
717+ }
678718}
679719return result;
680720}
@@ -686,7 +726,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::vec3>& values
686726for (size_t i = 0 ; i < values.size (); ++i)
687727{
688728const auto iname = name + " " + ofToString (i);
689- result |= ImGui::SliderFloat3 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
729+ if (minValue == 0 && maxValue == 0 )
730+ {
731+ result |= ImGui::DragFloat3 (GetUniqueName (iname), glm::value_ptr (values[i]));
732+ }
733+ else
734+ {
735+ result |= ImGui::SliderFloat3 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
736+ }
690737}
691738return result;
692739}
@@ -698,7 +745,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::vec4>& values
698745for (size_t i = 0 ; i < values.size (); ++i)
699746{
700747const auto iname = name + " " + ofToString (i);
701- result |= ImGui::SliderFloat4 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
748+ if (minValue == 0 && maxValue == 0 )
749+ {
750+ result |= ImGui::DragFloat4 (GetUniqueName (iname), glm::value_ptr (values[i]));
751+ }
752+ else
753+ {
754+ result |= ImGui::SliderFloat4 (GetUniqueName (iname), glm::value_ptr (values[i]), minValue, maxValue);
755+ }
702756}
703757return result;
704758}
@@ -712,7 +766,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<ofVec2f>& values,
712766for (size_t i = 0 ; i < values.size (); ++i)
713767{
714768const auto iname = name + " " + ofToString (i);
715- result |= ImGui::SliderFloat2 (GetUniqueName (iname), values[i].getPtr (), minValue, maxValue);
769+ if (minValue == 0 && maxValue == 0 )
770+ {
771+ result |= ImGui::DragFloat2 (GetUniqueName (iname), values[i].getPtr ());
772+ }
773+ else
774+ {
775+ result |= ImGui::SliderFloat2 (GetUniqueName (iname), values[i].getPtr (), minValue, maxValue);
776+ }
716777}
717778return result;
718779}
@@ -724,7 +785,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<ofVec3f>& values,
724785for (size_t i = 0 ; i < values.size (); ++i)
725786{
726787const auto iname = name + " " + ofToString (i);
727- result |= ImGui::SliderFloat3 (GetUniqueName (iname), values[i].getPtr (), minValue, maxValue);
788+ if (minValue == 0 && maxValue == 0 )
789+ {
790+ result |= ImGui::DragFloat3 (GetUniqueName (iname), values[i].getPtr ());
791+ }
792+ else
793+ {
794+ result |= ImGui::SliderFloat3 (GetUniqueName (iname), values[i].getPtr (), minValue, maxValue);
795+ }
728796}
729797return result;
730798}
@@ -736,24 +804,48 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<ofVec4f>& values,
736804for (size_t i = 0 ; i < values.size (); ++i)
737805{
738806const auto iname = name + " " + ofToString (i);
739- result |= ImGui::SliderFloat4 (GetUniqueName (iname), values[i].getPtr (), minValue, maxValue);
807+ if (minValue == 0 && maxValue == 0 )
808+ {
809+ result |= ImGui::DragFloat4 (GetUniqueName (iname), values[i].getPtr ());
810+ }
811+ else
812+ {
813+ result |= ImGui::SliderFloat4 (GetUniqueName (iname), values[i].getPtr (), minValue, maxValue);
814+ }
740815}
741816return result;
742817}
743818
744819// --------------------------------------------------------------
745- void ofxImGui::AddImage (ofBaseHasTexture& hasTexture, const ofVec2f& size)
820+ void ofxImGui::AddImage (const ofBaseHasTexture& hasTexture, const ofVec2f& size)
746821{
747822ofxImGui::AddImage (hasTexture.getTexture (), size);
748823}
749824
750825// --------------------------------------------------------------
751- void ofxImGui::AddImage (ofTexture& texture, const ofVec2f& size)
826+ void ofxImGui::AddImage (const ofTexture& texture, const ofVec2f& size)
752827{
753828ImTextureID textureID = GetImTextureID (texture);
754829ImGui::Image (textureID, size);
755830}
756831
832+ #if OF_VERSION_MINOR >= 10
833+
834+ // --------------------------------------------------------------
835+ void ofxImGui::AddImage (const ofBaseHasTexture& hasTexture, const glm::vec2& size)
836+ {
837+ ofxImGui::AddImage (hasTexture.getTexture (), size);
838+ }
839+
840+ // --------------------------------------------------------------
841+ void ofxImGui::AddImage (const ofTexture& texture, const glm::vec2& size)
842+ {
843+ ImTextureID textureID = GetImTextureID (texture);
844+ ImGui::Image (textureID, size);
845+ }
846+
847+ #endif
848+
757849
758850static auto vector_getter = [](void * vec, int idx, const char ** out_text)
759851{
@@ -776,4 +868,3 @@ bool ofxImGui::VectorListBox(const char* label, int* currIndex, std::vector<std:
776868 return ImGui::ListBox (label, currIndex, vector_getter,
777869 static_cast <void *>(&values), values.size ());
778870}
779-
0 commit comments