Dear ImGui State Management

Recommended Posts

Hello,

Just wondering how others have managed there GUI state when using ImGui, it seems as though you will end up with huge if else branches or switch cases to resolve the state of the dialog essentially a big state machine...

// WinForm
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream ;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
// Create a File
}
}

// My ImGui Guess
{
{
{
m_FileDialog.Open("New Project");
m_UIState = UIState::New_File_Dialog;
}
}

{
{
m_UIState = UIState::Build_Dialog;
}

}

// Current State, If Else or Switch etc?
if(m_UIState == UIState::New_File_Dialog)
{
// Do the New File dialog
if(m_FileDialog.ShowDialog() == DialogResult::OK)
{
// Create file.
}
}
else if (m_UIState == UIState::Build_Dialog)
{
// Do the Build Dialog
}

Thanks,

Share on other sites
46 minutes ago, Jman2 said:

Hello,

Just wondering how others have managed there GUI state when using ImGui, it seems as though you will end up with huge if else branches or switch cases to resolve the state of the dialog essentially a big state machine...

I have slightly adapted Imgui to my render lifecycle and input handling, everything imgui related is inside my imgui overlay class. I call Imgui::Newframe once each frame before all other drawable objects start their frame preparations. Each renderable can prepare its own imgui dialog (imgui::begin ... lego together a dialogue ... imgui::end), and when it comes to drawing, imgui renders last.

I don't have any sophisticated state management yet. The only gl state imgui changes is the blend equation, and it disables culling and the depth test and enables scissoring. That can easily be done and undone in the render method of the imgui overlay.

The day may come that i will have to think about something more fancy for state management ...

Edited by Green_Baron
spelling

Share on other sites
Just now, Green_Baron said:

I have slightly adapted Imgui to my render lifercycle and input handling, everything imgui related is inside my imgui overlay class. I call Imgui::Newframe once each frame before all other drawable objects start their frame preparations. Each renderable can prepare its own imgui dialog (imgui::begin ... lego together a dialogue ... imgui::end), and when it comes to drawing, imgui renders last.

I don't have any sophisticate state management yet. The only gl state imgui changes is the blend equation, and it disables culling and the depth test and enables scissoring. That can easily be done and undone in the render method of the imgui overlay.

The day may come that i will have to think about something more fancy for state management ...

Yes my engine has a similar set up, i have an void OnGui() that is called, i have a ImGui Manager that initialize the frame based on the graphics version and os platform etc. So mostly just figuring out how most do there managment of the actual GUI for sophisticated apps like Level Editors as opposed to in game debug etc.

	virtual bool Initialize() = 0;
virtual void Update(Time time) = 0;
virtual void Draw() = 0;
virtual void OnGui() = 0;
virtual void ShutDown() = 0;

Create an account

Register a new account

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 21
• 11
• 25