Skip to main content

MainMenuWidget Class

Main menu bar providing access to application settings. More...

Declaration

class helios::ext::imgui::widgets::MainMenuWidget { ... }

Base class

classImGuiWidget

Abstract base class for ImGui widgets rendered in debug overlays. More...

Public Constructors Index

MainMenuWidget ()

Default constructor, registers settings handler with ImGui. More...

Public Destructor Index

~MainMenuWidget () override

Public Member Functions Index

voidsetDockingCallback (std::function< void(bool)> callback)

Sets a callback for when docking is enabled/disabled. More...

voidsetWindowAlpha (float alpha)

Sets the window transparency level. More...

floatwindowAlpha () const noexcept

Returns the current window transparency level. More...

boolisDockingEnabled () const noexcept

Returns whether docking is enabled. More...

voiddraw () override

Renders the main menu bar. More...

Private Member Functions Index

voidapplyTransparency ()

Applies the current transparency settings to ImGui style. More...

voidregisterSettingsHandler ()

Registers the ImGui settings handler for persistence. More...

Private Member Attributes Index

floatwindowAlpha_ = 0.85f

Window background transparency (0.0 - 1.0). More...

floatchildAlpha_ = 0.0f

Child window background transparency. More...

boolshowDemoWindow_ = false

Whether to show the ImGui demo window. More...

boolshowStyleEditor_ = false

Whether to show the style editor. More...

booldockingEnabled_ = true

Whether docking is enabled. More...

boolfirstDraw_ = true

Whether this is the first draw call (for initial setup). More...

boolhandlerRegistered_ = false

Whether the settings handler has been registered. More...

std::function< void(bool)>onDockingChanged_

Callback when docking setting changes. More...

Private Static Attributes Index

static MainMenuWidget *instance_ = nullptr

Static pointer to the current instance (for ImGui callbacks). More...

Description

Main menu bar providing access to application settings.

This widget renders a menu bar at the top of the viewport with options for:

  • View settings (window transparency, docking)
  • Debug tools (show/hide log console, demo window)
  • Style presets

Settings are automatically saved to and loaded from ImGui's imgui.ini file.

Definition at line 31 of file MainMenuWidget.ixx.

Public Constructors

MainMenuWidget()

helios::ext::imgui::widgets::MainMenuWidget::MainMenuWidget ()
inline

Default constructor, registers settings handler with ImGui.

Definition at line 136 of file MainMenuWidget.ixx.

137 registerSettingsHandler();
138 }

Public Destructor

~MainMenuWidget()

helios::ext::imgui::widgets::MainMenuWidget::~MainMenuWidget ()
inline

Definition at line 140 of file MainMenuWidget.ixx.

140 ~MainMenuWidget() override {
141 if (instance_ == this) {
142 instance_ = nullptr;
143 }
144 }

Public Member Functions

draw()

void helios::ext::imgui::widgets::MainMenuWidget::draw ()
inline virtual

Renders the main menu bar.

Definition at line 183 of file MainMenuWidget.ixx.

