Ember
Loading...
Searching...
No Matches
Panel.cpp
Go to the documentation of this file.
1#include "Components/Panel.h"
2
3#include <wx/menu.h>
4#include <wx/sizer.h>
5
6namespace EmberUI {
7
9
10 Panel::Panel(wxWindow *parent, const wxString &name, long style)
11 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style), main_sizer_(nullptr), name_(name),
12 title_(name), panel_type_("Panel"), is_initialized_(false), is_active_(false), has_unsaved_changes_(false) {
13 background_color_ = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
14 foreground_color_ = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
15 panel_font_ = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
16
17 InitializePanel();
18}
19
21
22void Panel::SetName(const wxString &name) {
23 name_ = name;
24 wxPanel::SetName(name);
25}
26
29 return;
30
32 ApplyTheme();
34
35 is_initialized_ = true;
36}
37
39 if (!is_initialized_)
40 return;
41
44 wxPanel::Refresh();
45}
46
48 if (is_active_)
49 return;
50
51 is_active_ = true;
53}
54
56 if (!is_active_)
57 return;
58
59 is_active_ = false;
61}
62
64
66 if (!is_initialized_)
67 return;
68
69 is_initialized_ = false;
70 is_active_ = false;
71
72 if (main_sizer_) {
73 main_sizer_->Clear(true);
74 main_sizer_ = nullptr;
75 }
76}
77
78wxString Panel::SerializeState() const {
79 wxString state;
80 state += "name=" + name_ + ";";
81 state += "title=" + title_ + ";";
82 state += "type=" + panel_type_ + ";";
83 state += "visible=" + wxString(IsShown() ? "true" : "false") + ";";
84 return state;
85}
86
87void Panel::DeserializeState(const wxString &state) {}
88
91 return true;
93 return true;
94}
95
96bool Panel::SupportsOperation(const wxString &operation) const {
97 return operation == "refresh" || operation == "reset" || operation == "serialize";
98}
99
100bool Panel::ExecuteOperation(const wxString &operation, const wxString &parameter) {
101 if (operation == "refresh") {
102 Refresh();
103 return true;
104 } else if (operation == "reset") {
105 Cleanup();
106 Initialize();
107 return true;
108 } else if (operation == "serialize") {
110 return true;
111 }
112 return false;
113}
114
116 if (!main_sizer_) {
117 main_sizer_ = new wxBoxSizer(wxVERTICAL);
118 SetSizer(main_sizer_);
119 }
120}
121
123
125 SetBackgroundColour(background_color_);
126 SetForegroundColour(foreground_color_);
127 SetFont(panel_font_);
128}
129
131
133
135
136bool Panel::ValidateState() const { return is_initialized_; }
137
138void Panel::SetMainSizer(wxSizer *sizer) {
139 main_sizer_ = sizer;
140 SetSizer(sizer);
141}
142
143void Panel::OnPanelSize(wxSizeEvent &event) {
144 if (main_sizer_) {
145 Layout();
146 }
147 event.Skip();
148}
149
150void Panel::OnPanelPaint(wxPaintEvent &event) {
151 wxPaintDC dc(this);
152 event.Skip();
153}
154
159
161
163 ApplyTheme();
164 Layout();
165}
166
167} // namespace EmberUI
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
Base class for all panels with layout, theme, and state management.
Definition Panel.h:11
wxFont panel_font_
Definition Panel.h:103
virtual void OnPanelPaint(wxPaintEvent &event)
Hook: handles panel paint events.
Definition Panel.cpp:150
virtual void CreateLayout()
Hook: creates the panel layout. Override to customize.
Definition Panel.cpp:115
void Cleanup() override
Cleans up panel resources.
Definition Panel.cpp:63
virtual void HandleActivation()
Hook: handles panel activation. Override to customize.
Definition Panel.cpp:132
void DeserializeState(const wxString &state) override
Restores panel state from a serialized string.
Definition Panel.cpp:87
void SetName(const wxString &name) override
Sets the panel name.
Definition Panel.cpp:22
void OnActivated() override
Called when the panel is activated.
Definition Panel.cpp:47
void OnDeactivated() override
Called when the panel is deactivated.
Definition Panel.cpp:55
wxColour foreground_color_
Definition Panel.h:102
virtual void ApplyTheme()
Hook: applies theme colors and fonts. Override to customize.
Definition Panel.cpp:122
virtual void OnPanelSize(wxSizeEvent &event)
Hook: handles panel resize events.
Definition Panel.cpp:143
bool SupportsOperation(const wxString &operation) const override
Returns true if the panel supports the given operation.
Definition Panel.cpp:96
void DoCleanup()
Definition Panel.cpp:65
virtual ~Panel()
Definition Panel.cpp:20
void UpdateAppearance()
Definition Panel.cpp:162
wxString panel_type_
Definition Panel.h:96
wxString name_
Definition Panel.h:94
bool is_active_
Definition Panel.h:98
void DoApplyTheme()
Definition Panel.cpp:124
bool ExecuteOperation(const wxString &operation, const wxString &parameter="") override
Executes a named operation with optional parameter.
Definition Panel.cpp:100
wxString title_
Definition Panel.h:95
void InitializePanel()
Definition Panel.cpp:155
bool is_initialized_
Definition Panel.h:97
void SetupEventHandlers()
Definition Panel.cpp:160
void Initialize() override
Initializes the panel layout and appearance.
Definition Panel.cpp:27
void SetMainSizer(wxSizer *sizer)
Sets the main sizer.
Definition Panel.cpp:138
wxColour background_color_
Definition Panel.h:101
virtual void UpdateContent()
Hook: updates displayed content. Override to refresh data.
Definition Panel.cpp:130
wxSizer * main_sizer_
Definition Panel.h:93
wxString SerializeState() const override
Serializes panel state to a string.
Definition Panel.cpp:78
virtual void HandleDeactivation()
Hook: handles panel deactivation. Override to customize.
Definition Panel.cpp:134
void Refresh() override
Refreshes panel content.
Definition Panel.cpp:38
bool Save() override
Saves panel state; returns true on success.
Definition Panel.cpp:89
virtual bool ValidateState() const
Hook: validates panel state; returns true if valid.
Definition Panel.cpp:136
bool has_unsaved_changes_
Definition Panel.h:99
Standard layout constants for consistent UI spacing and sizing.
Definition Panel.h:8
wxBEGIN_EVENT_TABLE(Panel, wxPanel) EVT_SIZE(Panel
Definition Panel.cpp:8