Fixup the UI for the symbol preview widget

This is the proper fix for the symbole preview widget. It will ensure
there are no size changes between the two panels (preview and status),
and also ensure that the status panel has the same background color as
the preview panel.

Fixes https://gitlab.com/kicad/code/kicad/issues/4997
This commit is contained in:
Ian McInerney 2020-08-10 00:51:36 +01:00
parent b3525bc642
commit b23db7c4cb
2 changed files with 27 additions and 12 deletions

View File

@ -65,24 +65,36 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway,
// before any OnPaint event is fired for the canvas using a wrong bg color // before any OnPaint event is fired for the canvas using a wrong bg color
KIGFX::VIEW* view = m_preview->GetView(); KIGFX::VIEW* view = m_preview->GetView();
auto settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() ); auto settings = static_cast<KIGFX::SCH_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
m_preview->GetGAL()->SetClearColor( settings->GetBackgroundColor() );
SetBackgroundColour( *wxWHITE ); const COLOR4D& backgroundColor = settings->GetBackgroundColor();
SetForegroundColour( *wxBLACK ); const COLOR4D& foregroundColor = settings->GetCursorColor();
m_status = new wxStaticText( this, wxID_ANY, wxEmptyString ); m_preview->GetGAL()->SetClearColor( backgroundColor );
m_statusPanel = new wxPanel( this );
m_status = new wxStaticText( m_statusPanel, wxID_ANY, wxEmptyString );
m_statusSizer = new wxBoxSizer( wxVERTICAL ); m_statusSizer = new wxBoxSizer( wxVERTICAL );
m_statusSizer->Add( 0, 0, 1 ); // add a spacer m_statusSizer->Add( 0, 0, 1 ); // add a spacer
m_statusSizer->Add( m_status, 0, wxALIGN_CENTER ); m_statusSizer->Add( m_status, 0, wxALIGN_CENTER );
m_statusSizer->Add( 0, 0, 1 ); // add a spacer m_statusSizer->Add( 0, 0, 1 ); // add a spacer
m_statusPanel->SetSizer( m_statusSizer );
auto outer_sizer = new wxBoxSizer( wxVERTICAL ); // Give the status panel the same color scheme as the canvas so it isn't jarring when switched to
outer_sizer->Add( m_preview, 1, wxTOP | wxEXPAND, 5 ); m_statusPanel->SetBackgroundColour( backgroundColor.ToColour() );
outer_sizer->Add( m_statusSizer, 1, wxALIGN_CENTER ); m_statusPanel->SetForegroundColour( foregroundColor.ToColour() );
m_statusSizer->ShowItems( false ); // Give the preview panel a small top border to align its top with the status panel,
// and give the status panel a small bottom border to align its bottom with the preview
// panel.
m_outerSizer = new wxBoxSizer( wxVERTICAL );
m_outerSizer->Add( m_preview, 1, wxTOP | wxEXPAND, 5 );
m_outerSizer->Add( m_statusPanel, 1, wxBOTTOM | wxEXPAND, 5 );
SetSizer( outer_sizer ); // Hide the status panel to start
m_statusPanel->Hide();
SetSizer( m_outerSizer );
Layout();
Connect( wxEVT_SIZE, wxSizeEventHandler( SYMBOL_PREVIEW_WIDGET::onSize ), NULL, this ); Connect( wxEVT_SIZE, wxSizeEventHandler( SYMBOL_PREVIEW_WIDGET::onSize ), NULL, this );
} }
@ -100,8 +112,8 @@ SYMBOL_PREVIEW_WIDGET::~SYMBOL_PREVIEW_WIDGET()
void SYMBOL_PREVIEW_WIDGET::SetStatusText( wxString const& aText ) void SYMBOL_PREVIEW_WIDGET::SetStatusText( wxString const& aText )
{ {
m_status->SetLabel( aText ); m_status->SetLabel( aText );
m_statusSizer->ShowItems( true );
m_preview->Hide(); m_preview->Hide();
m_statusPanel->Show();
Layout(); Layout();
} }
@ -187,7 +199,7 @@ void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit, i
if( !m_preview->IsShown() ) if( !m_preview->IsShown() )
{ {
m_preview->Show(); m_preview->Show();
m_statusSizer->ShowItems( false ); m_statusPanel->Hide();
Layout(); // Ensure panel size is up to date. Layout(); // Ensure panel size is up to date.
} }
@ -235,5 +247,6 @@ void SYMBOL_PREVIEW_WIDGET::DisplayPart( LIB_PART* aPart, int aUnit, int aConver
m_preview->ForceRefresh(); m_preview->ForceRefresh();
m_preview->Show(); m_preview->Show();
m_statusSizer->ShowItems( false ); m_statusPanel->Hide();
Layout();
} }

View File

@ -73,7 +73,9 @@ private:
EDA_DRAW_PANEL_GAL* m_preview; EDA_DRAW_PANEL_GAL* m_preview;
wxStaticText* m_status; wxStaticText* m_status;
wxPanel* m_statusPanel;
wxSizer* m_statusSizer; wxSizer* m_statusSizer;
wxSizer* m_outerSizer;
/** a local copy of the LIB_ALIAS or the LIB_PART to display on the canvas /** a local copy of the LIB_ALIAS or the LIB_PART to display on the canvas
*/ */