Removed IMGUI_ONCE_UPON_A_FRAME in favor of ImGuiOnceUponAFrame which is supported by all compilers

This commit is contained in:
omar 2014-11-26 22:16:38 +00:00
parent 7f6453ca70
commit b9118750ae
2 changed files with 49 additions and 45 deletions

View File

@ -142,7 +142,7 @@
e.g. "##Foobar" display an empty label and uses "##Foobar" as ID e.g. "##Foobar" display an empty label and uses "##Foobar" as ID
- read articles about the imgui principles (see web links) to understand the requirement and use of ID. - read articles about the imgui principles (see web links) to understand the requirement and use of ID.
- tip: the construct 'if (IMGUI_ONCE_UPON_A_FRAME)' will evaluate to true only once a frame, you can use it to add custom UI in the middle of a deep nested inner loop in your code. - tip: the construct 'static ImGuiOnceUponAFrame once; if (once)' will evaluate to 'true' only once a frame, you can use it to quickly add custom UI in the middle of a deep nested inner loop in your code.
- tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function. - tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function.
- tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug" - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"
- tip: read the ShowTestWindow() code for more example of how to use ImGui! - tip: read the ShowTestWindow() code for more example of how to use ImGui!
@ -6674,6 +6674,10 @@ void ImGui::ShowTestWindow(bool* open)
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
//static ImGuiOnceUponAFrame oaf;
//if (oaf) ImGui::Text("This will be displayed.");
//if (oaf) ImGui::Text("This won't be displayed!");
ImGui::Separator(); ImGui::Separator();
ImGui::Text("^ Horizontal separator"); ImGui::Text("^ Horizontal separator");

18
imgui.h
View File

@ -123,7 +123,7 @@ public:
#endif // #ifndef ImVector #endif // #ifndef ImVector
// Helpers at bottom of the file: // Helpers at bottom of the file:
// - if (IMGUI_ONCE_UPON_A_FRAME) // Execute a block of code once per frame only // - struct ImGuiOnceUponAFrame // Execute a block of code once per frame only (convenient for creating UI within deep-nested code that runs multiple times)
// - struct ImGuiTextFilter // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" // - struct ImGuiTextFilter // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
// - struct ImGuiTextBuffer // Text buffer for logging/accumulating text // - struct ImGuiTextBuffer // Text buffer for logging/accumulating text
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually) // - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
@ -529,15 +529,15 @@ struct ImGuiIO
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Helper: execute a block of code once a frame only // Helper: execute a block of code once a frame only
// Usage: if (IMGUI_ONCE_UPON_A_FRAME) {/*do something once a frame*/) // Convenient if you want to quickly create an UI within deep-nested code that runs multiple times every frame.
#define IMGUI_ONCE_UPON_A_FRAME static ImGuiOncePerFrame im = ImGuiOncePerFrame() // Usage:
struct ImGuiOncePerFrame // static ImGuiOnceUponAFrame once;
// if (once) { ... }
struct ImGuiOnceUponAFrame
{ {
ImGuiOncePerFrame() : LastFrame(-1) {} ImGuiOnceUponAFrame() { RefFrame = -1; }
operator bool() const { return TryIsNewFrame(); } mutable int RefFrame;
private: operator bool() const { const int current_frame = ImGui::GetFrameCount(); if (RefFrame == current_frame) return false; RefFrame = current_frame; return true; }
mutable int LastFrame;
bool TryIsNewFrame() const { const int current_frame = ImGui::GetFrameCount(); if (LastFrame == current_frame) return false; LastFrame = current_frame; return true; }
}; };
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"