183 void draw() override {
184 // Apply settings on first draw
185 if (firstDraw_) {
186 applyTransparency();
187 if (onDockingChanged_) {
188 onDockingChanged_(dockingEnabled_);
189 }
190 firstDraw_ = false;
191 }
192
193 if (ImGui::BeginMainMenuBar()) {
194
195 // === View Menu ===
196 if (ImGui::BeginMenu("View")) {
197
198 // Transparency settings
199 if (ImGui::BeginMenu("Transparency")) {
200 if (ImGui::SliderFloat("Window", &windowAlpha_, 0.3f, 1.0f, "%.2f")) {
201 applyTransparency();
202 ImGui::MarkIniSettingsDirty();
203 }
204 if (ImGui::SliderFloat("Child Areas", &childAlpha_, 0.0f, 1.0f, "%.2f")) {
205 applyTransparency();
206 ImGui::MarkIniSettingsDirty();
207 }
208
209 ImGui::Separator();
210
211 // Presets
212 if (ImGui::MenuItem("Solid")) {
213 windowAlpha_ = 1.0f;
214 childAlpha_ = 0.0f;
215 applyTransparency();
216 ImGui::MarkIniSettingsDirty();
217 }
218 if (ImGui::MenuItem("Semi-Transparent")) {
219 windowAlpha_ = 0.85f;
220 childAlpha_ = 0.0f;
221 applyTransparency();
222 ImGui::MarkIniSettingsDirty();
223 }
224 if (ImGui::MenuItem("Transparent")) {
225 windowAlpha_ = 0.6f;
226 childAlpha_ = 0.0f;
227 applyTransparency();
228 ImGui::MarkIniSettingsDirty();
229 }
230 if (ImGui::MenuItem("Glass")) {
231 windowAlpha_ = 0.4f;
232 childAlpha_ = 0.2f;
233 applyTransparency();
234 ImGui::MarkIniSettingsDirty();
235 }
236
237 ImGui::EndMenu();
238 }
239
240 // Docking toggle
241 if (ImGui::MenuItem("Docking", nullptr, &dockingEnabled_)) {
242 if (onDockingChanged_) {
243 onDockingChanged_(dockingEnabled_);
244 }
245 ImGui::MarkIniSettingsDirty();
246 }
247
248 ImGui::EndMenu();
249 }
250
251 // === Style Menu ===
252 if (ImGui::BeginMenu("Style")) {
253 if (ImGui::MenuItem("Dark")) {
254 ImGui::StyleColorsDark();
255 applyTransparency();
256 }
257 if (ImGui::MenuItem("Light")) {
258 ImGui::StyleColorsLight();
259 applyTransparency();
260 }
261 if (ImGui::MenuItem("Classic")) {
262 ImGui::StyleColorsClassic();
263 applyTransparency();
264 }
265
266 ImGui::Separator();
267
268 ImGui::MenuItem("Style Editor...", nullptr, &showStyleEditor_);
269
270 ImGui::EndMenu();
271 }
272
273 // === Debug Menu ===
274 if (ImGui::BeginMenu("Debug")) {
275 ImGui::MenuItem("ImGui Demo Window", nullptr, &showDemoWindow_);
276 ImGui::EndMenu();
277 }
278
279 ImGui::EndMainMenuBar();
280 }
281
282 // Render optional windows
283 if (showDemoWindow_) {
284 ImGui::ShowDemoWindow(&showDemoWindow_);
285 }
286
287 if (showStyleEditor_) {
288 if (ImGui::Begin("Style Editor", &showStyleEditor_)) {
289 ImGui::ShowStyleEditor();
290 }
291 ImGui::End();
292 }
293 }

isDockingEnabled()

bool helios::ext::imgui::widgets::MainMenuWidget::isDockingEnabled ()
inline nodiscard noexcept

Returns whether docking is enabled.

Definition at line 176 of file MainMenuWidget.ixx.

176 [[nodiscard]] bool isDockingEnabled() const noexcept {
177 return dockingEnabled_;
178 }

setDockingCallback()

void helios::ext::imgui::widgets::MainMenuWidget::setDockingCallback (std::function< void(bool)> callback)
inline

Sets a callback for when docking is enabled/disabled.

Parameters
callback

Function called with the new docking state.

Definition at line 151 of file MainMenuWidget.ixx.

151 void setDockingCallback(std::function<void(bool)> callback) {
152 onDockingChanged_ = std::move(callback);
153 }

setWindowAlpha()

void helios::ext::imgui::widgets::MainMenuWidget::setWindowAlpha (float alpha)
inline

Sets the window transparency level.

Parameters
alpha

Transparency value (0.0 = transparent, 1.0 = opaque).

Definition at line 160 of file MainMenuWidget.ixx.

160 void setWindowAlpha(float alpha) {
161 windowAlpha_ = alpha;
162 applyTransparency();
163 ImGui::MarkIniSettingsDirty();
164 }

windowAlpha()

float helios::ext::imgui::widgets::MainMenuWidget::windowAlpha ()
inline nodiscard noexcept

Returns the current window transparency level.

Definition at line 169 of file MainMenuWidget.ixx.

169 [[nodiscard]] float windowAlpha() const noexcept {
170 return windowAlpha_;
171 }

Private Member Functions

applyTransparency()

void helios::ext::imgui::widgets::MainMenuWidget::applyTransparency ()
inline

Applies the current transparency settings to ImGui style.

Definition at line 82 of file MainMenuWidget.ixx.

82 void applyTransparency() {
83 ImGuiStyle& style = ImGui::GetStyle();
84 style.Colors[ImGuiCol_WindowBg].w = windowAlpha_;
85 style.Colors[ImGuiCol_ChildBg].w = childAlpha_;
86 style.Colors[ImGuiCol_PopupBg].w = std::min(windowAlpha_ + 0.05f, 1.0f);
87 style.Colors[ImGuiCol_TitleBg].w = std::min(windowAlpha_ + 0.05f, 1.0f);
88 style.Colors[ImGuiCol_TitleBgActive].w = std::min(windowAlpha_ + 0.1f, 1.0f);
89 }

registerSettingsHandler()

