yaze
0.3.2
Link to the Past ROM Editor
Loading...
Searching...
No Matches
canvas_popup.cc
Go to the documentation of this file.
1
#include "
canvas_popup.h
"
2
3
#include <algorithm>
4
5
namespace
yaze
{
6
namespace
gui {
7
8
void
PopupRegistry::Open
(
const
std::string& popup_id,
9
std::function<
void
()> render_callback) {
10
// Check if popup already exists
11
auto
it =
FindPopup
(popup_id);
12
13
if
(it !=
popups_
.end()) {
14
// Update existing popup
15
it->is_open =
true
;
16
it->render_callback = std::move(render_callback);
17
ImGui::OpenPopup(popup_id.c_str());
18
return
;
19
}
20
21
// Add new popup
22
PopupState
new_popup;
23
new_popup.
popup_id
= popup_id;
24
new_popup.
is_open
=
true
;
25
new_popup.
render_callback
= std::move(render_callback);
26
new_popup.
persist
=
true
;
27
28
popups_
.push_back(new_popup);
29
30
// Open the popup in ImGui
31
ImGui::OpenPopup(popup_id.c_str());
32
}
33
34
void
PopupRegistry::Close
(
const
std::string& popup_id) {
35
auto
it =
FindPopup
(popup_id);
36
37
if
(it !=
popups_
.end()) {
38
it->is_open =
false
;
39
40
// Close in ImGui if it's the current popup
41
// Note: ImGui::CloseCurrentPopup() only works if this is the active popup
42
// In practice, the popup will be removed on next RenderAll() call
43
if
(ImGui::IsPopupOpen(popup_id.c_str())) {
44
ImGui::CloseCurrentPopup();
45
}
46
}
47
}
48
49
bool
PopupRegistry::IsOpen
(
const
std::string& popup_id)
const
{
50
auto
it =
FindPopup
(popup_id);
51
return
it !=
popups_
.end() && it->is_open;
52
}
53
54
void
PopupRegistry::RenderAll
() {
55
// Render all active popups
56
auto
it =
popups_
.begin();
57
while
(it !=
popups_
.end()) {
58
if
(it->is_open && it->render_callback) {
59
// Call the render callback which should handle BeginPopup/EndPopup
60
it->render_callback();
61
62
// Check if popup was closed by user (clicking outside, pressing Escape, etc.)
63
if
(!ImGui::IsPopupOpen(it->popup_id.c_str())) {
64
it->is_open =
false
;
65
}
66
}
67
68
// Remove closed popups from the registry
69
if
(!it->is_open) {
70
it =
popups_
.erase(it);
71
}
else
{
72
++it;
73
}
74
}
75
}
76
77
size_t
PopupRegistry::GetActiveCount
()
const
{
78
return
std::count_if(
popups_
.begin(),
popups_
.end(),
79
[](
const
PopupState
& popup) { return popup.is_open; });
80
}
81
82
void
PopupRegistry::Clear
() {
83
// Close all popups
84
for
(
auto
& popup :
popups_
) {
85
if
(popup.is_open && ImGui::IsPopupOpen(popup.popup_id.c_str())) {
86
ImGui::CloseCurrentPopup();
87
}
88
popup.is_open =
false
;
89
}
90
91
// Clear the registry
92
popups_
.clear();
93
}
94
95
std::vector<PopupState>::iterator
PopupRegistry::FindPopup
(
96
const
std::string& popup_id) {
97
return
std::find_if(
popups_
.begin(),
popups_
.end(),
98
[&popup_id](
const
PopupState
& popup) {
99
return popup.popup_id == popup_id;
100
});
101
}
102
103
std::vector<PopupState>::const_iterator
PopupRegistry::FindPopup
(
104
const
std::string& popup_id)
const
{
105
return
std::find_if(
popups_
.begin(),
popups_
.end(),
106
[&popup_id](
const
PopupState
& popup) {
107
return popup.popup_id == popup_id;
108
});
109
}
110
111
}
// namespace gui
112
}
// namespace yaze
113
canvas_popup.h
yaze::gui::PopupRegistry::Close
void Close(const std::string &popup_id)
Close a persistent popup.
Definition
canvas_popup.cc:34
yaze::gui::PopupRegistry::GetActiveCount
size_t GetActiveCount() const
Get the number of active popups.
Definition
canvas_popup.cc:77
yaze::gui::PopupRegistry::RenderAll
void RenderAll()
Render all active popups.
Definition
canvas_popup.cc:54
yaze::gui::PopupRegistry::Clear
void Clear()
Clear all popups from the registry.
Definition
canvas_popup.cc:82
yaze::gui::PopupRegistry::popups_
std::vector< PopupState > popups_
Definition
canvas_popup.h:119
yaze::gui::PopupRegistry::IsOpen
bool IsOpen(const std::string &popup_id) const
Check if a popup is currently open.
Definition
canvas_popup.cc:49
yaze::gui::PopupRegistry::FindPopup
std::vector< PopupState >::iterator FindPopup(const std::string &popup_id)
Definition
canvas_popup.cc:95
yaze::gui::PopupRegistry::Open
void Open(const std::string &popup_id, std::function< void()> render_callback)
Open a persistent popup.
Definition
canvas_popup.cc:8
yaze
Main namespace for the application.
Definition
controller.cc:20
yaze::gui::PopupState
State for a single persistent popup.
Definition
canvas_popup.h:19
yaze::gui::PopupState::is_open
bool is_open
Definition
canvas_popup.h:24
yaze::gui::PopupState::persist
bool persist
Definition
canvas_popup.h:31
yaze::gui::PopupState::popup_id
std::string popup_id
Definition
canvas_popup.h:21
yaze::gui::PopupState::render_callback
std::function< void()> render_callback
Definition
canvas_popup.h:28
src
app
gui
canvas
canvas_popup.cc
Generated by
1.9.8