🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Dear ImGui State Management

Started by
2 comments, last by Jman2 4 years, 9 months ago

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
if (ImGui::BeginMainMenuBar())
	{
		if (ImGui::BeginMenu("File"))
		{
			if (ImGui::MenuItem("New"))
			{
				m_FileDialog.Open("New Project");
                m_UIState = UIState::New_File_Dialog;
			}
			ImGui::EndMenu();
		}

		if (ImGui::BeginMenu("Build"))
		{
			if (ImGui::MenuItem("Build"))
			{
				m_UIState = UIState::Build_Dialog;
			}

			ImGui::EndMenu();
		}

		ImGui::EndMainMenuBar();
  
  // 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,

Advertisement
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 ...

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 LoadContent() = 0;
	virtual void Update(Time time) = 0;
	virtual void Draw() = 0;
	virtual void OnGui() = 0;
	virtual void ShutDown() = 0;

 

This topic is closed to new replies.

Advertisement