void helios::ext::imgui::widgets::MainMenuWidget::registerSettingsHandler ()
inline

Registers the ImGui settings handler for persistence.

Definition at line 94 of file MainMenuWidget.ixx.

94 void registerSettingsHandler() {
95 if (handlerRegistered_) return;
96
97 instance_ = this;
98
99 ImGuiSettingsHandler handler;
100 handler.TypeName = "HeliosUserSettings";
101 handler.TypeHash = ImHashStr("HeliosUserSettings");
102 handler.ClearAllFn = nullptr;
103 handler.ReadOpenFn = [](ImGuiContext*, ImGuiSettingsHandler*, const char* name) -> void* {
104 return (std::strcmp(name, "Main") == 0) ? instance_ : nullptr;
105 };
106 handler.ReadLineFn = [](ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line) {
107 auto* widget = static_cast<MainMenuWidget*>(entry);
108 float f;
109 int i;
110 if (std::sscanf(line, "WindowAlpha=%f", &f) == 1) { widget->windowAlpha_ = f; }
111 else if (std::sscanf(line, "ChildAlpha=%f", &f) == 1) { widget->childAlpha_ = f; }
112 else if (std::sscanf(line, "DockingEnabled=%d", &i) == 1) { widget->dockingEnabled_ = (i != 0); }
113 };
114 handler.ApplyAllFn = [](ImGuiContext*, ImGuiSettingsHandler*) {
115 if (instance_) {
116 instance_->applyTransparency();
117 }
118 };
119 handler.WriteAllFn = [](ImGuiContext*, ImGuiSettingsHandler* h, ImGuiTextBuffer* buf) {
120 if (!instance_) return;
121 buf->appendf("[%s][Main]\n", h->TypeName);
122 buf->appendf("WindowAlpha=%.3f\n", instance_->windowAlpha_);
123 buf->appendf("ChildAlpha=%.3f\n", instance_->childAlpha_);
124 buf->appendf("DockingEnabled=%d\n", instance_->dockingEnabled_ ? 1 : 0);
125 buf->append("\n");
126 };
127
128 ImGui::GetCurrentContext()->SettingsHandlers.push_back(handler);
129 handlerRegistered_ = true;
130 }

Private Member Attributes

childAlpha_

float helios::ext::imgui::widgets::MainMenuWidget::childAlpha_ = 0.0f

Child window background transparency.

Definition at line 42 of file MainMenuWidget.ixx.

42 float childAlpha_ = 0.0f;

dockingEnabled_

bool helios::ext::imgui::widgets::MainMenuWidget::dockingEnabled_ = true

Whether docking is enabled.

Definition at line 57 of file MainMenuWidget.ixx.

57 bool dockingEnabled_ = true;

firstDraw_

bool helios::ext::imgui::widgets::MainMenuWidget::firstDraw_ = true

Whether this is the first draw call (for initial setup).

Definition at line 62 of file MainMenuWidget.ixx.

62 bool firstDraw_ = true;

handlerRegistered_

bool helios::ext::imgui::widgets::MainMenuWidget::handlerRegistered_ = false

Whether the settings handler has been registered.

Definition at line 67 of file MainMenuWidget.ixx.

67 bool handlerRegistered_ = false;

onDockingChanged_

std::function<void(bool)> helios::ext::imgui::widgets::MainMenuWidget::onDockingChanged_

Callback when docking setting changes.

Definition at line 72 of file MainMenuWidget.ixx.

72 std::function<void(bool)> onDockingChanged_;

showDemoWindow_

bool helios::ext::imgui::widgets::MainMenuWidget::showDemoWindow_ = false

Whether to show the ImGui demo window.

Definition at line 47 of file MainMenuWidget.ixx.

47 bool showDemoWindow_ = false;

showStyleEditor_

bool helios::ext::imgui::widgets::MainMenuWidget::showStyleEditor_ = false

Whether to show the style editor.

Definition at line 52 of file MainMenuWidget.ixx.

52 bool showStyleEditor_ = false;

windowAlpha_

float helios::ext::imgui::widgets::MainMenuWidget::windowAlpha_ = 0.85f

Window background transparency (0.0 - 1.0).

Definition at line 37 of file MainMenuWidget.ixx.

37 float windowAlpha_ = 0.85f;

Private Static Attributes

instance_

MainMenuWidget* helios::ext::imgui::widgets::MainMenuWidget::instance_ = nullptr
static

Static pointer to the current instance (for ImGui callbacks).

Definition at line 77 of file MainMenuWidget.ixx.

77 static inline MainMenuWidget* instance_ = nullptr;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.