Kicad manager: Fix some issues in DIALOG_TEMPLATE_SELECTOR. The fix is not perfect, but it works. Fixes #9329 https://gitlab.com/kicad/code/kicad/issues/9329

This commit is contained in:
jean-pierre charras 2021-10-07 19:38:58 +02:00
parent 8c8d66a181
commit e508e08ecf
5 changed files with 78 additions and 47 deletions

View File

@ -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 ) );
}

View File

@ -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; }
};

View File

@ -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();
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="15" />
<FileVersion major="1" minor="16" />
<object class="Project" expanded="1">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
@ -14,6 +14,7 @@
<property name="file">dialog_template_selector_base</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="image_path_wrapper_function_name"></property>
<property name="indent_with_spaces"></property>
<property name="internationalize">1</property>
<property name="name">DIALOG_TEMPLATE_SELECTOR_BASE</property>
@ -25,6 +26,7 @@
<property name="skip_php_events">1</property>
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_array_enum">0</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Dialog" expanded="1">
@ -45,11 +47,12 @@
<property name="minimum_size">640,480</property>
<property name="name">DIALOG_TEMPLATE_SELECTOR_BASE</property>
<property name="pos"></property>
<property name="size">800,540</property>
<property name="size">640,540</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Project Template Selector</property>
<property name="tooltip"></property>
<property name="two_step_creation">0</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
@ -60,7 +63,7 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">3</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="flag">wxEXPAND|wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxNotebook" expanded="1">
<property name="BottomDockable">1</property>
@ -96,7 +99,7 @@
<property name="maximum_size">-1,-1</property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">-1,-1</property>
<property name="minimum_size">-1,100</property>
<property name="moveable">1</property>
<property name="name">m_notebook</property>
<property name="pane_border">1</property>
@ -119,8 +122,8 @@
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">10</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="border">5</property>
<property name="flag">wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxHtmlWindow" expanded="1">
<property name="BottomDockable">1</property>
@ -324,6 +327,7 @@
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
@ -397,6 +401,7 @@
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
@ -556,6 +561,7 @@
<property name="size">-1,140</property>
<property name="subclass"></property>
<property name="tooltip"></property>
<property name="two_step_creation">0</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL|wxBORDER_NONE</property>
@ -565,9 +571,9 @@
<property name="orient">wxHORIZONTAL</property>
<property name="permission">public</property>
<object class="sizeritem" expanded="1">
<property name="border">3</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">0</property>
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxScrolledWindow" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
@ -601,7 +607,7 @@
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="minimum_size">-1,-1</property>
<property name="moveable">1</property>
<property name="name">m_scrolledWindow</property>
<property name="pane_border">1</property>
@ -615,13 +621,13 @@
<property name="scroll_rate_y">5</property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxHSCROLL</property>
<object class="wxGridSizer" expanded="1">
<property name="window_style">wxHSCROLL|wxVSCROLL</property>
<object class="wxGridSizer" expanded="0">
<property name="cols">0</property>
<property name="hgap">0</property>
<property name="minimum_size"></property>
@ -653,19 +659,20 @@
<property name="size">108,-1</property>
<property name="subclass"></property>
<property name="tooltip"></property>
<property name="two_step_creation">0</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxTAB_TRAVERSAL</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer4</property>
<property name="name">bSizerMain</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">3</property>
<property name="flag">wxALL|wxALIGN_CENTER_HORIZONTAL</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="1">
<object class="wxStaticBitmap" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -719,11 +726,11 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">3</property>
<property name="flag">wxALL|wxALIGN_CENTER_HORIZONTAL</property>
<property name="proportion">1</property>
<object class="wxStaticText" expanded="1">
<object class="wxStaticText" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>

View File

@ -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();
};