Dynamic Neural Field Composer 0.0.0
A C++20 library and interactive application for building and simulating Dynamic Neural Field (DNF) architectures.
Loading...
Searching...
No Matches
application.h
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4//#if defined(_WIN32)
5#include <imgui-platform-kit/user_interface.h>
6//#elif defined(__linux__)
7//#endif
8
12
13#define IMGUI_ENABLE_FREETYPE
15
18
19namespace dnf_composer
20{
21 // Base template: assumes T does not have a constructor that takes Simulation*
22 template<typename T, typename = void>
23 struct has_simulation_constructor : std::false_type {};
24
25 // Specialization for types that take a Simulation*
26 template<typename T>
28 std::void_t<decltype(T(std::declval<std::shared_ptr<Simulation>>()))>> : std::true_type {};
29
30 // Base template: assumes T does not have a constructor that takes Visualization*
31 template<typename T, typename = void>
32 struct has_visualization_constructor : std::false_type {};
33
34 // Specialization for types that take a Visualization*
35 template<typename T>
37 std::void_t<decltype(T(std::declval<std::shared_ptr<Visualization>>()))>> : std::true_type {};
38
55 {
56 private:
57 std::shared_ptr<Simulation> simulation;
58 std::shared_ptr<Visualization> visualization;
59 std::shared_ptr<imgui_kit::UserInterface> gui;
60 bool guiActive;
61 static float uiScalePct;
62
63 public:
64 static float getUiScalePct() { return uiScalePct; }
65 static void setUiScalePct(float pct) { uiScalePct = pct; }
66
70 explicit Application(const std::shared_ptr<Simulation>& simulation = nullptr,
71 const std::shared_ptr<Visualization>& visualization = nullptr);
72
74 void init() const;
75
77 void step() const;
78
80 void close() const;
81
83 static void registerSettingsHandler();
84
86 template<typename WindowType, typename... Args>
87 void addWindow(Args&&... args) const requires (!has_simulation_constructor<WindowType>::value &&
89 gui->addWindow<WindowType>(std::forward<Args>(args)...);
90 }
91
93 template<typename WindowType, typename... Args>
94 void addWindow(Args&&... args) const requires has_simulation_constructor<WindowType>::value {
95 gui->addWindow<WindowType>(simulation, std::forward<Args>(args)...);
96 }
97
99 template<typename WindowType, typename... Args>
100 void addWindow(Args&&... args) const requires (!has_simulation_constructor<WindowType>::value&&
102 gui->addWindow<WindowType>(visualization, std::forward<Args>(args)...);
103 }
104
106 void toggleGUI();
107
109 [[nodiscard]] bool hasGUIBeenClosed() const;
110
112 [[nodiscard]] bool isGUIActive() const;
113
114 ~Application() = default;
115 private:
116 void setGUIParameters();
117 static void enableKeyboardShortcuts();
118 static void appendFonts();
119 static void defineImGuiStyle();
120 };
121
122 // Text fonts — 3 sizes per weight
123 inline ImFont* g_LightMediumFont;
124 inline ImFont* g_LightSmallFont;
125 inline ImFont* g_LightLargeFont;
126
127 inline ImFont* g_MediumSmallFont;
128 inline ImFont* g_MediumMediumFont;
129 inline ImFont* g_MediumLargeFont;
130
131 inline ImFont* g_BoldSmallFont;
132 inline ImFont* g_BoldMediumFont;
133 inline ImFont* g_BoldLargeFont;
134
135 inline ImFont* g_BlackSmallFont;
136 inline ImFont* g_BlackMediumFont;
137 inline ImFont* g_BlackLargeFont;
138
139 inline ImFont* g_MonoSmallFont;
140 inline ImFont* g_MonoMediumFont;
141 inline ImFont* g_MonoLargeFont;
142
143 inline constexpr size_t g_FontCount = 15;
144 inline ImFont* g_SmallIconsFont;
145 inline ImFont* g_MediumIconsFont;
146 inline ImFont* g_LargeIconsFont;
147}
Top-level application that owns the GUI, simulation, and visualization.
Definition application.h:55
void step() const
Advance the simulation by one step and render all windows.
Definition application.cpp:75
static void registerSettingsHandler()
Register the application's ImGui settings handler (for persistence).
Definition application.cpp:43
bool isGUIActive() const
Return true if the GUI overlay is currently active.
Definition application.cpp:108
bool hasGUIBeenClosed() const
Return true if the user has closed the main window.
Definition application.cpp:100
void addWindow(Args &&... args) const
Register a window that needs no Simulation or Visualization pointer.
Definition application.h:87
static void setUiScalePct(float pct)
Definition application.h:65
static float getUiScalePct()
Definition application.h:64
void toggleGUI()
Toggle the GUI on or off at runtime.
Definition application.cpp:94
void init() const
Initialize the GUI and all registered windows. Call once before step().
Definition application.cpp:27
void close() const
Tear down the GUI and close the simulation. Call once after the main loop.
Definition application.cpp:85
void addWindow(Args &&... args) const
Register a window that takes a Simulation shared_ptr as the first argument.
Definition application.h:94
Definition application.h:20
ImFont * g_MonoMediumFont
JetBrainsMono.
Definition application.h:140
ImFont * g_LargeIconsFont
Font Awesome.
Definition application.h:146
ImFont * g_LightLargeFont
Cera Pro Light.
Definition application.h:125
ImFont * g_MonoLargeFont
JetBrainsMono.
Definition application.h:141
ImFont * g_BlackMediumFont
Cera Pro Black.
Definition application.h:136
ImFont * g_MonoSmallFont
JetBrainsMono.
Definition application.h:139
ImFont * g_MediumIconsFont
Font Awesome.
Definition application.h:145
ImFont * g_SmallIconsFont
Font Awesome.
Definition application.h:144
ImFont * g_BoldMediumFont
Cera Pro Bold.
Definition application.h:132
ImFont * g_BoldLargeFont
Cera Pro Bold.
Definition application.h:133
ImFont * g_BlackSmallFont
Cera Pro Black.
Definition application.h:135
ImFont * g_LightMediumFont
Cera Pro Light.
Definition application.h:123
ImFont * g_BlackLargeFont
Cera Pro Black.
Definition application.h:137
ImFont * g_LightSmallFont
Cera Pro Light.
Definition application.h:124
constexpr size_t g_FontCount
Number of text font variants (icon fonts not counted).
Definition application.h:143
ImFont * g_MediumMediumFont
Cera Pro Medium (main font)
Definition application.h:128
ImFont * g_MediumLargeFont
Cera Pro Medium.
Definition application.h:129
ImFont * g_MediumSmallFont
Cera Pro Medium.
Definition application.h:127
ImFont * g_BoldSmallFont
Cera Pro Bold.
Definition application.h:131
Definition application.h:23