mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 07:01:04 +01:00 
			
		
		
		
	Examples: Tweaked the main.cpp example structure for all examples. (There are a few hidden agendas here: 1) I would like to avoid encouraging people from using the implicit "Debug" window, and promote using Begin/End. In spite of my best attempt, there are a few feature of the upcoming docking system that cannot work 100% properly for the implicit Debug window, so future proof let's not put that feature in the spotlight too much for new users. 2) Moved dumb hardcoded positions into a single spot that can be replaced with a viewport relative position and not affect other demo windows. 3) Calling ShowDemoWindow before anything else, also for the benefit of a specific docking demo which will have an ordering constraint which is not really problematic in a real app but shouldn't be put forward in the demo.
This commit is contained in:
		@@ -40,6 +40,7 @@
 | 
			
		||||
 | 
			
		||||
-(void)updateAndDrawDemoView
 | 
			
		||||
{
 | 
			
		||||
    // Start the Dear ImGui frame
 | 
			
		||||
	ImGui_ImplOpenGL2_NewFrame();
 | 
			
		||||
	ImGui_ImplOSX_NewFrame(self);
 | 
			
		||||
    ImGui::NewFrame();
 | 
			
		||||
@@ -49,42 +50,42 @@
 | 
			
		||||
    static bool show_another_window = false;
 | 
			
		||||
    static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
 | 
			
		||||
 | 
			
		||||
	// 1. Show a simple window.
 | 
			
		||||
	// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
 | 
			
		||||
	{
 | 
			
		||||
		static float f = 0.0f;
 | 
			
		||||
		static int counter = 0;
 | 
			
		||||
		ImGui::Text("Hello, world!");                           // Display some text (you can use a format string too)
 | 
			
		||||
		ImGui::SliderFloat("float", &f, 0.0f, 1.0f);            // Edit 1 float using a slider from 0.0f to 1.0f
 | 
			
		||||
		ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
 | 
			
		||||
    // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
 | 
			
		||||
    if (show_demo_window)
 | 
			
		||||
        ImGui::ShowDemoWindow(&show_demo_window);
 | 
			
		||||
 | 
			
		||||
		ImGui::Checkbox("Demo Window", &show_demo_window);      // Edit bools storing our windows open/close state
 | 
			
		||||
		ImGui::Checkbox("Another Window", &show_another_window);
 | 
			
		||||
    // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
 | 
			
		||||
    {
 | 
			
		||||
        static float f = 0.0f;
 | 
			
		||||
        static int counter = 0;
 | 
			
		||||
 | 
			
		||||
		if (ImGui::Button("Button"))                            // Buttons return true when clicked (NB: most widgets return true when edited/activated)
 | 
			
		||||
			counter++;
 | 
			
		||||
		ImGui::SameLine();
 | 
			
		||||
		ImGui::Text("counter = %d", counter);
 | 
			
		||||
        ImGui::Begin("Hello, world!");                          // Create a window called "Hello, world!" and append into it.
 | 
			
		||||
 | 
			
		||||
		ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
 | 
			
		||||
	}
 | 
			
		||||
        ImGui::Text("This is some useful text.");               // Display some text (you can use a format strings too)
 | 
			
		||||
        ImGui::Checkbox("Demo Window", &show_demo_window);      // Edit bools storing our window open/close state
 | 
			
		||||
        ImGui::Checkbox("Another Window", &show_another_window);
 | 
			
		||||
 | 
			
		||||
	// 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows.
 | 
			
		||||
	if (show_another_window)
 | 
			
		||||
	{
 | 
			
		||||
		ImGui::Begin("Another Window", &show_another_window);
 | 
			
		||||
		ImGui::Text("Hello from another window!");
 | 
			
		||||
		if (ImGui::Button("Close Me"))
 | 
			
		||||
			show_another_window = false;
 | 
			
		||||
		ImGui::End();
 | 
			
		||||
	}
 | 
			
		||||
        ImGui::SliderFloat("float", &f, 0.0f, 1.0f);            // Edit 1 float using a slider from 0.0f to 1.0f    
 | 
			
		||||
        ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
 | 
			
		||||
 | 
			
		||||
	// 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). Read its code to learn more about Dear ImGui!
 | 
			
		||||
	if (show_demo_window)
 | 
			
		||||
	{
 | 
			
		||||
		ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
 | 
			
		||||
		ImGui::ShowDemoWindow(&show_demo_window);
 | 
			
		||||
	}
 | 
			
		||||
        if (ImGui::Button("Button"))                            // Buttons return true when clicked (most widgets return true when edited/activated)
 | 
			
		||||
            counter++;
 | 
			
		||||
        ImGui::SameLine();
 | 
			
		||||
        ImGui::Text("counter = %d", counter);
 | 
			
		||||
 | 
			
		||||
        ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
 | 
			
		||||
        ImGui::End();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 3. Show another simple window.
 | 
			
		||||
    if (show_another_window)
 | 
			
		||||
    {
 | 
			
		||||
        ImGui::Begin("Another Window", &show_another_window);   // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
 | 
			
		||||
        ImGui::Text("Hello from another window!");
 | 
			
		||||
        if (ImGui::Button("Close Me"))
 | 
			
		||||
            show_another_window = false;
 | 
			
		||||
        ImGui::End();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	// Rendering
 | 
			
		||||
	ImGui::Render();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user