MetaImGUI 1.0.0
ImGui Application Template for C++20
Loading...
Searching...
No Matches
DialogManager.h
Go to the documentation of this file.
1/*
2 MetaImGUI
3 Copyright (C) 2026 A P Nicholson
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#include <functional>
22#include <memory>
23#include <string>
24#include <vector>
25
26namespace MetaImGUI {
27
32 OK,
33 OKCancel,
34 YesNo,
37};
38
42enum class MessageBoxIcon {
43 Info,
44 Warning,
45 Error,
47};
48
53
61public:
64
65 // Prevent copying and moving
66 DialogManager(const DialogManager&) = delete;
70
75 void Render();
76
77 // Message Box
86 void ShowMessageBox(const std::string& title, const std::string& message,
88 std::function<void(MessageBoxResult)> callback = nullptr);
89
90 // Input Dialog
98 void ShowInputDialog(const std::string& title, const std::string& prompt, const std::string& defaultValue = "",
99 std::function<void(const std::string&)> callback = nullptr);
100
101 // Progress Dialog
108 int ShowProgressDialog(const std::string& title, const std::string& message = "");
109
116 void UpdateProgress(int dialogId, float progress, const std::string& message = "");
117
122 void CloseProgress(int dialogId);
123
124 // List Selection Dialog
131 void ShowListDialog(const std::string& title, const std::vector<std::string>& items,
132 std::function<void(int)> callback = nullptr);
133
134 // Confirmation Dialog (convenience wrapper)
141 void ShowConfirmation(const std::string& title, const std::string& message,
142 std::function<void(bool)> callback = nullptr);
143
147 [[nodiscard]] bool HasOpenDialog() const;
148
152 void CloseAll();
153
154private:
155 struct Impl;
156 std::unique_ptr<Impl> m_impl;
157
158 void RenderMessageBox();
159 void RenderInputDialog();
160 void RenderProgressDialogs();
161 void RenderListDialog();
162};
163
164} // namespace MetaImGUI
Manager for common UI dialogs.
void CloseProgress(int dialogId)
Close progress dialog.
bool HasOpenDialog() const
Check if any dialog is currently open.
DialogManager & operator=(const DialogManager &)=delete
void ShowInputDialog(const std::string &title, const std::string &prompt, const std::string &defaultValue="", std::function< void(const std::string &)> callback=nullptr)
Show an input dialog.
void CloseAll()
Close all dialogs.
void Render()
Render all active dialogs Call this each frame in your main render loop.
DialogManager(DialogManager &&)=delete
void ShowMessageBox(const std::string &title, const std::string &message, MessageBoxButtons buttons=MessageBoxButtons::OK, MessageBoxIcon icon=MessageBoxIcon::Info, std::function< void(MessageBoxResult)> callback=nullptr)
Show a message box.
DialogManager & operator=(DialogManager &&)=delete
DialogManager(const DialogManager &)=delete
void ShowListDialog(const std::string &title, const std::vector< std::string > &items, std::function< void(int)> callback=nullptr)
Show a list selection dialog.
int ShowProgressDialog(const std::string &title, const std::string &message="")
Show a progress dialog.
void UpdateProgress(int dialogId, float progress, const std::string &message="")
Update progress dialog.
void ShowConfirmation(const std::string &title, const std::string &message, std::function< void(bool)> callback=nullptr)
Show a confirmation dialog (Yes/No)
MessageBoxButtons
Types of message box buttons.
@ OKCancel
OK and Cancel buttons.
@ RetryCancel
Retry and Cancel buttons.
@ YesNoCancel
Yes, No, and Cancel buttons.
@ YesNo
Yes and No buttons.
MessageBoxResult
Result from message box.
MessageBoxIcon
Message box icons/types.
@ Info
Information icon.
@ Question
Question icon.