ofxGuiElement *ofxGuiContainer::addSpacer(const ofJson& config) {
    ofxGuiElement* e = add<ofxGuiElement>();
    e->setConfig(ofJson({
        {"border-width", 0},
        {"background-color", "rgba(0,0,0,0)"}
    }));
    e->setConfig(config);
    return e;
}
Example #2
0
//--------------------------------------------------------------
void ofApp::setup(){

	ofSetFrameRate(120);

	ofAddListener(ofEvents().draw, this, &ofApp::drawMousePosition, OF_EVENT_ORDER_AFTER_APP+1);

	testBool.set("bool", true);
	testFloat.set("float", 0.5, 0, 1);
	testColor.set("color", ofColor(120), ofColor(0,0), ofColor(255,255));
	testPoint.set("point", ofPoint(0.5,0.5), ofPoint(0,0), ofPoint(100,100));
	testString.set("string", "teststring");


	gui_flex.setupFlexBoxLayout();


	ofxGuiGroup* control = gui_control.addPanel("active layout", ofJson({
		{"show-header", false},
		{"direction", "horizontal"},
		{"left", 300},
		{"width", "auto"}
	}));
	control->setExclusiveToggles(true);
	control->add(gui_box.getVisible().set("box layout", false));
	control->add(gui_flex.getVisible().set("flexbox layout", true));
	control->add<ofxGuiLabel>("(note: both cases should look identical)");


	vector<ofxGui*> guis;
	guis.push_back(&gui_box);
	guis.push_back(&gui_flex);

	for(ofxGui* gui : guis){

		gui->add(testBool, testFloat);

		vector<ofxGuiGroup*> panels;

		ofxGuiGroup* panel1 = gui->addPanel();
		panel1->setPosition(10, 130);
		panel1->loadTheme("theme_default.json");

		ofxGuiGroup* panel2 = gui->addPanel();
		panel2->loadTheme("theme_light.json");
		panel2->setPosition(panel1->getPosition().x + panel1->getWidth()+10, panel1->getPosition().y);

		panels.push_back(panel1);
		panels.push_back(panel2);

		for(ofxGuiGroup* panel : panels){
			panel->add(testBool);
			panel->add(testPoint);
			panel->add(testFloat);
			panel->add(testColor);
			panel->add(testString);
		}

		ofxGuiGroup* panel3 = gui->addPanel("horizontal", ofJson({
			{"direction", "horizontal"},
			{"flex-direction", "row"}
		}));
		panel3->setPosition(panel2->getPosition().x + panel2->getWidth()+10, panel2->getPosition().y);
		panel3->add(testBool);
		panel3->add(testBool);
		panel3->add(testBool);

		ofxGuiGroup* panel4 = gui->addPanel();
		panel4->setPosition(panel3->getPosition().x, panel3->getPosition().y +  panel3->getHeight()+10);
		panel4->add(testFloat);
		ofxGuiGroup* panel4_vertical = panel4->addGroup("", ofJson({
			{"direction", "horizontal"},
			{"show-header", false},
			{"flex-direction", "row"},
			{"width", 270}
		}));
		panel4_vertical->add(testBool, ofJson({
			{"type", "radio"},
			{"show-name", false},
			{"width", "10%"}
		}));
		panel4_vertical->add(testFloat, ofJson({{"width", "45%"}}));
		panel4_vertical->add(testFloat, ofJson({{"width", "45%"}}));

//		ofJson toggleTheme = {{"show-name", false}, {"width", "10%"}};
//	    ofJson postToggleTheme = {{"fill-color", "rgba(220,80,50,0.5)"}, {"width", "90%"}};
//	    ofJson postToggle2Theme = {{"fill-color", "rgba(220,80,50,0.5)"}, {"width", "45%"}};
//	    ofJson groupTheme = {{"flex-direction", "row"}, {"flex-wrap", "wrap"}, {"width", 320}, {"align-content", "space-between"}};

//	    //////  Groups

//	    menuAudioGroup = menuAudioPanel->addGroup("Audio Analyzer");

//	    powerGroup = menuAudioGroup->addGroup("POWER", groupTheme);
//	    powerGroup->add(energyToggleVal, toggleTheme);
//	    powerGroup->add(energyMultiplierSliderVal, postToggle2Theme);
//	    powerGroup->add(intenSmoothSliderVal, postToggle2Theme);
//	    powerGroup->add<ofxGuiValuePlotter>(energySliderVal);
//	    powerGroup->add(rmsSliderVal);


		//give the flexbox layout a different color to be able to see that something happens when you change the layout
		if(gui == &gui_flex){
			ofJson config = {
				{
					"group-header", {
						 {"background-color", "#123456"}
					 }
				 }
			};
			panel1->setTheme(config);
			panel2->setTheme(config);

		}

	}

}
Example #3
0
//--------------------------------------------------------------
void ofApp::setup(){

	ofSetLogLevel(OF_LOG_VERBOSE);

	ofSetFrameRate(120);

	activeName.set("element name", "");
	activeIndex.set("element index", -1);


	/*
	 *  panel without header and a button that toggles the visibility of all the other headers
	 */
	panel1 = gui.addPanel();
	panel1->setPosition(20,20);
	panel1->setShowHeader(false);

	/*
	 * toggle to show or hide header
	 */

	showHeaders.set("show/hide header", true);
	panel1->add(showHeaders, ofJson({{"type", "fullsize"}, {"text-align", "center"}}));

	panel1->addSpacer(0, 20);

	/*
	 * Plotter
	 */
	panel1->addFpsPlotter();
	auto sinusfunction = [&] (float x) { return sin(x); };

	sinus.set("sinus", ofPoint(0,0), ofPoint(0, -1), ofPoint(4*PI, 1));
	panel1->add<ofxGuiFunctionPlotter>(sinus, sinusfunction);

	panel1->add<ofxGuiValuePlotter>(randomVal.set("random value", 0, 0, 9), ofJson({{"precision", 2}}));

	panel1->addSpacer(0, 20);

	/*
	 * buttons
	 */
	buttons = panel1->addGroup("buttons");
	buttons->add<ofxGuiButton>("fullsize button", ofJson({{"type", "fullsize"}, {"text-align", "center"}}));
	buttons->add<ofxGuiButton>("checkbox button", ofJson({{"type", "checkbox"}}));
	buttons->add<ofxGuiButton>("radio button", ofJson({{"type", "radio"}}));

	panel1->addSpacer(0, 20);

	/*
	 *  input fields
	 */
	panel1->add<ofxGuiFloatInputField>(floatfieldVal.set("float input",3.5,0,500));
	panel1->add<ofxGuiTextField>(textfieldVal.set("text input","type in here"));

	/*
	 * ofParameterGroup example with radio toggles, listener to show current index and name
	 */

	colorParameters.setName("ofParameterGroup");
	colorParameters.add(color0.set("mediumSlateBlue",false));
	colorParameters.add(color1.set("tomato",false));
	colorParameters.add(color2.set("mediumAquaMarine",false));
	colorParameters.add(color3.set("steelBlue",false));

	colorPanel = gui.addPanel("header color", ofJson({{"width", 270}}));
	colorPanel->setPosition(panel1->getShape().getTopRight()+ofPoint(20,0));
	colorToggles = colorPanel->addGroup(colorParameters);
	colorToggles->setExclusiveToggles(true);
	colorToggles->setConfig(ofJson({{"type", "radio"}}));

	/*
	 *  labels
	 */
	labels = colorPanel->addGroup("labels");
	labels->add(activeName);
	labels->add<ofxGuiIntLabel>(activeIndex);
	labels->add<ofxGuiLabel>("text without parameter");


	/*
	 *  sliders
	 */
	sliders = gui.addContainer("vertical sliders", ofJson({{"direction", "horizontal"}}));
	sliders->setPosition(colorPanel->getShape().getTopRight()+ofPoint(20,0));

	sliders->add(slider1Val.set("slider1", 1. / 7., 0, 1), ofJson({{"width", 40}, {"height", 130}}));
	sliders->add(slider2Val.set("slider2", 5. / 7., 0, 1), ofJson({{"width", 50}, {"height", 130}}));
	sliders->add(slider3Val.set("slider3", 4. / 7., 0, 1), ofJson({{"width", 60}, {"height", 130}}));
	sliders->add(slider4Val.set("slider4", 6. / 7., 0, 1), ofJson({{"width", 70}, {"height", 130}}));

	sliders->add(circularSliderVal.set("slider", 0.5, 0, 1), ofJson({{"type", "circular"}, {"width", 130}, {"height", 130}, {"precision", 2}}));


	/*
	 * showing the differences between containers, groups and panels
	 */

	ofJson containerSettings = {{"width", 400}};

	containerExample = gui.addContainer("Container", containerSettings);
	containerExample->add(containerLabel.set("Container", "A collection of elements."));
	containerExample->setPosition(sliders->getShape().getBottomLeft() + ofPoint(20, 170));

	groupExample = gui.addGroup("Group", containerSettings);
	groupExample->add(groupLabel.set("A container with header to minimize / maximize."));
	groupExample->setPosition(containerExample->getShape().getBottomLeft() + ofPoint(0, 20));

	panelExample = gui.addPanel("Panel", containerSettings);
	panelExample->add(panelLabel.set("A container with header to drag, save and load."));
	panelExample->setPosition(groupExample->getShape().getBottomLeft() + ofPoint(0, 20));


	/*
	 * adding listeners
	 */

	showHeaders.addListener(this, &ofApp::toggleGroupHeader);
	colorToggles->getActiveToggleIndex().addListener(this, &ofApp::setHeaderColors);
	colorToggles->setActiveToggle(3);

}