mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-28 05:58:25 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
1 changed files with 784842 additions and 0 deletions
27
Brutal.ImGui/Manual/Structs/ImGuiOnceUponAFrame.cs
Normal file
27
Brutal.ImGui/Manual/Structs/ImGuiOnceUponAFrame.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
namespace Brutal.ImGuiApi;
|
||||
|
||||
/// <summary>Helper: Execute a block of code at maximum once a frame. </summary>
|
||||
/// <remarks>
|
||||
/// Convenient if you want to quickly create a UI within deep-nested code that runs multiple times every frame.<br/>
|
||||
/// Usage: static ImGuiOnceUponAFrame oaf = new(); if (oaf) ImGui.Text("This will be called only once per frame");
|
||||
/// </remarks>
|
||||
/// <source href="https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui.h#L194"><a href="https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui.h#L194">imgui.h:194</a></source>
|
||||
/// <br/>
|
||||
/// <declaration><c>struct ImGuiOnceUponAFrame</c></declaration>
|
||||
// A class, not a struct, so the implicit bool operator mutates the shared instance's _refFrame.
|
||||
public class ImGuiOnceUponAFrame
|
||||
{
|
||||
private int _refFrame = -1;
|
||||
|
||||
public static implicit operator bool(ImGuiOnceUponAFrame value)
|
||||
{
|
||||
var currentFrame = ImGui.GetFrameCount();
|
||||
|
||||
if (value._refFrame == currentFrame)
|
||||
return false;
|
||||
|
||||
value._refFrame = currentFrame;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue