diff --git a/kicad/dialogs/dialog_template_selector.cpp b/kicad/dialogs/dialog_template_selector.cpp index 5be0a3921b..5d8487eff4 100644 --- a/kicad/dialogs/dialog_template_selector.cpp +++ b/kicad/dialogs/dialog_template_selector.cpp @@ -35,6 +35,15 @@ TEMPLATE_SELECTION_PANEL::TEMPLATE_SELECTION_PANEL( wxNotebookPage* aParent, { m_parent = aParent; m_templatesPath = aPath; + m_minHeight = 0; +} + + +void TEMPLATE_SELECTION_PANEL::AddTemplateWidget( TEMPLATE_WIDGET* aTemplateWidget ) +{ + m_SizerChoice->Add( aTemplateWidget ); + int height = aTemplateWidget->GetBestSize().GetHeight(); + m_minHeight = std::max( m_minHeight, height ); } @@ -96,17 +105,19 @@ void TEMPLATE_WIDGET::OnMouse( wxMouseEvent& event ) void DIALOG_TEMPLATE_SELECTOR::onNotebookResize( wxSizeEvent& event ) { + // Ensure all panels have the full available width: for( size_t i = 0; i < m_notebook->GetPageCount(); i++ ) { - m_panels[i]->SetSize( m_notebook->GetSize().GetWidth() - 6, - m_panels[i]->m_SizerChoice->GetSize().GetHeight() ); - m_panels[i]->m_SizerBase->FitInside( m_panels[i] ); - m_panels[i]->m_scrolledWindow->SetSize( m_panels[i]->GetSize().GetWidth() - 6, - m_panels[i]->GetSize().GetHeight() - 6 ); - m_panels[i]->m_SizerChoice->FitInside( m_panels[i]->m_scrolledWindow ); + // Gives a little margin for panel horizontal size, especially to show the + // full scroll bars of wxScrolledWindow + // Fix me if a better way exists + const int h_margin = 10; + + int max_width = m_notebook->GetClientSize().GetWidth() - h_margin; + m_panels[i]->SetSize( max_width, -1); } - m_notebook->Refresh(); + Refresh(); event.Skip(); } @@ -151,15 +162,7 @@ void DIALOG_TEMPLATE_SELECTOR::AddTemplate( int aPage, PROJECT_TEMPLATE* aTempla { TEMPLATE_WIDGET* w = new TEMPLATE_WIDGET( m_panels[aPage]->m_scrolledWindow, this ); w->SetTemplate( aTemplate ); - - m_panels[aPage]->m_SizerChoice->Add( w ); - m_panels[aPage]->m_SizerChoice->Layout(); - m_panels[aPage]->SetSize( m_notebook->GetSize().GetWidth() - 6, - m_panels[aPage]->m_SizerChoice->GetSize().GetHeight() ); - m_panels[aPage]->m_SizerBase->FitInside( m_panels[aPage] ); - m_panels[aPage]->m_scrolledWindow->SetSize( m_panels[aPage]->GetSize().GetWidth() - 6, - m_panels[aPage]->GetSize().GetHeight() - 6 ); - m_panels[aPage]->m_SizerChoice->FitInside( m_panels[aPage]->m_scrolledWindow ); + m_panels[aPage]->AddTemplateWidget( w ); m_notebook->Refresh(); } @@ -187,6 +190,16 @@ void DIALOG_TEMPLATE_SELECTOR::AddTemplatesPage( const wxString& aTitle, wxFileN m_tcTemplatePath->SetValue( path ); buildPageContent( path, m_notebook->GetPageCount() - 1 ); + + // Ensure m_notebook has a minimal height to show the template widgets: + // and add a margin for scroll bars and decorations + // FIX ME: find a better way to allow space for these items: the value works on MSW + // but is too big on GTK. But I did not find a better way (JPC) + const int margin = 50; + int min_height = tpanel->GetMinHeight() + margin; + + if( m_notebook->GetMinClientSize().GetHeight() < min_height ) + m_notebook->SetMinClientSize( wxSize( -1, min_height ) ); } diff --git a/kicad/dialogs/dialog_template_selector.h b/kicad/dialogs/dialog_template_selector.h index 09b919e49f..7ad202d2b5 100644 --- a/kicad/dialogs/dialog_template_selector.h +++ b/kicad/dialogs/dialog_template_selector.h @@ -68,6 +68,8 @@ protected: wxNotebookPage* m_parent; wxString m_templatesPath; ///< the path to access to the folder ///< containing the templates (which are also folders) + int m_minHeight; ///< minimal height to show templates (this is the height + ///< of the biggest template widget) public: /** @@ -77,6 +79,10 @@ public: TEMPLATE_SELECTION_PANEL( wxNotebookPage* aParent, const wxString& aPath ); const wxString& GetPath() { return m_templatesPath; } + + void AddTemplateWidget( TEMPLATE_WIDGET* aTemplateWidget ); + + int GetMinHeight() { return m_minHeight; } }; diff --git a/kicad/dialogs/dialog_template_selector_base.cpp b/kicad/dialogs/dialog_template_selector_base.cpp index b62793fabd..f0b6de8732 100644 --- a/kicad/dialogs/dialog_template_selector_base.cpp +++ b/kicad/dialogs/dialog_template_selector_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -17,11 +17,13 @@ DIALOG_TEMPLATE_SELECTOR_BASE::DIALOG_TEMPLATE_SELECTOR_BASE( wxWindow* parent, bmainSizer = new wxBoxSizer( wxVERTICAL ); m_notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + m_notebook->SetMinSize( wxSize( -1,100 ) ); - bmainSizer->Add( m_notebook, 0, wxEXPAND | wxALL, 3 ); + + bmainSizer->Add( m_notebook, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 3 ); m_htmlWin = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxSize( -1,-1 ), wxHW_SCROLLBAR_AUTO ); - bmainSizer->Add( m_htmlWin, 1, wxALL|wxEXPAND, 10 ); + bmainSizer->Add( m_htmlWin, 1, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); wxBoxSizer* bsizerTemplateSelector; bsizerTemplateSelector = new wxBoxSizer( wxHORIZONTAL ); @@ -81,7 +83,7 @@ TEMPLATE_SELECTION_PANEL_BASE::TEMPLATE_SELECTION_PANEL_BASE( wxWindow* parent, { m_SizerBase = new wxBoxSizer( wxHORIZONTAL ); - m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL ); + m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); m_scrolledWindow->SetScrollRate( 5, 5 ); m_SizerChoice = new wxGridSizer( 1, 0, 0, 0 ); @@ -89,7 +91,7 @@ TEMPLATE_SELECTION_PANEL_BASE::TEMPLATE_SELECTION_PANEL_BASE( wxWindow* parent, m_scrolledWindow->SetSizer( m_SizerChoice ); m_scrolledWindow->Layout(); m_SizerChoice->Fit( m_scrolledWindow ); - m_SizerBase->Add( m_scrolledWindow, 0, wxEXPAND | wxALL, 3 ); + m_SizerBase->Add( m_scrolledWindow, 1, wxEXPAND, 5 ); this->SetSizer( m_SizerBase ); @@ -105,20 +107,20 @@ TEMPLATE_WIDGET_BASE::TEMPLATE_WIDGET_BASE( wxWindow* parent, wxWindowID id, con this->SetMinSize( wxSize( 108,-1 ) ); this->SetMaxSize( wxSize( 108,-1 ) ); - wxBoxSizer* bSizer4; - bSizer4 = new wxBoxSizer( wxVERTICAL ); + wxBoxSizer* bSizerMain; + bSizerMain = new wxBoxSizer( wxVERTICAL ); m_bitmapIcon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 64,64 ), 0 ); m_bitmapIcon->SetMinSize( wxSize( 64,64 ) ); - bSizer4->Add( m_bitmapIcon, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 3 ); + bSizerMain->Add( m_bitmapIcon, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 3 ); m_staticTitle = new wxStaticText( this, wxID_ANY, _("Project Template Title"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL ); m_staticTitle->Wrap( 100 ); - bSizer4->Add( m_staticTitle, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 3 ); + bSizerMain->Add( m_staticTitle, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 3 ); - this->SetSizer( bSizer4 ); + this->SetSizer( bSizerMain ); this->Layout(); } diff --git a/kicad/dialogs/dialog_template_selector_base.fbp b/kicad/dialogs/dialog_template_selector_base.fbp index 72f7b174ab..0c24a11bb2 100644 --- a/kicad/dialogs/dialog_template_selector_base.fbp +++ b/kicad/dialogs/dialog_template_selector_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ dialog_template_selector_base 1000 none + 1 DIALOG_TEMPLATE_SELECTOR_BASE @@ -25,6 +26,7 @@ 1 1 UI + 0 0 0 @@ -45,11 +47,12 @@ 640,480 DIALOG_TEMPLATE_SELECTOR_BASE - 800,540 + 640,540 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER DIALOG_SHIM; dialog_shim.h Project Template Selector + 0 @@ -60,7 +63,7 @@ none 3 - wxEXPAND | wxALL + wxEXPAND|wxTOP|wxRIGHT|wxLEFT 0 1 @@ -96,7 +99,7 @@ -1,-1 0 - -1,-1 + -1,100 1 m_notebook 1 @@ -119,8 +122,8 @@ - 10 - wxALL|wxEXPAND + 5 + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT 1 1 @@ -324,6 +327,7 @@ + 0 @@ -397,6 +401,7 @@ + 0 @@ -556,6 +561,7 @@ -1,140 + 0 wxTAB_TRAVERSAL|wxBORDER_NONE @@ -565,9 +571,9 @@ wxHORIZONTAL public - 3 - wxEXPAND | wxALL - 0 + 5 + wxEXPAND + 1 1 1 @@ -601,7 +607,7 @@ 0 - + -1,-1 1 m_scrolledWindow 1 @@ -615,13 +621,13 @@ 5 1 - + ; ; forward_declare 0 - wxHSCROLL - + wxHSCROLL|wxVSCROLL + 0 0 @@ -653,19 +659,20 @@ 108,-1 + 0 wxTAB_TRAVERSAL - bSizer4 + bSizerMain wxVERTICAL none - + 3 wxALL|wxALIGN_CENTER_HORIZONTAL 0 - + 1 1 1 @@ -719,11 +726,11 @@ - + 3 wxALL|wxALIGN_CENTER_HORIZONTAL 1 - + 1 1 1 diff --git a/kicad/dialogs/dialog_template_selector_base.h b/kicad/dialogs/dialog_template_selector_base.h index d068010575..d7d6ec6389 100644 --- a/kicad/dialogs/dialog_template_selector_base.h +++ b/kicad/dialogs/dialog_template_selector_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -54,7 +54,7 @@ class DIALOG_TEMPLATE_SELECTOR_BASE : public DIALOG_SHIM wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; - // Virtual event handlers, overide them in your derived class + // Virtual event handlers, override them in your derived class virtual void OnPageChange( wxNotebookEvent& event ) { event.Skip(); } virtual void OnHtmlLinkActivated( wxHtmlLinkEvent& event ) { event.Skip(); } virtual void onDirectoryBrowseClicked( wxCommandEvent& event ) { event.Skip(); } @@ -63,7 +63,8 @@ class DIALOG_TEMPLATE_SELECTOR_BASE : public DIALOG_SHIM public: - DIALOG_TEMPLATE_SELECTOR_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Project Template Selector"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 800,540 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + DIALOG_TEMPLATE_SELECTOR_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Project Template Selector"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 640,540 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~DIALOG_TEMPLATE_SELECTOR_BASE(); }; @@ -83,6 +84,7 @@ class TEMPLATE_SELECTION_PANEL_BASE : public wxPanel wxGridSizer* m_SizerChoice; TEMPLATE_SELECTION_PANEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,140 ), long style = wxTAB_TRAVERSAL|wxBORDER_NONE, const wxString& name = wxEmptyString ); + ~TEMPLATE_SELECTION_PANEL_BASE(); }; @@ -101,6 +103,7 @@ class TEMPLATE_WIDGET_BASE : public wxPanel public: TEMPLATE_WIDGET_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 108,-1 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + ~TEMPLATE_WIDGET_BASE(); };