Jump to content
Site Stability Read more... ×
  • Advertisement
Jman2

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
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,

Share this post


Link to post
Share on other sites
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 ...

Edited by Green_Baron
spelling

Share this post


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

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!