ofxGui setDefaultHeight()

I was hoping to have 2 ofxPanel GUIs.

ofxPanel gui_admin;
ofxPanel gui_user;

One is for the admin and uses the standard GUI size.
And the other for the user which I was hoping can have larger sliders and buttons; i.e.

Using

   group_user.setDefaultHeight(50);

works but changes the size for both guis.

thanks for any tip.

Hi Stefan,

I don’t know of there is a work around for your case, but maybe you need some more advanced gui like those ones I analyzed some years ago for a OF 0.9.8 project. I just pasted this text from a file I wrote. I still use OfxGui because I don’t need any particular widget and I found it simple, efficient and full compliant with OF, especially if you need to mantein your code for years.

link save load ofParameter Group Model View Controller description keyboard input fine tuning 0.8.3 other
ofxDatGui NO YES ? YES YES NO NO NO ofParameter
ofxGuiExtended YES YES YES NO YES NO NO NO OF 0.9.8 ofParameterGroup arrangement
ofxImGui NO YES NO ? YES NO NO

Good luck

Paolo

Hi Stephan,
the setDefaultHeight is a static function which modifies a static variable. Actually you can call ofxGuiSetDefaultHeight(int height) which will have the same effect as calling it over a gui object as you are doing. As it is setting a static variable it will affect all instances of ofxGui although, in your particular case, it sounds to me that you will be showing one or the other gui, so at the moment you switch between these you can change the default height to the desired one for each case.

Thanks you two.
I will investigate what works best for my situation.

:slight_smile:

@stephanschulz there is actually a way to set the height to each element individually.
Look at this example
ofApp.h

#pragma once

#include "ofMain.h"
#include "ofxGui.h"
class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();
	
	ofxPanel gui, gui2;
	
	ofParameter<float> guiHeight = {"Gui Height", 20, 1, 100};
	
	
	ofParameter<int> intParam = {"int", 0,0,1000};
	ofParameter<float> floatParam = {"float", 0,0,1};
	ofParameter<glm::vec2> vec2Param = {"glm::vec2", {0,0},{0,0},{1,1}};
	ofParameter<glm::vec3> vec3Param = {"glm::vec3", {0,0,0},{0,0,0},{1,1,1}};
	ofParameter<ofRectangle> rectParam = {"ofRectangle", {0,0,0,0},{0,0,0,0},{0,0,1,1}};
	ofParameter<ofColor> colorParam = {"ofColor", {0},{0},{255}};
	ofParameter<ofFloatColor> fColorParam = {"ofFloatColor", {0},{0},{1}};
	ofParameter<bool> boolParam = {"bool", true};
	ofParameter<void> voidParam = {"void"};


	void guiHeightChanged(float&);

	void setGuiGroupElementHeight(ofxGuiGroup* group, float height);
	
	ofEventListener listener;
	
};

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
	
	gui.setup("blabla");
	
	gui.add(intParam);
	gui.add(floatParam);
	gui.add(vec2Param);
	gui.add(vec3Param);
	gui.add(rectParam);
	gui.add(colorParam);
	gui.add(fColorParam);
	gui.add(boolParam);
	gui.add(voidParam);
	
	
	gui2.setup("2");
	gui2.setPosition(gui.getShape().getTopRight() + glm::vec3(20,0,0));
	gui2.add(guiHeight);
	
	listener  = guiHeight.newListener(this, &ofApp::guiHeightChanged);
}

//--------------------------------------------------------------
void ofApp::update(){

}
//--------------------------------------------------------------
void ofApp::setGuiGroupElementHeight(ofxGuiGroup* group, float height){
	if(group){
		auto n = group->getNumControls();
		for(size_t i = 0; i < n; i++){
			auto c = group->getControl(i);
			if(c){
				auto g = dynamic_cast<ofxGuiGroup*>(c);
				if(g){
					setGuiGroupElementHeight(g, height);
				}else{
					auto r = c->getShape();
					r.height = height;
					if(dynamic_cast<ofxColorPicker_<unsigned char>*>(c)||
					   dynamic_cast<ofxColorPicker_<unsigned short>*>(c)||
					   dynamic_cast<ofxColorPicker_<float>*>(c)
					  	){
						r.height = r.width * 9. / 11.;
					}
					c->setShape(r);
				}
			}
		}
	}
}
//--------------------------------------------------------------
void ofApp::guiHeightChanged(float&){
	setGuiGroupElementHeight(&gui, guiHeight);

}
//--------------------------------------------------------------
void ofApp::draw(){

	gui.draw();
	gui2.draw();
}

Out of it the only thing you need is the void setGuiGroupElementHeight(ofxGuiGroup* group, float height); function, which you can actually copy paste anywhere else.

1 Like

I edited the code above so it now will resize properly the color picker

1 Like