ImGui main menu bar widget with application settings. More...
#include <functional>
#include <string>
#include <cstring>
#include <cstdio>
#include "imgui.h"
#include "imgui_internal.h"
#include <
helios.ext.imgui.ImGuiWidget>
Namespaces Index
| namespace | helios |
|
|
|
| namespace | ext |
|
Platform-specific extensions and backend implementations. More...
|
|
| namespace | imgui |
|
|
|
| namespace | widgets |
|
Debug and developer widgets for ImGui overlays. More...
|
|
Classes Index
Description
ImGui main menu bar widget with application settings.
File Listing
The file content with the documentation metadata removed is:
12#include "imgui_internal.h"
14export module helios.ext.imgui.widgets.MainMenuWidget;
16import helios.ext.imgui.ImGuiWidget;
37 float windowAlpha_ = 0.85f;
42 float childAlpha_ = 0.0f;
47 bool showDemoWindow_ = false;
52 bool showStyleEditor_ = false;
57 bool dockingEnabled_ = true;
62 bool firstDraw_ = true;
67 bool handlerRegistered_ = false;
72 std::function<void(bool)> onDockingChanged_;
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);
94 void registerSettingsHandler() {
95 if (handlerRegistered_) return;
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;
106 handler.ReadLineFn = [](ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line) {
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); }
114 handler.ApplyAllFn = [](ImGuiContext*, ImGuiSettingsHandler*) {
116 instance_->applyTransparency();
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);
128 ImGui::GetCurrentContext()->SettingsHandlers.push_back(handler);
129 handlerRegistered_ = true;
137 registerSettingsHandler();
141 if (instance_ == this) {
152 onDockingChanged_ = std::move(callback);
161 windowAlpha_ = alpha;
163 ImGui::MarkIniSettingsDirty();
177 return dockingEnabled_;
187 if (onDockingChanged_) {
188 onDockingChanged_(dockingEnabled_);
193 if (ImGui::BeginMainMenuBar()) {
196 if (ImGui::BeginMenu("View")) {
199 if (ImGui::BeginMenu("Transparency")) {
200 if (ImGui::SliderFloat("Window", &windowAlpha_, 0.3f, 1.0f, "%.2f")) {
202 ImGui::MarkIniSettingsDirty();
204 if (ImGui::SliderFloat("Child Areas", &childAlpha_, 0.0f, 1.0f, "%.2f")) {
206 ImGui::MarkIniSettingsDirty();
212 if (ImGui::MenuItem("Solid")) {
216 ImGui::MarkIniSettingsDirty();
218 if (ImGui::MenuItem("Semi-Transparent")) {
219 windowAlpha_ = 0.85f;
222 ImGui::MarkIniSettingsDirty();
224 if (ImGui::MenuItem("Transparent")) {
228 ImGui::MarkIniSettingsDirty();
230 if (ImGui::MenuItem("Glass")) {
234 ImGui::MarkIniSettingsDirty();
241 if (ImGui::MenuItem("Docking", nullptr, &dockingEnabled_)) {
242 if (onDockingChanged_) {
243 onDockingChanged_(dockingEnabled_);
245 ImGui::MarkIniSettingsDirty();
252 if (ImGui::BeginMenu("Style")) {
253 if (ImGui::MenuItem("Dark")) {
254 ImGui::StyleColorsDark();
257 if (ImGui::MenuItem("Light")) {
258 ImGui::StyleColorsLight();
261 if (ImGui::MenuItem("Classic")) {
262 ImGui::StyleColorsClassic();
268 ImGui::MenuItem("Style Editor...", nullptr, &showStyleEditor_);
274 if (ImGui::BeginMenu("Debug")) {
275 ImGui::MenuItem("ImGui Demo Window", nullptr, &showDemoWindow_);
279 ImGui::EndMainMenuBar();
283 if (showDemoWindow_) {
284 ImGui::ShowDemoWindow(&showDemoWindow_);
287 if (showStyleEditor_) {
288 if (ImGui::Begin("Style Editor", &showStyleEditor_)) {
289 ImGui::ShowStyleEditor();
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.