Skip to content

Conversation

@ewgnr
Copy link

@ewgnr ewgnr commented Jun 9, 2025

Here an simple open frameworks example how to use it

ofApp.cpp:


#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup()
{
myGui = new ofxDatGui(ofxDatGuiAnchor::TOP_RIGHT);
myGui->enableFboMode(true, ofGetWidth(), ofGetHeight());

for (int i = 0; i < 12; i++)
{
	textInputCount = i;
	myGui->addTextInput("** input " + ofToString(textInputCount), "nested input field");
}

myGui->onTextInputEvent(this, &ofApp::onTextInputEvent);
ofAddListener(ofEvents().mouseScrolled, this, &ofApp::mouseScrolled);

}

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

//--------------------------------------------------------------
void ofApp::draw()
{
ofTexture& guiTex = myGui->getFboTexture();
guiTex.draw(0, 0); // or use as texture
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key)
{
std::cout << "Key pressed: " << key << std::endl;

if (key == 'a' || key == 'A')
{
	textInputCount++;
	myGui->addTextInput("** input " + ofToString(textInputCount), "nested input field");
}

}

//--------------------------------------------------------------
void ofApp::onTextInputEvent(ofxDatGuiTextInputEvent e)
{
cout << "onTextInputEvent: " << e.target->getLabel() << " " << e.target->getText() << endl;
}

//--------------------------------------------------------------
void ofApp::mouseScrolled(ofMouseEventArgs& args)
{
float scrollAmount = args.scrollY * 10.0f; // Adjust speed

myGui->scroll(scrollAmount);

}

ofApp.h:


#pragma once

#include "ofMain.h"
#include "ofxDatGui.h"

class ofApp : public ofBaseApp
{

public:
	void setup();
	void update();
	void draw();

	void keyPressed(int key);
	void onTextInputEvent(ofxDatGuiTextInputEvent e);
	void mouseScrolled(ofMouseEventArgs& args);

	size_t textInputCount;
	ofxDatGui* myGui;

};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant