Make layout of project template browser more flexible.

In particular, don't use a fixed height for the templates chooser,
and Wrap() must be called again whenever the text is changed.

Also moves the buttons to icon buttons.

Fixes https://gitlab.com/kicad/code/kicad/issues/9241
This commit is contained in:
Jeff Young 2021-09-26 18:38:53 +01:00
parent 5dc82037fb
commit 665eeb65e9
5 changed files with 58 additions and 47 deletions

View File

@ -23,7 +23,7 @@
*/
#include "dialog_template_selector.h"
#include <bitmaps.h>
#include <wx/dir.h>
#include <wx/dirdlg.h>
#include <wx/settings.h>
@ -81,6 +81,7 @@ void TEMPLATE_WIDGET::SetTemplate( PROJECT_TEMPLATE* aTemplate )
{
m_currTemplate = aTemplate;
m_staticTitle->SetLabel( *( aTemplate->GetTitle() ) );
m_staticTitle->Wrap( 100 );
m_bitmapIcon->SetBitmap( *( aTemplate->GetIcon() ) );
}
@ -124,6 +125,9 @@ void DIALOG_TEMPLATE_SELECTOR::OnPageChange( wxNotebookEvent& event )
DIALOG_TEMPLATE_SELECTOR::DIALOG_TEMPLATE_SELECTOR( wxWindow* aParent ) :
DIALOG_TEMPLATE_SELECTOR_BASE( aParent )
{
m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
m_reloadButton->SetBitmap( KiBitmap( BITMAPS::small_refresh ) );
m_htmlWin->SetPage( _( "<html><h1>Template Selector</h1></html>" ) );
m_notebook->Connect( wxEVT_SIZE,
wxSizeEventHandler( DIALOG_TEMPLATE_SELECTOR::onNotebookResize ),
@ -149,7 +153,8 @@ void DIALOG_TEMPLATE_SELECTOR::AddTemplate( int aPage, PROJECT_TEMPLATE* aTempla
m_panels[aPage]->m_SizerChoice->Add( w );
m_panels[aPage]->m_SizerChoice->Layout();
m_panels[aPage]->SetSize( m_notebook->GetSize().GetWidth() - 6, 140 );
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 );
@ -241,7 +246,7 @@ void DIALOG_TEMPLATE_SELECTOR::onDirectoryBrowseClicked( wxCommandEvent& event )
}
void DIALOG_TEMPLATE_SELECTOR::onValidatePath( wxCommandEvent& event )
void DIALOG_TEMPLATE_SELECTOR::onReload( wxCommandEvent& event )
{
int page = m_notebook->GetSelection();

View File

@ -121,7 +121,7 @@ private:
void onNotebookResize( wxSizeEvent& event );
void OnPageChange( wxNotebookEvent& event ) override;
void onDirectoryBrowseClicked( wxCommandEvent& event ) override;
void onValidatePath( wxCommandEvent& event ) override;
void onReload( wxCommandEvent& event ) override;
void OnHtmlLinkActivated( wxHtmlLinkEvent& event ) override;
};

View File

@ -33,11 +33,11 @@ DIALOG_TEMPLATE_SELECTOR_BASE::DIALOG_TEMPLATE_SELECTOR_BASE( wxWindow* parent,
m_tcTemplatePath = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
bsizerTemplateSelector->Add( m_tcTemplatePath, 1, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
m_buttonBrowse = new wxButton( this, wxID_ANY, _("Browse"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
bsizerTemplateSelector->Add( m_buttonBrowse, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_browseButton = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
bsizerTemplateSelector->Add( m_browseButton, 0, wxTOP|wxBOTTOM, 5 );
m_buttonValidate = new wxButton( this, wxID_ANY, _("Validate"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
bsizerTemplateSelector->Add( m_buttonValidate, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
m_reloadButton = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
bsizerTemplateSelector->Add( m_reloadButton, 0, wxALL, 5 );
bmainSizer->Add( bsizerTemplateSelector, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
@ -63,8 +63,8 @@ DIALOG_TEMPLATE_SELECTOR_BASE::DIALOG_TEMPLATE_SELECTOR_BASE( wxWindow* parent,
// Connect Events
m_notebook->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::OnPageChange ), NULL, this );
m_htmlWin->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::OnHtmlLinkActivated ), NULL, this );
m_buttonBrowse->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::onDirectoryBrowseClicked ), NULL, this );
m_buttonValidate->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::onValidatePath ), NULL, this );
m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::onDirectoryBrowseClicked ), NULL, this );
m_reloadButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::onReload ), NULL, this );
}
DIALOG_TEMPLATE_SELECTOR_BASE::~DIALOG_TEMPLATE_SELECTOR_BASE()
@ -72,8 +72,8 @@ DIALOG_TEMPLATE_SELECTOR_BASE::~DIALOG_TEMPLATE_SELECTOR_BASE()
// Disconnect Events
m_notebook->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::OnPageChange ), NULL, this );
m_htmlWin->Disconnect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::OnHtmlLinkActivated ), NULL, this );
m_buttonBrowse->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::onDirectoryBrowseClicked ), NULL, this );
m_buttonValidate->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::onValidatePath ), NULL, this );
m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::onDirectoryBrowseClicked ), NULL, this );
m_reloadButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_TEMPLATE_SELECTOR_BASE::onReload ), NULL, this );
}
@ -83,7 +83,7 @@ TEMPLATE_SELECTION_PANEL_BASE::TEMPLATE_SELECTION_PANEL_BASE( wxWindow* parent,
m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL );
m_scrolledWindow->SetScrollRate( 5, 5 );
m_SizerChoice = new wxBoxSizer( wxHORIZONTAL );
m_SizerChoice = new wxGridSizer( 1, 0, 0, 0 );
m_scrolledWindow->SetSizer( m_SizerChoice );
@ -102,18 +102,20 @@ TEMPLATE_SELECTION_PANEL_BASE::~TEMPLATE_SELECTION_PANEL_BASE()
TEMPLATE_WIDGET_BASE::TEMPLATE_WIDGET_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name )
{
this->SetMinSize( wxSize( 74,150 ) );
this->SetMaxSize( wxSize( 74,-1 ) );
this->SetMinSize( wxSize( 108,-1 ) );
this->SetMaxSize( wxSize( 108,-1 ) );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxVERTICAL );
m_bitmapIcon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 64,64 ), 0 );
bSizer4->Add( m_bitmapIcon, 0, wxALL|wxEXPAND, 3 );
m_bitmapIcon->SetMinSize( wxSize( 64,64 ) );
bSizer4->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( 150 );
bSizer4->Add( m_staticTitle, 1, wxALL|wxEXPAND, 3 );
m_staticTitle->Wrap( 100 );
bSizer4->Add( m_staticTitle, 1, wxALL|wxALIGN_CENTER_HORIZONTAL, 3 );
this->SetSizer( bSizer4 );

