nv-sgl 0.6.0__cp313-cp313-win_amd64.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. include/tevclient.h +393 -0
  2. nv_sgl-0.6.0.dist-info/LICENSE +29 -0
  3. nv_sgl-0.6.0.dist-info/METADATA +21 -0
  4. nv_sgl-0.6.0.dist-info/RECORD +142 -0
  5. nv_sgl-0.6.0.dist-info/WHEEL +5 -0
  6. nv_sgl-0.6.0.dist-info/top_level.txt +1 -0
  7. sgl/__init__.py +15 -0
  8. sgl/__init__.pyi +6738 -0
  9. sgl/d3d12/D3D12Core.dll +0 -0
  10. sgl/d3d12/d3d12SDKLayers.dll +0 -0
  11. sgl/dxcompiler.dll +0 -0
  12. sgl/dxil.dll +0 -0
  13. sgl/gfx.dll +0 -0
  14. sgl/include/sgl/app/app.h +113 -0
  15. sgl/include/sgl/core/bitmap.h +302 -0
  16. sgl/include/sgl/core/crypto.h +89 -0
  17. sgl/include/sgl/core/data_type.h +46 -0
  18. sgl/include/sgl/core/dds_file.h +103 -0
  19. sgl/include/sgl/core/enum.h +201 -0
  20. sgl/include/sgl/core/error.h +161 -0
  21. sgl/include/sgl/core/file_stream.h +77 -0
  22. sgl/include/sgl/core/file_system_watcher.h +141 -0
  23. sgl/include/sgl/core/format.h +36 -0
  24. sgl/include/sgl/core/fwd.h +90 -0
  25. sgl/include/sgl/core/hash.h +45 -0
  26. sgl/include/sgl/core/input.h +522 -0
  27. sgl/include/sgl/core/logger.h +214 -0
  28. sgl/include/sgl/core/macros.h +184 -0
  29. sgl/include/sgl/core/maths.h +45 -0
  30. sgl/include/sgl/core/memory_mapped_file.h +112 -0
  31. sgl/include/sgl/core/memory_mapped_file_stream.h +32 -0
  32. sgl/include/sgl/core/memory_stream.h +74 -0
  33. sgl/include/sgl/core/object.h +683 -0
  34. sgl/include/sgl/core/platform.h +239 -0
  35. sgl/include/sgl/core/plugin.h +331 -0
  36. sgl/include/sgl/core/resolver.h +39 -0
  37. sgl/include/sgl/core/short_vector.h +141 -0
  38. sgl/include/sgl/core/static_vector.h +111 -0
  39. sgl/include/sgl/core/stream.h +54 -0
  40. sgl/include/sgl/core/string.h +276 -0
  41. sgl/include/sgl/core/struct.h +360 -0
  42. sgl/include/sgl/core/thread.h +28 -0
  43. sgl/include/sgl/core/timer.h +52 -0
  44. sgl/include/sgl/core/traits.h +15 -0
  45. sgl/include/sgl/core/type_utils.h +19 -0
  46. sgl/include/sgl/core/window.h +177 -0
  47. sgl/include/sgl/device/agility_sdk.h +24 -0
  48. sgl/include/sgl/device/blit.h +88 -0
  49. sgl/include/sgl/device/buffer_cursor.h +162 -0
  50. sgl/include/sgl/device/command.h +539 -0
  51. sgl/include/sgl/device/cuda_api.h +766 -0
  52. sgl/include/sgl/device/cuda_interop.h +39 -0
  53. sgl/include/sgl/device/cuda_utils.h +107 -0
  54. sgl/include/sgl/device/cursor_utils.h +129 -0
  55. sgl/include/sgl/device/device.h +668 -0
  56. sgl/include/sgl/device/device_resource.h +37 -0
  57. sgl/include/sgl/device/fence.h +91 -0
  58. sgl/include/sgl/device/formats.h +330 -0
  59. sgl/include/sgl/device/framebuffer.h +85 -0
  60. sgl/include/sgl/device/fwd.h +164 -0
  61. sgl/include/sgl/device/helpers.h +20 -0
  62. sgl/include/sgl/device/hot_reload.h +75 -0
  63. sgl/include/sgl/device/input_layout.h +74 -0
  64. sgl/include/sgl/device/kernel.h +69 -0
  65. sgl/include/sgl/device/memory_heap.h +155 -0
  66. sgl/include/sgl/device/native_formats.h +342 -0
  67. sgl/include/sgl/device/native_handle.h +73 -0
  68. sgl/include/sgl/device/native_handle_traits.h +65 -0
  69. sgl/include/sgl/device/pipeline.h +138 -0
  70. sgl/include/sgl/device/print.h +45 -0
  71. sgl/include/sgl/device/python/cursor_utils.h +853 -0
  72. sgl/include/sgl/device/query.h +52 -0
  73. sgl/include/sgl/device/raytracing.h +84 -0
  74. sgl/include/sgl/device/reflection.h +1254 -0
  75. sgl/include/sgl/device/resource.h +705 -0
  76. sgl/include/sgl/device/sampler.h +57 -0
  77. sgl/include/sgl/device/shader.h +516 -0
  78. sgl/include/sgl/device/shader_cursor.h +85 -0
  79. sgl/include/sgl/device/shader_object.h +94 -0
  80. sgl/include/sgl/device/shader_offset.h +67 -0
  81. sgl/include/sgl/device/shared_handle.h +12 -0
  82. sgl/include/sgl/device/slang_utils.h +54 -0
  83. sgl/include/sgl/device/swapchain.h +74 -0
  84. sgl/include/sgl/device/types.h +782 -0
  85. sgl/include/sgl/math/colorspace.h +56 -0
  86. sgl/include/sgl/math/constants.h +7 -0
  87. sgl/include/sgl/math/float16.h +146 -0
  88. sgl/include/sgl/math/matrix.h +6 -0
  89. sgl/include/sgl/math/matrix_math.h +746 -0
  90. sgl/include/sgl/math/matrix_types.h +207 -0
  91. sgl/include/sgl/math/python/primitivetype.h +33 -0
  92. sgl/include/sgl/math/quaternion.h +6 -0
  93. sgl/include/sgl/math/quaternion_math.h +484 -0
  94. sgl/include/sgl/math/quaternion_types.h +83 -0
  95. sgl/include/sgl/math/ray.h +47 -0
  96. sgl/include/sgl/math/scalar_math.h +249 -0
  97. sgl/include/sgl/math/scalar_types.h +107 -0
  98. sgl/include/sgl/math/vector.h +6 -0
  99. sgl/include/sgl/math/vector_math.h +1796 -0
  100. sgl/include/sgl/math/vector_types.h +336 -0
  101. sgl/include/sgl/python/nanobind.h +489 -0
  102. sgl/include/sgl/python/py_doc.h +11600 -0
  103. sgl/include/sgl/python/sgl_ext_pch.h +8 -0
  104. sgl/include/sgl/sgl.h +21 -0
  105. sgl/include/sgl/sgl_pch.h +6 -0
  106. sgl/include/sgl/stl/bit.h +377 -0
  107. sgl/include/sgl/tests/testing.h +54 -0
  108. sgl/include/sgl/ui/fwd.h +34 -0
  109. sgl/include/sgl/ui/imgui_config.h +43 -0
  110. sgl/include/sgl/ui/ui.h +71 -0
  111. sgl/include/sgl/ui/widgets.h +918 -0
  112. sgl/include/sgl/utils/python/slangpy.h +366 -0
  113. sgl/include/sgl/utils/renderdoc.h +50 -0
  114. sgl/include/sgl/utils/slangpy.h +153 -0
  115. sgl/include/sgl/utils/tev.h +93 -0
  116. sgl/include/sgl/utils/texture_loader.h +106 -0
  117. sgl/math/__init__.pyi +5083 -0
  118. sgl/platform/__init__.pyi +102 -0
  119. sgl/renderdoc/__init__.pyi +51 -0
  120. sgl/sgl.dll +0 -0
  121. sgl/sgl_ext.cp313-win_amd64.pyd +0 -0
  122. sgl/shaders/nvapi/nvHLSLExtns.h +2315 -0
  123. sgl/shaders/nvapi/nvHLSLExtnsInternal.h +758 -0
  124. sgl/shaders/nvapi/nvShaderExtnEnums.h +142 -0
  125. sgl/shaders/sgl/device/blit.slang +93 -0
  126. sgl/shaders/sgl/device/nvapi.slang +5 -0
  127. sgl/shaders/sgl/device/nvapi.slangh +7 -0
  128. sgl/shaders/sgl/device/print.slang +445 -0
  129. sgl/shaders/sgl/math/constants.slang +4 -0
  130. sgl/shaders/sgl/math/ray.slang +29 -0
  131. sgl/shaders/sgl/ui/imgui.slang +49 -0
  132. sgl/slang-glslang.dll +0 -0
  133. sgl/slang-llvm.dll +0 -0
  134. sgl/slang-rt.dll +0 -0
  135. sgl/slang.dll +0 -0
  136. sgl/slangpy/__init__.pyi +268 -0
  137. sgl/tev/__init__.pyi +108 -0
  138. sgl/tevclient.lib +0 -0
  139. sgl/thread/__init__.pyi +4 -0
  140. sgl/ui/__init__.pyi +1118 -0
  141. share/cmake/tevclient/tevclient-config-release.cmake +19 -0
  142. share/cmake/tevclient/tevclient-config.cmake +108 -0
