yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
panel_host.cc
Go to the documentation of this file.
2
4#include "imgui/imgui.h"
5
6namespace yaze {
7namespace editor {
8
10 PanelDescriptor descriptor;
11 descriptor.card_id = definition.id;
12 descriptor.display_name = definition.display_name;
13 descriptor.icon = definition.icon;
14 descriptor.category = definition.category;
15 descriptor.window_title = definition.window_title;
16 descriptor.shortcut_hint = definition.shortcut_hint;
17 descriptor.priority = definition.priority;
18 descriptor.scope = definition.scope;
19 descriptor.panel_category = definition.panel_category;
20 descriptor.context_scope = definition.context_scope;
21 descriptor.on_show = definition.on_show;
22 descriptor.on_hide = definition.on_hide;
23 descriptor.visibility_flag = definition.visibility_flag;
24 return descriptor;
25}
26
27bool PanelHost::RegisterPanel(size_t session_id,
28 const PanelDefinition& definition) {
29 if (!panel_manager_ || definition.id.empty()) {
30 return false;
31 }
32
33 for (const auto& legacy_id : definition.legacy_ids) {
34 RegisterPanelAlias(legacy_id, definition.id);
35 }
36
37 panel_manager_->RegisterPanel(session_id, ToDescriptor(definition));
38 if (definition.visible_by_default) {
39 panel_manager_->ShowPanel(session_id, definition.id);
40 }
41
42 return true;
43}
44
46 if (!panel_manager_) {
47 return false;
48 }
49 return RegisterPanel(panel_manager_->GetActiveSessionId(), definition);
50}
51
53 size_t session_id, const std::vector<PanelDefinition>& definitions) {
54 if (!panel_manager_) {
55 return false;
56 }
57
58 bool any_registered = false;
59 for (const auto& definition : definitions) {
60 any_registered = RegisterPanel(session_id, definition) || any_registered;
61 }
62 return any_registered;
63}
64
66 const std::vector<PanelDefinition>& definitions) {
67 if (!panel_manager_) {
68 return false;
69 }
70 return RegisterPanels(panel_manager_->GetActiveSessionId(), definitions);
71}
72
73void PanelHost::RegisterPanelAlias(const std::string& legacy_id,
74 const std::string& canonical_id) {
75 if (!panel_manager_) {
76 return;
77 }
78 panel_manager_->RegisterPanelAlias(legacy_id, canonical_id);
79}
80
81bool PanelHost::ShowPanel(size_t session_id, const std::string& panel_id) {
82 return panel_manager_ && panel_manager_->ShowPanel(session_id, panel_id);
83}
84
85bool PanelHost::HidePanel(size_t session_id, const std::string& panel_id) {
86 return panel_manager_ && panel_manager_->HidePanel(session_id, panel_id);
87}
88
89bool PanelHost::TogglePanel(size_t session_id, const std::string& panel_id) {
90 return panel_manager_ && panel_manager_->TogglePanel(session_id, panel_id);
91}
92
93bool PanelHost::IsPanelVisible(size_t session_id,
94 const std::string& panel_id) const {
95 return panel_manager_ && panel_manager_->IsPanelVisible(session_id, panel_id);
96}
97
98bool PanelHost::OpenAndFocus(size_t session_id,
99 const std::string& panel_id) const {
100 if (!panel_manager_) {
101 return false;
102 }
103
104 if (!panel_manager_->ShowPanel(session_id, panel_id)) {
105 return false;
106 }
107
108 const std::string window_name =
109 panel_manager_->GetPanelWindowName(session_id, panel_id);
110 if (window_name.empty()) {
111 return false;
112 }
113
114 ImGui::SetWindowFocus(window_name.c_str());
115 return true;
116}
117
118std::string PanelHost::ResolvePanelId(const std::string& panel_id) const {
120 : panel_id;
121}
122
123std::string PanelHost::GetPanelWindowName(size_t session_id,
124 const std::string& panel_id) const {
125 return panel_manager_ ? panel_manager_->GetPanelWindowName(session_id, panel_id)
126 : std::string();
127}
128
129} // namespace editor
130} // namespace yaze
bool ShowPanel(size_t session_id, const std::string &panel_id)
Definition panel_host.cc:81
static PanelDescriptor ToDescriptor(const PanelDefinition &definition)
Definition panel_host.cc:9
bool IsPanelVisible(size_t session_id, const std::string &panel_id) const
Definition panel_host.cc:93
bool OpenAndFocus(size_t session_id, const std::string &panel_id) const
Definition panel_host.cc:98
std::string ResolvePanelId(const std::string &panel_id) const
std::string GetPanelWindowName(size_t session_id, const std::string &panel_id) const
PanelManager * panel_manager_
Definition panel_host.h:76
bool RegisterPanel(size_t session_id, const PanelDefinition &definition)
Definition panel_host.cc:27
bool RegisterPanels(size_t session_id, const std::vector< PanelDefinition > &definitions)
Definition panel_host.cc:52
bool TogglePanel(size_t session_id, const std::string &panel_id)
Definition panel_host.cc:89
void RegisterPanelAlias(const std::string &legacy_id, const std::string &canonical_id)
Definition panel_host.cc:73
bool HidePanel(size_t session_id, const std::string &panel_id)
Definition panel_host.cc:85
bool TogglePanel(size_t session_id, const std::string &base_card_id)
void RegisterPanelAlias(const std::string &legacy_base_id, const std::string &canonical_base_id)
Register a legacy panel ID alias that resolves to a canonical ID.
bool ShowPanel(size_t session_id, const std::string &base_card_id)
void RegisterPanel(size_t session_id, const PanelDescriptor &base_info)
bool IsPanelVisible(size_t session_id, const std::string &base_card_id) const
std::string GetPanelWindowName(size_t session_id, const std::string &base_card_id) const
Resolve the exact ImGui window name for a panel by base ID.
bool HidePanel(size_t session_id, const std::string &base_card_id)
size_t GetActiveSessionId() const
std::string ResolvePanelAlias(const std::string &panel_id) const
Resolve a panel ID through the alias table.
Declarative registration contract for editor panels.
Definition panel_host.h:22
std::vector< std::string > legacy_ids
Definition panel_host.h:35
PanelContextScope context_scope
Definition panel_host.h:34
std::function< void()> on_hide
Definition panel_host.h:37
std::function< void()> on_show
Definition panel_host.h:36
Metadata for an editor panel (formerly PanelInfo)
std::function< void()> on_show
PanelContextScope context_scope
std::function< void()> on_hide