How to change UI attributes (like background color) of ofParameter<int>?

When I create an ofxPanel and add an ofParamter<int>, how can I change the appearance of that slider - the way I can with ofxIntSlider? For example setBackgroundColor, setFillColor, etc.

int guiWidth = 300;
gui_Cyls.setDefaultWidth(guiWidth);
	gui_Cyls.setDefaultHeight(15);
	gui_Cyls.setWidthElements(guiWidth);
	gui_Cyls.setDefaultWidth(guiWidth);
	gui_Cyls.setDefaultHeight(30);
	gui_Cyls.setWidthElements(300);
	gui_Cyls.setDefaultTextPadding(35);
	gui_Cyls.setDefaultBorderColor(ofColor::orange); //color name
	gui_Cyls.setDefaultHeaderBackgroundColor(ofColor(255, 0, 0)); //rgb
	gui_Cyls.setDefaultFillColor(ofColor(255, 0, 0));
	gui_Cyls.setDefaultBackgroundColor(ofColor(16));//greys
	gui_Cyls.setDefaultTextColor(ofColor(255));

//...

gui_Cyls.setup("CONTROL"); // most of the time you don't need a name but don't forget to call setup
	gui_Cyls.setName("CONTROL");

	//add widgets
//...
1 Like

Thanks. I’d like to change the background colour of the sliders manually at different times during execution.

For example, when adjusting slider1, sometimes I want the background of slider2 to become red depending on the value selected in slider1. I can do this easily with ofxIntSlider, since it has the function setBackgroundColor, but I don’t know where or how to do this if I change the slider’s type from ofxIntSlider to ofParamater<int>.

ey @lethalrush, sorry but I don’t know.

anyway with that code you are maybe closer, if it’s possible…

ofApp.h

	ofParameterGroup parameters;
	ofParameter<float> parameter1;
	ofParameter<int> parameter2;
	void Changed_parameters(ofAbstractParameter &e);
	ofxPanel gui_panel;
ofApp.cpp

void ofApp::setup(){
    parameter1.set("parameter1 Name", 0.0f, 0.0f, 1.f);
    parameter2.set("parameter2 Name", 0, 0, 10);

	parameters.setName("group of parameters");
	parameters.add(parameter1);
	parameters.add(parameter2);

    gui_panel.setup("myPanel");
    gui_panel.add(parameters);

    ofAddListener(parameters.parameterChangedE(), this, &ofApp::Changed_parameters);

}

void ofApp::Changed_parameters(ofAbstractParameter &e) {
        string WIDGET_name = e.getName();

        ofLogNotice() << "a parameter from group has changed : " << WIDGET_name << ": " << e;

        if (WIDGET_name == "parameter1 Name")
        {
            // re-check if type is float as expected (not required)
            if(e.type() == typeid(ofParameter<float>).name() )
            {
                ofParameter<float> p = e.cast<float>();
                ofLogNotice() << "parameter1 type is a float with value: " <<  p.get();
            }
            // ofLogNotice() << "parameter1 = " <<  parameter1;
        }
        else if (WIDGET_name == "parameter2 Name")
        {
            ofLogNotice() << "parameter2 = " <<  parameter2;
        }
}

on the callback / listener function maybe you can do something trying to get/cast the parameter from the gui panel object, but I don’t how how to do it neither…