I thought that one way to implement this is to duplicate the features for both panels. This is plausible for things like buttons. But for things like a text editor, this is not the best solution. The program would have to copy the buffers when switching modes.
What would be the best way share resources between panels? When I say "share resources" I mean instantiate one object that both panels use. I know it's possible to switch parents but what about sizers?
An example of what I'm looking for is to able to use the same text editor in both modes and be able to resize and move that text editor when switching between modes(using sizers).
Bellow is a code snippet of the class constructor creating all the wxWidget objects.
Code: Select all
wxSize window_size = UIPanel::panel() -> GetSize(); // UIPanel is a wrapper class for wxPanel.
uint32_t notebook_id = 1000;
// creation and window relationships.
wxNotebook * notebook = new wxNotebook(UIPanel::panel() , notebook_id , wxDefaultPosition , wxSize(window_size.GetWidth() , window_size.GetWidth()) , 0 , "");
wxPanel * m_edit_mode_panel = new wxPanel(notebook , wxID_ANY , wxDefaultPosition , wxDefaultSize , 0 , "");
wxPanel * m_debug_mode_panel = new wxPanel(notebook , wxID_ANY , wxDefaultPosition , wxDefaultSize , 0 , "");
m_text_editor = new TextEditor(m_edit_mode_panel); // Wrapper class for wxStyledTextCtrl.
notebook -> AddPage(m_edit_mode_panel , "edit");
notebook -> AddPage(m_debug_mode_panel , "debug");
// button creation and binding.
wxButton * compile_button = new wxButton(m_edit_mode_panel , COMPILE_ID , "Compile" , wxDefaultPosition); // default mode is edit mode.
wxButton * run_button = new wxButton(m_edit_mode_panel , RUN_ID , "Run" , wxDefaultPosition);
// I have removed binding.
// sizing
wxBoxSizer * button_sizer = new wxBoxSizer(wxHORIZONTAL);
button_sizer -> Add(compile_button);
button_sizer -> Add(run_button);
wxBoxSizer * edit_mode_sizer = new wxBoxSizer(wxHORIZONTAL);
edit_mode_sizer -> Add(m_text_editor , wxALIGN_RIGHT);
edit_mode_sizer -> Add(button_sizer , wxALIGN_LEFT);
wxBoxSizer * debug_mode_sizer = new wxBoxSizer(wxHORIZONTAL);
m_debug_mode_panel -> SetSizer(debug_mode_sizer); // Adding text editor to debug_mode_sizer creates sizing conflicts.
this -> panel() -> GetSizer() -> Add(notebook , 1 , wxEXPAND); // "this" inherits from UIPanel hence "this -> panel() -> ..." .