Ember
Loading...
Searching...
No Matches
Panel.cpp
Go to the documentation of this file.
1#include "Components/Panel.h"
2#include "Utils/Logger.h"
3
4using namespace EmberCore;
5#include <wx/menu.h>
6#include <wx/sizer.h>
7
10
11 Panel::Panel(wxWindow *parent, const wxString &name, long style)
12 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style), main_sizer_(nullptr), name_(name),
13 title_(name), panel_type_("Panel"), is_initialized_(false), is_active_(false), has_unsaved_changes_(false) {
14 // Initialize appearance
15 background_color_ = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
16 foreground_color_ = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
17 panel_font_ = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
18
19 InitializePanel();
20 Logger::GetInstance().Info("Panel", "Created panel: " + name_.ToStdString());
21}
22
24 Logger::GetInstance().Info("Panel", "Destroying panel: " + name_.ToStdString());
25 DoCleanup(); // Non-virtual: safe to call from destructor
26}
27
28void Panel::SetName(const wxString &name) {
29 name_ = name;
30 wxPanel::SetName(name);
31}
32
35 return;
36
38 ApplyTheme();
40
41 is_initialized_ = true;
42 Logger::GetInstance().Info("Panel", "Initialized panel: " + name_.ToStdString());
43}
44
46 if (!is_initialized_)
47 return;
48
51 wxPanel::Refresh();
52}
53
55 if (is_active_)
56 return;
57
58 is_active_ = true;
60 Logger::GetInstance().Info("Panel", "Activated panel: " + name_.ToStdString());
61}
62
64 if (!is_active_)
65 return;
66
67 is_active_ = false;
69 Logger::GetInstance().Info("Panel", "Deactivated panel: " + name_.ToStdString());
70}
71
73 DoCleanup(); // Virtual dispatch works here (object fully constructed)
74}
75
77 if (!is_initialized_)
78 return;
79
80 is_initialized_ = false;
81 is_active_ = false;
82
83 if (main_sizer_) {
84 main_sizer_->Clear(true);
85 main_sizer_ = nullptr;
86 }
87
88 Logger::GetInstance().Info("Panel", "Cleaned up panel: " + name_.ToStdString());
89}
90
91wxString Panel::SerializeState() const {
92 wxString state;
93 state += "name=" + name_ + ";";
94 state += "title=" + title_ + ";";
95 state += "type=" + panel_type_ + ";";
96 state += "visible=" + wxString(IsShown() ? "true" : "false") + ";";
97 return state;
98}
99
100void Panel::DeserializeState(const wxString &state) {
101 // Simple state deserialization
102 // In a real implementation, this would parse the state string
103 Logger::GetInstance().Info("Panel", "Deserializing state for panel: " + name_.ToStdString());
104}
105
108 return true;
109
110 // Default implementation - override in derived classes
111 has_unsaved_changes_ = false;
112 return true;
113}
114
115bool Panel::SupportsOperation(const wxString &operation) const {
116 // Default supported operations
117 return operation == "refresh" || operation == "reset" || operation == "serialize";
118}
119
120bool Panel::ExecuteOperation(const wxString &operation, const wxString &parameter) {
121 if (operation == "refresh") {
122 Refresh();
123 return true;
124 } else if (operation == "reset") {
125 Cleanup();
126 Initialize();
127 return true;
128 } else if (operation == "serialize") {
130 return true;
131 }
132 return false;
133}
134
136 // Default empty layout - override in derived classes
137 if (!main_sizer_) {
138 main_sizer_ = new wxBoxSizer(wxVERTICAL);
139 SetSizer(main_sizer_);
140 }
141}
142
144 DoApplyTheme(); // Virtual dispatch works when called at runtime
145}
146
148 // Apply theme colors
149 SetBackgroundColour(background_color_);
150 SetForegroundColour(foreground_color_);
151 SetFont(panel_font_);
152}
153
155 // Default empty implementation - override in derived classes
156}
157
159 // Default empty implementation - override in derived classes
160}
161
163 // Default empty implementation - override in derived classes
164}
165
166bool Panel::ValidateState() const { return is_initialized_; }
167
168void Panel::SetMainSizer(wxSizer *sizer) {
169 main_sizer_ = sizer;
170 SetSizer(sizer);
171}
172
173void Panel::OnPanelSize(wxSizeEvent &event) {
174 if (main_sizer_) {
175 Layout();
176 }
177 event.Skip();
178}
179
180void Panel::OnPanelPaint(wxPaintEvent &event) {
181 wxPaintDC dc(this);
182 // Default paint handling
183 event.Skip();
184}
185
186void Panel::OnPanelRightClick(wxContextMenuEvent &event) {
187 // Default context menu handling
188 event.Skip();
189}
190
193 DoApplyTheme(); // Non-virtual: safe to call from constructor
194}
195
197 // Event handlers are set up via the event table
198}
199
201 ApplyTheme();
202 Layout();
203}
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
wxBEGIN_EVENT_TABLE(Panel, wxPanel) EVT_SIZE(Panel
Definition Panel.cpp:8
static Logger & GetInstance()
Definition Logger.cpp:251
void Info(const EmberCore::String &category, const EmberCore::String &message)
Definition Logger.cpp:105
Base implementation of IPanel interface.
Definition Panel.h:28
void OnActivated() override
Called when the panel becomes visible/active.
Definition Panel.cpp:54
wxSizer * main_sizer_
Definition Panel.h:136
bool SupportsOperation(const wxString &operation) const override
Check if this panel supports the given operation.
Definition Panel.cpp:115
virtual void HandleActivation()
Handle panel activation Called when panel becomes active.
Definition Panel.cpp:158
virtual void HandleDeactivation()
Handle panel deactivation Called when panel becomes inactive.
Definition Panel.cpp:162
void Initialize() override
Initialize the panel after construction Called once after the panel is created and configured.
Definition Panel.cpp:33
virtual void OnPanelSize(wxSizeEvent &event)
Definition Panel.cpp:173
void Refresh() override
Called when the panel should refresh its display This should update the panel's content to reflect cu...
Definition Panel.cpp:45
wxString title_
Definition Panel.h:140
bool Save() override
Save the panel's data (if applicable)
Definition Panel.cpp:106
virtual void ApplyTheme()
Apply current theme to the panel Called when theme changes.
Definition Panel.cpp:143
void DoApplyTheme()
Definition Panel.cpp:147
bool is_active_
Definition Panel.h:143
void SetupEventHandlers()
Definition Panel.cpp:196
wxColour background_color_
Definition Panel.h:147
wxColour foreground_color_
Definition Panel.h:148
virtual void OnPanelRightClick(wxContextMenuEvent &event)
Definition Panel.cpp:186
void DeserializeState(const wxString &state) override
Restore the panel's state from serialized data.
Definition Panel.cpp:100
virtual ~Panel()
Destructor.
Definition Panel.cpp:23
wxString panel_type_
Definition Panel.h:141
virtual bool ValidateState() const
Validate panel state Override to provide custom validation logic.
Definition Panel.cpp:166
wxFont panel_font_
Definition Panel.h:149
void Cleanup() override
Called when the panel is about to be destroyed Use this for cleanup operations.
Definition Panel.cpp:72
virtual void UpdateContent()
Update panel content Called during refresh.
Definition Panel.cpp:154
wxString SerializeState() const override
Serialize the panel's current state to a string.
Definition Panel.cpp:91
void SetMainSizer(wxSizer *sizer)
Set the main sizer (takes ownership)
Definition Panel.cpp:168
void UpdateAppearance()
Definition Panel.cpp:200
void OnDeactivated() override
Called when the panel becomes hidden/inactive.
Definition Panel.cpp:63
bool has_unsaved_changes_
Definition Panel.h:144
void InitializePanel()
Definition Panel.cpp:191
bool is_initialized_
Definition Panel.h:142
void SetName(const wxString &name) override
Definition Panel.cpp:28
wxString name_
Definition Panel.h:139
virtual void OnPanelPaint(wxPaintEvent &event)
Definition Panel.cpp:180
bool ExecuteOperation(const wxString &operation, const wxString &parameter="") override
Execute a named operation on this panel.
Definition Panel.cpp:120
virtual void CreateLayout()
Create the panel's UI layout Called during initialization.
Definition Panel.cpp:135
void DoCleanup()
Definition Panel.cpp:76
Main types header for EmberCore.