@@ -0,0 +1,918 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+
5
+ #include "sgl/core/object.h"
6
+ #include "sgl/math/vector_types.h"
7
+
8
+ #include <imgui.h>
9
+
10
+ #include <algorithm>
11
+ #include <string_view>
12
+ #include <string>
13
+ #include <functional>
14
+ #include <vector>
15
+
16
+ namespace sgl::ui {
17
+
18
+ class Widget;
19
+
20
+ struct Event {
21
+ Widget* sender;
22
+ };
23
+
24
+ /// Base class for Python UI widgets.
25
+ /// Widgets own their children.
26
+ class Widget : public Object {
27
+ SGL_OBJECT(Widget)
28
+ public:
29
+ Widget(Widget* parent)
30
+ : m_parent(parent)
31
+ {
32
+ if (m_parent)
33
+ m_parent->m_children.push_back(ref<Widget>(this));
34
+ }
35
+
36
+ virtual ~Widget() { }
37
+
38
+ Widget* parent() { return m_parent; }
39
+ const Widget* parent() const { return m_parent; }
40
+ void set_parent(Widget* parent) { m_parent = parent; }
41
+
42
+ const std::vector<ref<Widget>>& children() const { return m_children; }
43
+ size_t child_count() const { return m_children.size(); }
44
+ void clear_children() { m_children.clear(); }
45
+
46
+ int child_index(const Widget* child) const
47
+ {
48
+ auto it = std::find(m_children.begin(), m_children.end(), child);
49
+ return it != m_children.end() ? int(std::distance(m_children.begin(), it)) : -1;
50
+ }
51
+
52
+ ref<Widget> child_at(size_t index) const
53
+ {
54
+ SGL_CHECK(index < m_children.size(), "index out of bounds");
55
+ return m_children[index];
56
+ }
57
+
58
+ void add_child(ref<Widget> child)
59
+ {
60
+ SGL_CHECK_NOT_NULL(child);
61
+ m_children.push_back(child);
62
+ child->set_parent(this);
63
+ }
64
+
65
+ void add_child_at(ref<Widget> child, size_t index)
66
+ {
67
+ SGL_CHECK_NOT_NULL(child);
68
+ SGL_CHECK(index == 0 || index < m_children.size(), "index out of bounds");
69
+ m_children.insert(m_children.begin() + index, child);
70
+ child->set_parent(this);
71
+ }
72
+
73
+ void remove_child(ref<Widget> child)
74
+ {
75
+ auto it = std::find(m_children.begin(), m_children.end(), child);
76
+ SGL_CHECK(it != m_children.end(), "child widget not found");
77
+ m_children.erase(it);
78
+ child->set_parent(nullptr);
79
+ }
80
+
81
+ void remove_child_at(size_t index)
82
+ {
83
+ SGL_CHECK(index < m_children.size(), "index out of bounds");
84
+ auto child = m_children[index];
85
+ m_children.erase(m_children.begin() + index);
86
+ child->set_parent(nullptr);
87
+ }
88
+
89
+ void remove_all_children()
90
+ {
91
+ for (auto& child : m_children)
92
+ child->set_parent(nullptr);
93
+ m_children.clear();
94
+ }
95
+
96
+ bool visible() const { return m_visible; }
97
+ void set_visible(bool visible) { m_visible = visible; }
98
+
99
+ bool enabled() const { return m_enabled; }
100
+ void set_enabled(bool enabled) { m_enabled = enabled; }
101
+
102
+ virtual void render()
103
+ {
104
+ if (!m_visible)
105
+ return;
106
+
107
+ for (const auto& child : m_children)
108
+ child->render();
109
+ }
110
+
111
+ virtual void record_event(const Event& event)
112
+ {
113
+ if (m_parent)
114
+ m_parent->record_event(event);
115
+ }
116
+
117
+ virtual void dispatch_event(const Event& event) { SGL_UNUSED(event); }
118
+
119
+ protected:
120
+ Widget* m_parent;
121
+ std::vector<ref<Widget>> m_children;
122
+ bool m_visible{true};
123
+ bool m_enabled{true};
124
+ };
125
+
126
+ /// This is the main widget that represents the screen.
127
+ /// It is intended to be used as the parent for \c Window widgets.
128
+ class Screen : public Widget {
129
+ SGL_OBJECT(Screen)
130
+ public:
131
+ Screen()
132
+ : Widget(nullptr)
133
+ {
134
+ }
135
+
136
+ virtual void render() override { Widget::render(); }
137
+
138
+ virtual void record_event(const Event& event) override { m_events.push_back(event); }
139
+
140
+ void dispatch_events()
141
+ {
142
+ for (const auto& event : m_events)
143
+ event.sender->dispatch_event(event);
144
+ m_events.clear();
145
+ }
146
+
147
+ private:
148
+ std::vector<Event> m_events;
149
+ };
150
+
151
+ /// Scoped push/pop of ImGui ID.
152
+ class ScopedID {
153
+ public:
154
+ ScopedID(void* id) { ImGui::PushID(id); }
155
+ ~ScopedID() { ImGui::PopID(); }
156
+ };
157
+
158
+ /// Scoped begin/end for disabling ImGUI widgets.
159
+ class ScopedDisable {
160
+ public:
161
+ ScopedDisable(bool disabled)
162
+ : m_disabled(disabled)
163
+ {
164
+ if (disabled)
165
+ ImGui::BeginDisabled();
166
+ }
167
+ ~ScopedDisable()
168
+ {
169
+ if (m_disabled)
170
+ ImGui::EndDisabled();
171
+ }
172
+
173
+ private:
174
+ bool m_disabled;
175
+ };
176
+
177
+ class Window : public Widget {
178
+ SGL_OBJECT(Window)
179
+ public:
180
+ Window(
181
+ Widget* parent,
182
+ std::string_view title = "",
183
+ float2 position = float2(10.f, 10.f),
184
+ float2 size = float2(400.f, 400.f)
185
+ )
186
+ : Widget(parent)
187
+ , m_title(title)
188
+ , m_position(position)
189
+ , m_size(size)
190
+ {
191
+ }
192
+
193
+ const std::string& title() const { return m_title; }
194
+ void set_title(std::string_view title) { m_title = title; }
195
+
196
+ float2 position() const { return m_position; }
197
+ void set_position(const float2& position)
198
+ {
199
+ m_position = position;
200
+ m_set_position = true;
201
+ }
202
+
203
+ float2 size() const { return m_size; }
204
+ void set_size(const float2& size)
205
+ {
206
+ m_size = size;
207
+ m_set_size = true;
208
+ }
209
+
210
+ void show() { set_visible(true); }
211
+ void close() { set_visible(false); }
212
+
213
+ virtual void render() override
214
+ {
215
+ if (!m_visible)
216
+ return;
217
+
218
+ if (m_set_position) {
219
+ ImGui::SetNextWindowPos(ImVec2(m_position.x, m_position.y));
220
+ m_set_position = false;
221
+ }
222
+ if (m_set_size) {
223
+ ImGui::SetNextWindowSize(ImVec2(m_size.x, m_size.y));
224
+ m_set_size = false;
225
+ }
226
+
227
+ ScopedID id(this);
228
+ if (ImGui::Begin(m_title.c_str(), &m_visible)) {
229
+ auto pos = ImGui::GetWindowPos();
230
+ m_position = float2(pos.x, pos.y);
231
+ auto size = ImGui::GetWindowSize();
232
+ m_size = float2(size.x, size.y);
233
+
234
+ ImGui::PushItemWidth(300);
235
+ Widget::render();
236
+ ImGui::PopItemWidth();
237
+ }
238
+ ImGui::End();
239
+ }
240
+
241
+ private:
242
+ std::string m_title;
243
+ float2 m_position;
244
+ float2 m_size;
245
+ bool m_set_position{true};
246
+ bool m_set_size{true};
247
+ };
248
+
249
+ class Group : public Widget {
250
+ SGL_OBJECT(Group)
251
+ public:
252
+ Group(Widget* parent, std::string_view label = "")
253
+ : Widget(parent)
254
+ , m_label(label)
255
+ {
256
+ }
257
+
258
+ const std::string& label() const { return m_label; }
259
+ void set_label(std::string_view label) { m_label = label; }
260
+
261
+ virtual void render() override
262
+ {
263
+ if (!m_visible)
264
+ return;
265
+
266
+ // Check if this is a nested group
267
+ bool nested = false;
268
+ for (Widget* p = parent(); p != nullptr; p = p->parent())
269
+ if (dynamic_cast<Group*>(p) != nullptr)
270
+ nested = true;
271
+
272
+ ScopedID id(this);
273
+ ScopedDisable disable(!m_enabled);
274
+
275
+ if (nested ? ImGui::TreeNodeEx(m_label.c_str(), ImGuiTreeNodeFlags_DefaultOpen)
276
+ : ImGui::CollapsingHeader(m_label.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) {
277
+ Widget::render();
278
+ if (nested)
279
+ ImGui::TreePop();
280
+ }
281
+ }
282
+
283
+ private:
284
+ std::string m_label;
285
+ };
286
+
287
+ class Text : public Widget {
288
+ SGL_OBJECT(Text)
289
+ public:
290
+ Text(Widget* parent, std::string_view text = "")
291
+ : Widget(parent)
292
+ , m_text(text)
293
+ {
294
+ }
295
+
296
+ const std::string& text() const { return m_text; }
297
+ void set_text(std::string_view text) { m_text = text; }
298
+
299
+ virtual void render() override
300
+ {
301
+ if (!m_visible)
302
+ return;
303
+
304
+ ScopedID id(this);
305
+ ScopedDisable disable(!m_enabled);
306
+ ImGui::TextUnformatted(m_text.c_str());
307
+ }
308
+
309
+ private:
310
+ std::string m_text;
311
+ };
312
+
313
+ class ProgressBar : public Widget {
314
+ SGL_OBJECT(ProgressBar)
315
+ public:
316
+ ProgressBar(Widget* parent, float fraction = 0.f)
317
+ : Widget(parent)
318
+ , m_fraction(fraction)
319
+ {
320
+ }
321
+
322
+ float fraction() const { return m_fraction; }
323
+ void set_fraction(float fraction) { m_fraction = fraction; }
324
+
325
+ virtual void render() override
326
+ {
327
+ if (!m_visible)
328
+ return;
329
+
330
+ ScopedID id(this);
331
+ ScopedDisable disable(!m_enabled);
332
+ ImGui::ProgressBar(m_fraction);
333
+ }
334
+
335
+ private:
336
+ float m_fraction;
337
+ };
338
+
339
+ class Button : public Widget {
340
+ SGL_OBJECT(Button)
341
+ public:
342
+ using Callback = std::function<void()>;
343
+
344
+ Button(Widget* parent, std::string_view label = "", Callback callback = {})
345
+ : Widget(parent)
346
+ , m_label(label)
347
+ , m_callback(callback)
348
+ {
349
+ }
350
+
351
+ const std::string& label() const { return m_label; }
352
+ void set_label(std::string_view label) { m_label = label; }
353
+
354
+ Callback callback() const { return m_callback; }
355
+ void set_callback(Callback callback) { m_callback = callback; }
356
+
357
+ virtual void render() override
358
+ {
359
+ if (!m_visible)
360
+ return;
361
+
362
+ ScopedID id(this);
363
+ ScopedDisable disable(!m_enabled);
364
+ if (ImGui::Button(m_label.c_str()))
365
+ record_event({this});
366
+ }
367
+
368
+ virtual void dispatch_event(const Event& event) override
369
+ {
370
+ SGL_ASSERT(event.sender == this);
371
+ if (m_callback)
372
+ m_callback();
373
+ }
374
+
375
+ private:
376
+ std::string m_label;
377
+ Callback m_callback;
378
+ };
379
+
380
+ template<typename T>
381
+ class ValueProperty : public Widget {
382
+ public:
383
+ using value_type = T;
384
+ using Callback = std::function<void(const value_type&)>;
385
+
386
+ ValueProperty(Widget* parent, std::string_view label, value_type value, Callback callback)
387
+ : Widget(parent)
388
+ , m_label(label)
389
+ , m_value(value)
390
+ , m_callback(callback)
391
+ {
392
+ }
393
+
394
+ const std::string& label() const { return m_label; }
395
+ void set_label(std::string_view label) { m_label = label; }
396
+
397
+ const value_type& value() const { return m_value; }
398
+ void set_value(const value_type& value) { m_value = value; }
399
+
400
+ Callback callback() const { return m_callback; }
401
+ void set_callback(Callback callback) { m_callback = callback; }
402
+
403
+ virtual void dispatch_event(const Event& event) override
404
+ {
405
+ SGL_ASSERT(event.sender == this);
406
+ if (m_callback)
407
+ m_callback(m_value);
408
+ }
409
+
410
+ protected:
411
+ std::string m_label;
412
+ value_type m_value;
413
+ Callback m_callback;
414
+ };
415
+
416
+ class CheckBox : public ValueProperty<bool> {
417
+ SGL_OBJECT(CheckBox)
418
+ public:
419
+ using Base = ValueProperty<bool>;
420
+
421
+ CheckBox(Widget* parent, std::string_view label = "", bool value = false, Callback callback = {})
422
+ : Base(parent, label, value, callback)
423
+ {
424
+ }
425
+
426
+ virtual void render() override
427
+ {
428
+ if (!m_visible)
429
+ return;
430
+
431
+ ScopedID id(this);
432
+ ScopedDisable disable(!m_enabled);
433
+ if (ImGui::Checkbox(m_label.c_str(), &m_value))
434
+ record_event({this});
435
+ }
436
+ };
437
+
438
+ class ComboBox : public ValueProperty<int> {
439
+ SGL_OBJECT(ComboBox)
440
+ public:
441
+ using Base = ValueProperty<int>;
442
+
443
+ ComboBox(
444
+ Widget* parent,
445
+ std::string_view label = "",
446
+ int value = 0,
447
+ Callback callback = {},
448
+ std::vector<std::string> items = {}
449
+ )
450
+ : Base(parent, label, value, callback)
451
+ , m_items(items)
452
+ {
453
+ }
454
+
455
+ const std::vector<std::string>& items() const { return m_items; }
456
+ void set_items(const std::vector<std::string>& items) { m_items = items; }
457
+
458
+ virtual void render() override
459
+ {
460
+ if (!m_visible)
461
+ return;
462
+
463
+ ScopedID id(this);
464
+ ScopedDisable disable(!m_enabled);
465
+ if (ImGui::Combo(
466
+ m_label.c_str(),
467
+ &m_value,
468
+ [](void* data, int idx, const char** out_text) -> bool
469
+ {
470
+ auto& items = *reinterpret_cast<std::vector<std::string>*>(data);
471
+ if (idx < 0 || idx >= items.size())
472
+ return false;
473
+ *out_text = items[idx].c_str();
474
+ return true;
475
+ },
476
+ &m_items,
477
+ (int)m_items.size()
478
+ )) {
479
+ record_event({this});
480
+ }
481
+ }
482
+
483
+ private:
484
+ std::vector<std::string> m_items;
485
+ };
486
+
487
+ class ListBox : public ValueProperty<int> {
488
+ SGL_OBJECT(ListBox)
489
+ public:
490
+ using Base = ValueProperty<int>;
491
+
492
+ ListBox(
493
+ Widget* parent,
494
+ std::string_view label = "",
495
+ int value = 0,
496
+ Callback callback = {},
497
+ std::vector<std::string> items = {},
498
+ int height_in_items = -1
499
+ )
500
+ : Base(parent, label, value, callback)
501
+ , m_items(items)
502
+ , m_height_in_items(height_in_items)
503
+ {
504
+ }
505
+
506
+ const std::vector<std::string>& items() const { return m_items; }
507
+ void set_items(const std::vector<std::string>& items) { m_items = items; }
508
+
509
+ int height_in_items() const { return m_height_in_items; }
510
+ void set_height_in_items(int height_in_items) { m_height_in_items = height_in_items; }
511
+
512
+ virtual void render() override
513
+ {
514
+ if (!m_visible)
515
+ return;
516
+
517
+ ScopedID id(this);
518
+ ScopedDisable disable(!m_enabled);
519
+ if (ImGui::ListBox(
520
+ m_label.c_str(),
521
+ &m_value,
522
+ [](void* user_data, int idx) { return static_cast<const ListBox*>(user_data)->m_items[idx].c_str(); },
523
+ this,
524
+ int(m_items.size()),
525
+ m_height_in_items
526
+ )) {
527
+ record_event({this});
528
+ }
529
+ }
530
+
531
+ private:
532
+ std::vector<std::string> m_items;
533
+ int m_height_in_items;
534
+ };
535
+
536
+ enum class SliderFlags {
537
+ none = ImGuiSliderFlags_None,
538
+ always_clamp = ImGuiSliderFlags_AlwaysClamp,
539
+ logarithmic = ImGuiSliderFlags_Logarithmic,
540
+ no_round_to_format = ImGuiSliderFlags_NoRoundToFormat,
541
+ no_input = ImGuiSliderFlags_NoInput,
542
+ };
543
+
544
+ SGL_ENUM_CLASS_OPERATORS(SliderFlags);
545
+
546
+ template<typename T>
547
+ struct DataTypeTraits { };
548
+
549
+ // clang-format off
550
+ template<> struct DataTypeTraits<float> { static constexpr ImGuiDataType data_type{ImGuiDataType_Float}; static constexpr const char* default_format = "%.3f"; };
551
+ template<> struct DataTypeTraits<int> { static constexpr ImGuiDataType data_type{ImGuiDataType_S32}; static constexpr const char* default_format = "%d"; };
552
+ // clang-format on
553
+
554
+
555
+ template<typename T>
556
+ struct VectorTraits { };
557
+
558
+ // clang-format off
559
+ template<> struct VectorTraits<float> { using scalar_type = float; static constexpr int N = 1; };
560
+ template<> struct VectorTraits<float2> { using scalar_type = float; static constexpr int N = 2; };
561
+ template<> struct VectorTraits<float3> { using scalar_type = float; static constexpr int N = 3; };
562
+ template<> struct VectorTraits<float4> { using scalar_type = float; static constexpr int N = 4; };
563
+ template<> struct VectorTraits<int> { using scalar_type = int; static constexpr int N = 1; };
564
+ template<> struct VectorTraits<int2> { using scalar_type = int; static constexpr int N = 2; };
565
+ template<> struct VectorTraits<int3> { using scalar_type = int; static constexpr int N = 3; };
566
+ template<> struct VectorTraits<int4> { using scalar_type = int; static constexpr int N = 4; };
567
+ // clang-format on
568
+
569
+ template<typename T>
570
+ class Drag : public ValueProperty<T> {
571
+ SGL_OBJECT(Drag)
572
+ public:
573
+ using Base = ValueProperty<T>;
574
+ using typename Base::value_type;
575
+ using typename Base::Callback;
576
+
577
+ using Widget::record_event;
578
+ using Widget::m_enabled;
579
+ using Widget::m_visible;
580
+ using Base::m_label;
581
+ using Base::m_value;
582
+
583
+ using scalar_type = typename VectorTraits<T>::scalar_type;
584
+ static constexpr int N = VectorTraits<T>::N;
585
+ static constexpr const char* default_format = DataTypeTraits<scalar_type>::default_format;
586
+
587
+ Drag(
588
+ Widget* parent,
589
+ std::string_view label = "",
590
+ value_type value = value_type(0),
591
+ Callback callback = {},
592
+ float speed = 1.f,
593
+ scalar_type min = scalar_type(0),
594
+ scalar_type max = scalar_type(0),
595
+ std::string_view format = default_format,
596
+ SliderFlags flags = SliderFlags::none
597
+ )
598
+ : Base(parent, label, value, callback)
599
+ , m_speed(speed)
600
+ , m_min(min)
601
+ , m_max(max)
602
+ , m_format(format)
603
+ , m_flags(flags)
604
+ {
605
+ }
606
+
607
+ scalar_type speed() const { return static_cast<scalar_type>(m_speed); }
608
+ void set_speed(scalar_type speed) { m_speed = static_cast<float>(speed); }
609
+
610
+ scalar_type min() const { return m_min; }
611
+ void set_min(scalar_type min) { m_min = min; }
612
+
613
+ scalar_type max() const { return m_max; }
614
+ void set_max(scalar_type max) { m_max = max; }
615
+
616
+ const std::string& format() const { return m_format; }
617
+ void set_format(std::string_view format) { m_format = format; }
618
+
619
+ SliderFlags flags() const { return m_flags; }
620
+ void set_flags(SliderFlags flags) { m_flags = flags; }
621
+
622
+ virtual void render() override
623
+ {
624
+ if (!m_visible)
625
+ return;
626
+
627
+ ScopedID id(this);
628
+ ScopedDisable disable(!m_enabled);
629
+ bool changed = ImGui::DragScalarN(
630
+ m_label.c_str(),
631
+ DataTypeTraits<scalar_type>::data_type,
632
+ &m_value,
633
+ N,
634
+ m_speed,
635
+ &m_min,
636
+ &m_max,
637
+ m_format.c_str(),
638
+ ImGuiSliderFlags(m_flags)
639
+ );
640
+ if (changed)
641
+ record_event({this});
642
+ }
643
+
644
+ private:
645
+ float m_speed;
646
+ scalar_type m_min;
647
+ scalar_type m_max;
648
+ std::string m_format;
649
+ SliderFlags m_flags;
650
+ };
651
+
652
+ using DragFloat = Drag<float>;
653
+ using DragFloat2 = Drag<float2>;
654
+ using DragFloat3 = Drag<float3>;
655
+ using DragFloat4 = Drag<float4>;
656
+ using DragInt = Drag<int>;
657
+ using DragInt2 = Drag<int2>;
658
+ using DragInt3 = Drag<int3>;
659
+ using DragInt4 = Drag<int4>;
660
+
661
+ template<typename T>
662
+ class Slider : public ValueProperty<T> {
663
+ SGL_OBJECT(Slider)
664
+ public:
665
+ using Base = ValueProperty<T>;
666
+ using typename Base::value_type;
667
+ using typename Base::Callback;
668
+
669
+ using Widget::record_event;
670
+ using Widget::m_enabled;
671
+ using Widget::m_visible;
672
+ using Base::m_label;
673
+ using Base::m_value;
674
+
675
+ using scalar_type = typename VectorTraits<T>::scalar_type;
676
+ static constexpr int N = VectorTraits<T>::N;
677
+ static constexpr const char* default_format = DataTypeTraits<scalar_type>::default_format;
678
+
679
+ Slider(
680
+ Widget* parent,
681
+ std::string_view label = "",
682
+ value_type value = value_type(0),
683
+ Callback callback = {},
684
+ scalar_type min = scalar_type(0),
685
+ scalar_type max = scalar_type(0),
686
+ std::string_view format = default_format,
687
+ SliderFlags flags = SliderFlags::none
688
+ )
689
+ : Base(parent, label, value, callback)
690
+ , m_min(min)
691
+ , m_max(max)
692
+ , m_format(format)
693
+ , m_flags(flags)
694
+ {
695
+ }
696
+
697
+ scalar_type min() const { return m_min; }
698
+ void set_min(scalar_type min) { m_min = min; }
699
+
700
+ scalar_type max() const { return m_max; }
701
+ void set_max(scalar_type max) { m_max = max; }
702
+
703
+ const std::string& format() const { return m_format; }
704
+ void set_format(std::string_view format) { m_format = format; }
705
+
706
+ SliderFlags flags() const { return m_flags; }
707
+ void set_flags(SliderFlags flags) { m_flags = flags; }
708
+
709
+ virtual void render() override
710
+ {
711
+ if (!m_visible)
712
+ return;
713
+
714
+ ScopedID id(this);
715
+ ScopedDisable disable(!m_enabled);
716
+ bool changed = ImGui::SliderScalarN(
717
+ m_label.c_str(),
718
+ DataTypeTraits<scalar_type>::data_type,
719
+ &m_value,
720
+ N,
721
+ &m_min,
722
+ &m_max,
723
+ m_format.c_str(),
724
+ ImGuiSliderFlags(m_flags)
725
+ );
726
+ if (changed)
727
+ record_event({this});
728
+ }
729
+
730
+ private:
731
+ scalar_type m_min;
732
+ scalar_type m_max;
733
+ std::string m_format;
734
+ SliderFlags m_flags;
735
+ };
736
+
737
+ using SliderFloat = Slider<float>;
738
+ using SliderFloat2 = Slider<float2>;
739
+ using SliderFloat3 = Slider<float3>;
740
+ using SliderFloat4 = Slider<float4>;
741
+ using SliderInt = Slider<int>;
742
+ using SliderInt2 = Slider<int2>;
743
+ using SliderInt3 = Slider<int3>;
744
+ using SliderInt4 = Slider<int4>;
745
+
746
+ enum class InputTextFlags {
747
+ none = ImGuiInputTextFlags_None,
748
+ chars_decimal = ImGuiInputTextFlags_CharsDecimal,
749
+ chars_hexadecimal = ImGuiInputTextFlags_CharsHexadecimal,
750
+ chars_uppercase = ImGuiInputTextFlags_CharsUppercase,
751
+ chars_no_blank = ImGuiInputTextFlags_CharsNoBlank,
752
+ auto_select_all = ImGuiInputTextFlags_AutoSelectAll,
753
+ enter_returns_true = ImGuiInputTextFlags_EnterReturnsTrue,
754
+ callback_completion = ImGuiInputTextFlags_CallbackCompletion,
755
+ callback_history = ImGuiInputTextFlags_CallbackHistory,
756
+ callback_always = ImGuiInputTextFlags_CallbackAlways,
757
+ callback_char_filter = ImGuiInputTextFlags_CallbackCharFilter,
758
+ allow_tab_input = ImGuiInputTextFlags_AllowTabInput,
759
+ ctrl_enter_for_new_line = ImGuiInputTextFlags_CtrlEnterForNewLine,
760
+ no_horizontal_scroll = ImGuiInputTextFlags_NoHorizontalScroll,
761
+ always_overwrite = ImGuiInputTextFlags_AlwaysOverwrite,
762
+ read_only = ImGuiInputTextFlags_ReadOnly,
763
+ password = ImGuiInputTextFlags_Password,
764
+ no_undo_redo = ImGuiInputTextFlags_NoUndoRedo,
765
+ chars_scientific = ImGuiInputTextFlags_CharsScientific,
766
+ escape_clears_all = ImGuiInputTextFlags_EscapeClearsAll,
767
+ };
768
+
769
+ SGL_ENUM_CLASS_OPERATORS(InputTextFlags);
770
+
771
+ template<typename T>
772
+ class Input : public ValueProperty<T> {
773
+ SGL_OBJECT(Input)
774
+ public:
775
+ using Base = ValueProperty<T>;
776
+ using typename Base::value_type;
777
+ using typename Base::Callback;
778
+
779
+ using Widget::record_event;
780
+ using Widget::m_enabled;
781
+ using Widget::m_visible;
782
+ using Base::m_label;
783
+ using Base::m_value;
784
+
785
+ using scalar_type = typename VectorTraits<T>::scalar_type;
786
+ static constexpr int N = VectorTraits<T>::N;
787
+ static constexpr const char* default_format = DataTypeTraits<scalar_type>::default_format;
788
+
789
+ Input(
790
+ Widget* parent,
791
+ std::string_view label = "",
792
+ value_type value = value_type(0),
793
+ Callback callback = {},
794
+ scalar_type step = scalar_type(1),
795
+ scalar_type step_fast = scalar_type(100),
796
+ std::string_view format = default_format,
797
+ InputTextFlags flags = InputTextFlags::none
798
+ )
799
+ : Base(parent, label, value, callback)
800
+ , m_step(step)
801
+ , m_step_fast(step_fast)
802
+ , m_format(format)
803
+ , m_flags(flags)
804
+ {
805
+ }
806
+
807
+ scalar_type step() const { return m_step; }
808
+ void set_step(scalar_type step) { m_step = step; }
809
+
810
+ scalar_type step_fast() const { return m_step_fast; }
811
+ void set_step_fast(scalar_type step_fast) { m_step_fast = step_fast; }
812
+
813
+ const std::string& format() const { return m_format; }
814
+ void set_format(std::string_view format) { m_format = format; }
815
+
816
+ InputTextFlags flags() const { return m_flags; }
817
+ void set_flags(InputTextFlags flags) { m_flags = flags; }
818
+
819
+ virtual void render() override
820
+ {
821
+ if (!m_visible)
822
+ return;
823
+
824
+ ScopedID id(this);
825
+ ScopedDisable disable(!m_enabled);
826
+ bool changed = ImGui::InputScalarN(
827
+ m_label.c_str(),
828
+ DataTypeTraits<scalar_type>::data_type,
829
+ &m_value,
830
+ N,
831
+ &m_step,
832
+ &m_step_fast,
833
+ m_format.c_str(),
834
+ ImGuiInputTextFlags(m_flags)
835
+ );
836
+ if (changed)
837
+ record_event({this});
838
+ }
839
+
840
+ private:
841
+ scalar_type m_step;
842
+ scalar_type m_step_fast;
843
+ std::string m_format;
844
+ InputTextFlags m_flags;
845
+ };
846
+
847
+ using InputFloat = Input<float>;
848
+ using InputFloat2 = Input<float2>;
849
+ using InputFloat3 = Input<float3>;
850
+ using InputFloat4 = Input<float4>;
851
+ using InputInt = Input<int>;
852
+ using InputInt2 = Input<int2>;
853
+ using InputInt3 = Input<int3>;
854
+ using InputInt4 = Input<int4>;
855
+
856
+ class InputText : public ValueProperty<std::string> {
857
+ SGL_OBJECT(InputText)
858
+ public:
859
+ using Base = ValueProperty<std::string>;
860
+
861
+ InputText(
862
+ Widget* parent,
863
+ std::string_view label = "",
864
+ std::string value = "",
865
+ Callback callback = {},
866
+ bool multi_line = false,
867
+ InputTextFlags flags = InputTextFlags::none
868
+ )
869
+ : Base(parent, label, value, callback)
870
+ , m_multi_line(multi_line)
871
+ , m_flags(flags)
872
+ {
873
+ }
874
+
875
+ virtual void render() override
876
+ {
877
+ if (!m_visible)
878
+ return;
879
+
880
+ auto text_callback = [](ImGuiInputTextCallbackData* data)
881
+ {
882
+ auto self = static_cast<InputText*>(data->UserData);
883
+ if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) {
884
+ self->m_value.resize(data->BufTextLen);
885
+ data->Buf = self->m_value.data();
886
+ }
887
+ return 0;
888
+ };
889
+
890
+ ImGuiInputTextFlags flags = ImGuiInputTextFlags(m_flags) | ImGuiInputTextFlags_CallbackResize;
891
+
892
+ ScopedID id(this);
893
+ ScopedDisable disable(!m_enabled);
894
+ bool changed = false;
895
+ if (m_multi_line) {
896
+ changed = ImGui::InputTextMultiline(
897
+ m_label.c_str(),
898
+ m_value.data(),
899
+ m_value.capacity() + 1,
900
+ ImVec2(0, 0),
901
+ flags,
902
+ text_callback,
903
+ this
904
+ );
905
+ } else {
906
+ changed
907
+ = ImGui::InputText(m_label.c_str(), m_value.data(), m_value.capacity() + 1, flags, text_callback, this);
908
+ }
909
+ if (changed)
910
+ record_event({this});
911
+ }
912
+
913
+ private:
914
+ bool m_multi_line;
915
+ InputTextFlags m_flags;
916
+ };
917
+
918
+ } // namespace sgl::ui