Foundation
Loading...
Searching...
No Matches
ImGui.hpp
Go to the documentation of this file.
1#pragma once
2#include <Bindings/ImGui.hpp>
3
5{
6 const size_t capacity;
7 float mean = 0, m2 = 0;
8 size_t head = 0;
10
12
13
15 {
16 samples.reserve(capacity);
17 };
19 capacity(other.capacity),
20 mean(other.mean),
21 m2(other.m2),
22 head(other.head),
23 allocator(other.allocator),
24 samples(other.allocator),
25 sorted(other.allocator),
26 mode(other.mode),
27 median(other.median),
28 maxCount(other.maxCount)
29 {
30 samples.reserve(capacity);
31 samples.assign(other.samples.begin(), other.samples.end());
32 sorted.assign(other.sorted.begin(), other.sorted.end());
33 }
35
38
39 void push(unsigned data);
40 void clear() { samples.clear(), mean = m2 = .0f, head = 0; }
41
42 float variance() const { return samples.empty() ? 0.0f : m2 / samples.size(); }
43 float stddev() const { return sqrtf(variance()); }
44
46 unsigned mode = 0, median = 0, maxCount = 0;
47 // Side effects: updates sorted, mode, median, maxCount
48 void bin(Vector<unsigned>& bins, size_t binCount, bool logOrLinear /* false/true */);
49};
51{
52 int id;
53
54 size_t startTick;
55 size_t endTick;
56 int lane{-1};
57
59 ImColor color;
60 constexpr bool operator<(const ImProfilerSample& o) const
61 {
62 return Pair{startTick, endTick} < Pair{o.startTick, o.endTick};
63 }
64};
65extern bool ImModalButton(const char* label, int lineIndex = 0, int lineTotal = 1);
66extern void ImFillText(const char* label, ImU32 col = 0xFFFFFFFF, int lineIndex = 0, int lineTotal = 1);
67
69extern void ImProfilerDrawTimestampLabel(Span<const ImProfilerSample> samples, float resolution, int numLabels);
71extern int ImProfilerDrawTable(Span<const ImProfilerSample>, float resolution /* ns = tick * resolution */);
72
73extern void ImProfilerDrawHistogram(Vector<unsigned>& bins, ImProfilerHistogram const& histogram, size_t labelCount,
74 float resolution /* ns = tick * resolution */, bool logOrLinear = true);
75
76extern bool ImBitmaskOptionPicker(unsigned& value, const char** labels, const unsigned* masks, unsigned count, bool solo = false, int columns = 1);
77template <size_t N>
78bool ImBitmaskOptionPicker(unsigned& value, const char* (&labels)[N], const unsigned (&masks)[N], bool solo = false, int columns = 1)
79{
80 return ImBitmaskOptionPicker(value, labels, masks, N, solo, columns);
81}
82template <typename T, typename Mask, size_t N>
83bool ImBitmaskOptionPicker(T& value, const char* (&labels)[N], const Mask (&masks)[N], bool solo = false,
84 int columns = 1)
85{
86 bool any = false;
87 for (unsigned i = 0; i < N; i++)
88 {
89 bool selected = (value & masks[i]) != 0;
90 if (ImGui::Checkbox(labels[i], &selected))
91 {
92 if (selected)
93 {
94 value |= masks[i];
95 if (solo)
96 {
97 for (unsigned j = 0; j < N; j++)
98 {
99 if (j != i)
100 value &= ~masks[j];
101 }
102 }
103 }
104 else
105 value &= ~masks[i];
106 any = true;
107 }
108 if (i != N - 1 && (i + 1) % columns != 0)
109 ImGui::SameLine();
110 }
111 return any;
112}
113float LinearToSRGB(float linear);
114float SRGBToLinear(float srgb);
115float3 LinearToSRGB(float3 linear);
116float3 SRGBToLinear(float3 srgb);
117
118// ColorEdit for scene-linear RGB: shows/edits sRGB display values, writes linear.
119bool ImLinearColorEdit3(const char* label, float3& linearRgb);
120bool ImLinearColorEdit4(const char* label, float4& linearRgba);
121// Chromaticity RGB is display-encoded; power stays linear intensity.
122bool ImHDRColorEdit(const char* label, float3& color, float& power, float maxScale = 100.0f);
123
124// One row (track) drawn by ImTimeline. `muted` only dims the row visually.
126{
127 const char* label = nullptr;
128 bool muted = false;
129};
130
131// One draggable/resizable [start, end) block placed on an ImTimeline row. Callers own the backing
132// data; ImTimeline mutates `start`/`end` directly while a strip is being dragged/resized, the same
133// way ImGui::DragFloat mutates its target in place.
135{
136 int row = 0; // index into the ImTimelineRow span this strip is drawn on
137 float start = 0.0f;
138 float end = 0.0f;
139 ImU32 color = 0;
140 const char* label = nullptr;
141 bool selected = false;
142};
143
144// Per-frame interaction result from ImTimeline, so the caller can react (select, mark dirty, open
145// its own context menu popups, ...) without the widget knowing anything about the caller's data
146// model. ImTimeline never opens a popup itself; it only reports where a right-click landed.
148{
149 int clickedRow = -1; // >= 0 if a row's label area was left-clicked this frame
150 int muteToggledRow = -1; // >= 0 if a row's label was clicked to toggle its mute state this frame
151 int clickedStrip = -1; // >= 0 if a strip was left-clicked and/or is being interacted with
152 bool stripsChanged = false; // true if `clickedStrip`'s start/end was mutated by a drag this frame
153 bool scrubbed = false; // true if the ruler was clicked/dragged, updating `playhead`
154 int rightClickedRow = -1; // >= 0 if a row's label area was right-clicked this frame
155 int rightClickedStrip = -1; // >= 0 if a strip was right-clicked this frame
156 bool rightClickedBackground = false; // true if empty ruler/canvas space was right-clicked
157};
158
159// A horizontal ruler + N rows of draggable/resizable strips (a minimal NLA/sequencer-style track
160// view), laid out as a 2-column table so the row labels never scroll under the strips and the
161// widget never needs its own vertical scrollbar (it's exactly as tall as its rows).
162//
163// `length` sets the timeline extent in caller units (e.g. seconds). `playhead` is scrubbed in place
164// by clicking/dragging the ruler. `pixelsPerSecond`/`scrollX` are zoom/pan state owned by the caller
165// (persist them across frames); hovering the widget scrolls the wheel to zoom (keeping time under
166// the cursor fixed), and Ctrl+wheel pans horizontally instead.
167//
168// Right-clicks are only reported via `ImTimelineResult`, never turned into a popup here: the caller
169// owns what actions make sense for its data (e.g. "Add Strip", "Remove Track") and should respond
170// with its own plain `ImGui::OpenPopup`/`BeginPopup` calls after this returns.
172 float length, float& playhead, float& pixelsPerSecond, float& scrollX);
173
174// Generate linear, monotonous ints of [0, count - 1] at interval of intervalMS
175inline int ImBlink(int intervalMS, int count)
176{
177 size_t time = ImGui::GetTime() * 1000;
178 time = time % (intervalMS * count);
179 return time / intervalMS;
180}
181
182// Generate linear, monotonous float in range of [0, 1] at interval of intervalMS
183inline float ImBlinkF(float intervalMS)
184{
185 float time = ImGui::GetTime();
186 intervalMS /= 1000.0f;
187 time = fmod(time, intervalMS);
188 return time / intervalMS;
189}
190
191// CSS linear easing function on x of range [0,1]
192constexpr inline float ImEaseLinear(float x) { return x; }
193
194// CSS easeInOutCubic easing function on x of range [0,1]
195constexpr inline float ImEaseInOutCubic(float x)
196{
197 return x < 0.5f ? 4 * pow(x, 3.0f) : 1.0f - pow(-2.0f * x + 2.0f, 3.0f) / 2.0f;
198}
199
200using ImEaseFunction = float (*)(float);
float LinearToSRGB(float linear)
Definition ImGui.cpp:548
float(*)(float) ImEaseFunction
Definition ImGui.hpp:200
float SRGBToLinear(float srgb)
Definition ImGui.cpp:554
void ImProfilerDrawHistogram(Vector< unsigned > &bins, ImProfilerHistogram const &histogram, size_t labelCount, float resolution, bool logOrLinear=true)
Definition ImGui.cpp:227
int ImProfilerAssignLanes(Span< ImProfilerSample >, Allocator *)
Definition ImGui.cpp:124
constexpr float ImEaseLinear(float x)
Definition ImGui.hpp:192
int ImBlink(int intervalMS, int count)
Definition ImGui.hpp:175
int ImProfilerDrawTable(Span< const ImProfilerSample >, float resolution)
Definition ImGui.cpp:191
bool ImModalButton(const char *label, int lineIndex=0, int lineTotal=1)
Definition ImGui.cpp:89
float ImBlinkF(float intervalMS)
Definition ImGui.hpp:183
ImTimelineResult ImTimeline(const char *strId, Span< const ImTimelineRow > rows, Span< ImTimelineStrip > strips, float length, float &playhead, float &pixelsPerSecond, float &scrollX)
Definition ImGui.cpp:294
void ImFillText(const char *label, ImU32 col=0xFFFFFFFF, int lineIndex=0, int lineTotal=1)
Definition ImGui.cpp:99
constexpr float ImEaseInOutCubic(float x)
Definition ImGui.hpp:195
void ImProfilerDrawTimestampLabel(Span< const ImProfilerSample > samples, float resolution, int numLabels)
Definition ImGui.cpp:142
int ImProfilerDrawLane(Span< const ImProfilerSample >, int lane)
Definition ImGui.cpp:161
bool ImHDRColorEdit(const char *label, float3 &color, float &power, float maxScale=100.0f)
Definition ImGui.cpp:596
bool ImLinearColorEdit4(const char *label, float4 &linearRgba)
Definition ImGui.cpp:579
bool ImBitmaskOptionPicker(unsigned &value, const char **labels, const unsigned *masks, unsigned count, bool solo=false, int columns=1)
Definition ImGui.cpp:264
bool ImLinearColorEdit3(const char *label, float3 &linearRgb)
Definition ImGui.cpp:570
Allocator interface (noexcept)
Definition Allocator.hpp:29
std::vector< T, StlAllocator< T > > Vector
std::vector with explicit Foundation::Core::StlAllocator constructor
Definition Container.hpp:149
std::pair< First, Second > Pair
Alias for std::pair
Definition Container.hpp:33
std::basic_string< char, std::char_traits< char >, StlDefaultAllocator< char > > String
Alias for std::basic_string<char>, without an explicit allocator constructor.
Definition Container.hpp:120
std::span< T > Span
Alias for std::span
Definition Container.hpp:62
vec3 float3
Definition Math.hpp:26
Definition ImGui.hpp:5
Allocator * allocator
Definition ImGui.hpp:9
void clear()
Definition ImGui.hpp:40
void push(unsigned data)
Definition ImGui.cpp:14
ImProfilerHistogram(ImProfilerHistogram &&other)
Definition ImGui.hpp:34
Vector< unsigned > sorted
Definition ImGui.hpp:45
ImProfilerHistogram & operator=(ImProfilerHistogram const &)=delete
float m2
Definition ImGui.hpp:7
ImProfilerHistogram(size_t capacity, Allocator *alloc)
Definition ImGui.hpp:14
float mean
Definition ImGui.hpp:7
size_t head
Definition ImGui.hpp:8
ImProfilerHistogram(ImProfilerHistogram const &other)
Definition ImGui.hpp:18
ImProfilerHistogram & operator=(ImProfilerHistogram &&)=delete
float stddev() const
Definition ImGui.hpp:43
unsigned mode
Definition ImGui.hpp:46
unsigned maxCount
Definition ImGui.hpp:46
void bin(Vector< unsigned > &bins, size_t binCount, bool logOrLinear)
Definition ImGui.cpp:60
unsigned median
Definition ImGui.hpp:46
Vector< unsigned > samples
Definition ImGui.hpp:11
const size_t capacity
Definition ImGui.hpp:6
float variance() const
Definition ImGui.hpp:42
Definition ImGui.hpp:51
String label
Definition ImGui.hpp:58
int lane
Definition ImGui.hpp:56
size_t endTick
Definition ImGui.hpp:55
size_t startTick
Definition ImGui.hpp:54
constexpr bool operator<(const ImProfilerSample &o) const
Definition ImGui.hpp:60
ImColor color
Definition ImGui.hpp:59
int id
Definition ImGui.hpp:52
Definition ImGui.hpp:148
int muteToggledRow
Definition ImGui.hpp:150
bool rightClickedBackground
Definition ImGui.hpp:156
bool stripsChanged
Definition ImGui.hpp:152
int rightClickedRow
Definition ImGui.hpp:154
int clickedRow
Definition ImGui.hpp:149
int clickedStrip
Definition ImGui.hpp:151
int rightClickedStrip
Definition ImGui.hpp:155
bool scrubbed
Definition ImGui.hpp:153
Definition ImGui.hpp:126
bool muted
Definition ImGui.hpp:128
const char * label
Definition ImGui.hpp:127
Definition ImGui.hpp:135
const char * label
Definition ImGui.hpp:140
int row
Definition ImGui.hpp:136
bool selected
Definition ImGui.hpp:141
ImU32 color
Definition ImGui.hpp:139
float end
Definition ImGui.hpp:138
float start
Definition ImGui.hpp:137