Ember
Loading...
Searching...
No Matches
Panel.h
Go to the documentation of this file.
1#pragma once
2
3#include "Interfaces/IPanel.h"
4#include <memory>
5#include <wx/panel.h>
6#include <wx/sizer.h>
7
8namespace EmberUI {
9
11class Panel : public wxPanel, public IPanel {
12 public:
14 explicit Panel(wxWindow *parent, const wxString &name = "Panel", long style = wxTAB_TRAVERSAL);
15 virtual ~Panel();
16
18 wxPanel *GetPanel() override { return this; }
20 wxString GetTitle() const override { return title_; }
22 wxString GetPanelType() const override { return panel_type_; }
23
25 void Initialize() override;
27 void Refresh() override;
29 void OnActivated() override;
31 void OnDeactivated() override;
33 void Cleanup() override;
34
36 bool IsValid() const override { return is_initialized_; }
37
39 wxString SerializeState() const override;
41 void DeserializeState(const wxString &state) override;
42
44 bool HasUnsavedChanges() const override { return has_unsaved_changes_; }
46 bool Save() override;
47
49 bool SupportsOperation(const wxString &operation) const override;
51 bool ExecuteOperation(const wxString &operation, const wxString &parameter = "") override;
52
54 wxString GetName() const override { return name_; }
56 void SetName(const wxString &name) override;
57
59 void SetTitle(const wxString &title) { title_ = title; }
61 void SetPanelType(const wxString &type) { panel_type_ = type; }
62
63 protected:
65 virtual void CreateLayout();
67 virtual void ApplyTheme();
69 virtual void UpdateContent();
71 virtual void HandleActivation();
73 virtual void HandleDeactivation();
75 virtual bool ValidateState() const;
76
80 void MarkSaved() { has_unsaved_changes_ = false; }
81
83 wxSizer *GetMainSizer() const { return main_sizer_; }
85 void SetMainSizer(wxSizer *sizer);
86
88 virtual void OnPanelSize(wxSizeEvent &event);
90 virtual void OnPanelPaint(wxPaintEvent &event);
91
92 private:
93 wxSizer *main_sizer_;
94 wxString name_;
95 wxString title_;
96 wxString panel_type_;
100
104
105 void InitializePanel();
106 void SetupEventHandlers();
107 void UpdateAppearance();
108 void DoCleanup();
109 void DoApplyTheme();
110
111 Panel(const Panel &) = delete;
112 Panel &operator=(const Panel &) = delete;
113
114 DECLARE_EVENT_TABLE()
115};
116
117} // namespace EmberUI
bool HasUnsavedChanges() const override
Returns true if there are unsaved changes.
Definition Panel.h:44
void SetPanelType(const wxString &type)
Sets the panel type identifier.
Definition Panel.h:61
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
Panel & operator=(const Panel &)=delete
Panel(wxWindow *parent, const wxString &name="Panel", long style=wxTAB_TRAVERSAL)
Constructs the panel with optional name and style.
void Cleanup() override
Cleans up panel resources.
Definition Panel.cpp:63
bool IsValid() const override
Returns true if the panel has been initialized.
Definition Panel.h:36
wxString GetTitle() const override
Returns the panel title.
Definition Panel.h:20
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 SetTitle(const wxString &title)
Sets the panel title.
Definition Panel.h:59
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
void MarkChanged()
Marks the panel as having unsaved changes.
Definition Panel.h:78
virtual void OnPanelSize(wxSizeEvent &event)
Hook: handles panel resize events.
Definition Panel.cpp:143
wxString GetPanelType() const override
Returns the panel type identifier.
Definition Panel.h:22
bool SupportsOperation(const wxString &operation) const override
Returns true if the panel supports the given operation.
Definition Panel.cpp:96
void MarkSaved()
Clears the unsaved-changes flag.
Definition Panel.h:80
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
wxString GetName() const override
Returns the panel name.
Definition Panel.h:54
wxPanel * GetPanel() override
Returns this panel as wxPanel pointer.
Definition Panel.h:18
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
wxSizer * GetMainSizer() const
Returns the main sizer for layout.
Definition Panel.h:83
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
Panel(const Panel &)=delete
Interface for panel-based UI components in the application.
Definition IPanel.h:7
Definition Panel.h:8