jvcleave / ofxImGui

Use ImGui in openFrameworks
293 stars 124 forks source link

conflicting programming models? #73

Closed sphaero closed 6 years ago

sphaero commented 6 years ago

I was just wondering while testing this addon/lib whether this approach of dealing with UI logic inside the draw call is right (in OF terms). For example:

if (ImGui::Button("Load Image..."))
{
    auto dialogResult = ofSystemLoadDialog("Load Image", false, ofToDataPath(""));
    if (dialogResult.bSuccess)
    {
        this->loadImage(dialogResult.filePath);
    }
}

This is intervening in the draw loop and makes it stall while loading the image from filesystem. Input events are not handled in the draw loop, but then these must be cached for them to work in the draw loop?

I know Immediate Mode UI's are bit of non-classical approach but this feels kind of wrong? Any comments on this?

jvcleave commented 6 years ago

Immediate mode takes some getting used to but I prefer it. The addon is mainly to help start imgui, provide "engines" that support all the platforms OF runs on, and some methods to help out using OF textures and images.

I didn't want to try and wrap everything that imgui supports as that is likely to change and I wanted it to be fairly easy to use existing imgui example code

ofSystemLoadDialog could cause an issue if it stops the drawing loop. I would probably handle it by using an imgui dialog box.

sphaero commented 6 years ago

fwiw, I found it better matching the model by disabling autoDraw, doing the gui logic in update and doing the draw explicitly in draw(), ie:

void ofApp::setup(){
    gui.setup(nullptr, false);
    guiVisible = true;
}

//--------------------------------------------------------------
void ofApp::update(){
    // Gui
    if (this->guiVisible)
    {
        gui.begin();
        // Create a window called "My First Tool", with a menu bar.
        if (ImGui::BeginMainMenuBar())
        ...  
        gui.end();
    }
}

//--------------------------------------------------------------
void ofApp::draw(){
    gui.draw();
}

I there are any repercussions I'll post it here