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