View File

@ -45,7 +45,7 @@
<property name="minimum_size">640,480</property>
<property name="name">DIALOG_TEMPLATE_SELECTOR_BASE</property>
<property name="pos"></property>
<property name="size">640,480</property>
<property name="size">800,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>
@ -313,9 +313,9 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT</property>
<property name="flag">wxTOP|wxBOTTOM</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<object class="wxBitmapButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -358,7 +358,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonBrowse</property>
<property name="name">m_browseButton</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -370,8 +370,8 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxBU_EXACTFIT</property>
<property name="subclass"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
@ -386,9 +386,9 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<object class="wxBitmapButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -421,7 +421,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Validate</property>
<property name="label">Reload</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
@ -431,7 +431,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonValidate</property>
<property name="name">m_reloadButton</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -443,8 +443,8 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxBU_EXACTFIT</property>
<property name="subclass"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
@ -454,7 +454,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">onValidatePath</event>
<event name="OnButtonClick">onReload</event>
</object>
</object>
</object>
@ -621,11 +621,14 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxHSCROLL</property>
<object class="wxBoxSizer" expanded="1">
<object class="wxGridSizer" expanded="1">
<property name="cols">0</property>
<property name="hgap">0</property>
<property name="minimum_size"></property>
<property name="name">m_SizerChoice</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">public</property>
<property name="rows">1</property>
<property name="vgap">0</property>
</object>
</object>
</object>
@ -643,11 +646,11 @@
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size">74,-1</property>
<property name="minimum_size">74,150</property>
<property name="maximum_size">108,-1</property>
<property name="minimum_size">108,-1</property>
<property name="name">TEMPLATE_WIDGET_BASE</property>
<property name="pos"></property>
<property name="size">74,118</property>
<property name="size">108,-1</property>
<property name="subclass"></property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
@ -660,7 +663,7 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">3</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="flag">wxALL|wxALIGN_CENTER_HORIZONTAL</property>
<property name="proportion">0</property>
<object class="wxStaticBitmap" expanded="1">
<property name="BottomDockable">1</property>
@ -696,7 +699,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">64,64</property>
<property name="moveable">1</property>
<property name="name">m_bitmapIcon</property>
<property name="pane_border">1</property>
@ -718,7 +721,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">3</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="flag">wxALL|wxALIGN_CENTER_HORIZONTAL</property>
<property name="proportion">1</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
@ -755,7 +758,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_staticTitle</property>
<property name="pane_border">1</property>
@ -774,7 +777,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">150</property>
<property name="wrap">100</property>
</object>
</object>
</object>

View File

@ -20,6 +20,7 @@
#include <wx/html/htmlwin.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/bmpbuttn.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
@ -46,8 +47,8 @@ class DIALOG_TEMPLATE_SELECTOR_BASE : public DIALOG_SHIM
wxHtmlWindow* m_htmlWin;
wxStaticText* m_staticTextTpath;
wxTextCtrl* m_tcTemplatePath;
wxButton* m_buttonBrowse;
wxButton* m_buttonValidate;
wxBitmapButton* m_browseButton;
wxBitmapButton* m_reloadButton;
wxStaticLine* m_staticline;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;
@ -57,12 +58,12 @@ class DIALOG_TEMPLATE_SELECTOR_BASE : public DIALOG_SHIM
virtual void OnPageChange( wxNotebookEvent& event ) { event.Skip(); }
virtual void OnHtmlLinkActivated( wxHtmlLinkEvent& event ) { event.Skip(); }
virtual void onDirectoryBrowseClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void onValidatePath( wxCommandEvent& event ) { event.Skip(); }
virtual void onReload( wxCommandEvent& event ) { event.Skip(); }
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( 640,480 ), 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( 800,540 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_TEMPLATE_SELECTOR_BASE();
};
@ -79,7 +80,7 @@ class TEMPLATE_SELECTION_PANEL_BASE : public wxPanel
public:
wxBoxSizer* m_SizerBase;
wxScrolledWindow* m_scrolledWindow;
wxBoxSizer* m_SizerChoice;
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();
@ -99,7 +100,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( 74,118 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
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();
};