Try and unify the background colors between panels and platforms.

Also moves to WX_GRID to get rid of some wxGrid bugs, and moves the
provision of attrs to the GRID_TABLE (as those applied to the grid
are ignored when a table is specified).

Fixes https://gitlab.com/kicad/code/kicad/issues/5260
This commit is contained in:
Jeff Young 2020-09-04 18:42:04 +01:00
parent c1889cefcf
commit 08dee31d9e
9 changed files with 91 additions and 32 deletions

View File

@ -80,11 +80,11 @@ wxString TOOL_ACTION::GetMenuItem() const
} }
wxString TOOL_ACTION::GetDescription() const wxString TOOL_ACTION::GetDescription( bool aIncludeHotkey ) const
{ {
wxString tooltip = wxGetTranslation( m_tooltip ); wxString tooltip = wxGetTranslation( m_tooltip );
if( GetHotKey() ) if( aIncludeHotkey && GetHotKey() )
tooltip += wxString::Format( wxT( " (%s)" ), KeyNameFromKeyCode( GetHotKey() ) ); tooltip += wxString::Format( wxT( " (%s)" ), KeyNameFromKeyCode( GetHotKey() ) );
return tooltip; return tooltip;

View File

@ -291,7 +291,7 @@ void WIDGET_HOTKEY_LIST::UpdateFromClientData()
const HOTKEY& changed_hk = hkdata->GetChangedHotkey(); const HOTKEY& changed_hk = hkdata->GetChangedHotkey();
wxString label = changed_hk.m_Actions[ 0 ]->GetLabel(); wxString label = changed_hk.m_Actions[ 0 ]->GetLabel();
wxString key_text = KeyNameFromKeyCode( changed_hk.m_EditKeycode ); wxString key_text = KeyNameFromKeyCode( changed_hk.m_EditKeycode );
wxString description = changed_hk.m_Actions[ 0 ]->GetDescription(); wxString description = changed_hk.m_Actions[ 0 ]->GetDescription( false );
if( label.IsEmpty() ) if( label.IsEmpty() )
label = changed_hk.m_Actions[ 0 ]->GetName(); label = changed_hk.m_Actions[ 0 ]->GetName();

View File

@ -48,6 +48,12 @@ WX_GRID::~WX_GRID()
void WX_GRID::SetColLabelSize( int aHeight ) void WX_GRID::SetColLabelSize( int aHeight )
{ {
if( aHeight == 0 )
{
wxGrid::SetColLabelSize( 0 );
return;
}
// correct wxFormBuilder height for large fonts // correct wxFormBuilder height for large fonts
wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
int minHeight = guiFont.GetPixelSize().y + 2 * MIN_GRIDCELL_MARGIN; int minHeight = guiFont.GetPixelSize().y + 2 * MIN_GRIDCELL_MARGIN;

View File

@ -122,7 +122,7 @@ public:
wxString GetLabel() const; wxString GetLabel() const;
wxString GetMenuItem() const; wxString GetMenuItem() const;
wxString GetDescription() const; wxString GetDescription( bool aIncludeHotkey = true ) const;
TOOL_ACTION_SCOPE GetScope() const { return m_scope; } TOOL_ACTION_SCOPE GetScope() const { return m_scope; }

View File

@ -33,12 +33,56 @@
#include <tools/pcb_actions.h> #include <tools/pcb_actions.h>
#include <widgets/bitmap_toggle.h> #include <widgets/bitmap_toggle.h>
#include <widgets/color_swatch.h> #include <widgets/color_swatch.h>
#include <widgets/wx_grid.h>
#include <widgets/grid_bitmap_toggle.h> #include <widgets/grid_bitmap_toggle.h>
#include <widgets/grid_color_swatch_helpers.h> #include <widgets/grid_color_swatch_helpers.h>
#include <widgets/grid_text_helpers.h> #include <widgets/grid_text_helpers.h>
#include <widgets/indicator_icon.h> #include <widgets/indicator_icon.h>
NET_GRID_TABLE::NET_GRID_TABLE( PCB_BASE_FRAME* aFrame, wxColor aBackgroundColor ) :
wxGridTableBase(),
m_frame( aFrame )
{
m_defaultAttr = new wxGridCellAttr;
m_defaultAttr->SetBackgroundColour( aBackgroundColor );
m_labelAttr = new wxGridCellAttr;
m_labelAttr->SetRenderer( new GRID_CELL_ESCAPED_TEXT_RENDERER );
m_labelAttr->SetBackgroundColour( aBackgroundColor );
}
NET_GRID_TABLE::~NET_GRID_TABLE()
{
m_defaultAttr->DecRef();
m_labelAttr->DecRef();
}
wxGridCellAttr* NET_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind )
{
switch( aCol )
{
case COL_COLOR:
m_defaultAttr->IncRef();
return m_defaultAttr;
case COL_VISIBILITY:
m_defaultAttr->IncRef();
return m_defaultAttr;
case COL_LABEL:
m_labelAttr->IncRef();
return m_labelAttr;
default:
wxFAIL;
return nullptr;
}
}
wxString NET_GRID_TABLE::GetValue( int aRow, int aCol ) wxString NET_GRID_TABLE::GetValue( int aRow, int aCol )
{ {
wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() ); wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
@ -219,8 +263,6 @@ void NET_GRID_TABLE::Rebuild()
{ {
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_nets.size() ); wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_nets.size() );
GetView()->ProcessTableMessage( msg ); GetView()->ProcessTableMessage( msg );
GetView()->AutoSizeColumn( NET_GRID_TABLE::COL_LABEL );
} }
} }
@ -346,6 +388,8 @@ APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFo
int pointSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize(); int pointSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ); int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
m_layerPanelColour = m_panelLayers->GetBackgroundColour().ChangeLightness( 110 );
m_layersOuterSizer = new wxBoxSizer( wxVERTICAL ); m_layersOuterSizer = new wxBoxSizer( wxVERTICAL );
m_windowLayers->SetSizer( m_layersOuterSizer ); m_windowLayers->SetSizer( m_layersOuterSizer );
m_windowLayers->SetScrollRate( 0, 5 ); m_windowLayers->SetScrollRate( 0, 5 );
@ -438,18 +482,20 @@ APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFo
new GRID_CELL_COLOR_RENDERER( m_frame, SWATCH_SMALL ), new GRID_CELL_COLOR_RENDERER( m_frame, SWATCH_SMALL ),
new GRID_CELL_COLOR_SELECTOR( m_frame, m_netsGrid ) ); new GRID_CELL_COLOR_SELECTOR( m_frame, m_netsGrid ) );
wxGridCellAttr* attr = new wxGridCellAttr; m_netsTable = new NET_GRID_TABLE( m_frame, m_panelNets->GetBackgroundColour() );
attr->SetRenderer( new GRID_CELL_ESCAPED_TEXT_RENDERER ); m_netsGrid->SetTable( m_netsTable, true );
m_netsGrid->SetColAttr( NET_GRID_TABLE::COL_LABEL, attr ); m_netsGrid->SetColLabelSize( 0 );
m_netsTable = new NET_GRID_TABLE( m_frame );
m_netsGrid->SetTable( m_netsTable, true, wxGrid::wxGridSelectRows );
m_netsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
m_netsGrid->SetSelectionForeground( m_netsGrid->GetDefaultCellTextColour() ); m_netsGrid->SetSelectionForeground( m_netsGrid->GetDefaultCellTextColour() );
m_netsGrid->SetSelectionBackground( m_netsGrid->GetBackgroundColour() ); m_netsGrid->SetSelectionBackground( m_panelNets->GetBackgroundColour() );
const int cellPadding = 6; const int cellPadding = 6;
const int rowHeightPadding = 4; #ifdef __WXMAC__
const int rowHeightPadding = 5;
#else
const int rowHeightPadding = 3;
#endif
wxSize size = ConvertDialogToPixels( SWATCH_SIZE_SMALL_DU ); wxSize size = ConvertDialogToPixels( SWATCH_SIZE_SMALL_DU );
m_netsGrid->SetColSize( NET_GRID_TABLE::COL_COLOR, size.x + cellPadding ); m_netsGrid->SetColSize( NET_GRID_TABLE::COL_COLOR, size.x + cellPadding );
@ -1001,7 +1047,6 @@ void APPEARANCE_CONTROLS::rebuildLayers()
wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
panel->SetSizer( sizer ); panel->SetSizer( sizer );
m_layerPanelColour = panel->GetBackgroundColour().ChangeLightness( 110 );
panel->SetBackgroundColour( m_layerPanelColour ); panel->SetBackgroundColour( m_layerPanelColour );
aSetting->visible = visible[layer]; aSetting->visible = visible[layer];

View File

@ -79,10 +79,8 @@ public:
} }
public: public:
NET_GRID_TABLE( PCB_BASE_FRAME* aFrame ) : NET_GRID_TABLE( PCB_BASE_FRAME* aFrame, wxColor aBackgroundColor );
wxGridTableBase(), ~NET_GRID_TABLE();
m_frame( aFrame )
{}
int GetNumberRows() override int GetNumberRows() override
{ {
@ -94,6 +92,8 @@ public:
return COL_SIZE; return COL_SIZE;
} }
wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind ) override;
wxString GetValue( int aRow, int aCol ) override; wxString GetValue( int aRow, int aCol ) override;
void SetValue( int aRow, int aCol, const wxString& aValue ) override; void SetValue( int aRow, int aCol, const wxString& aValue ) override;
@ -127,6 +127,9 @@ private:
PCB_BASE_FRAME* m_frame; PCB_BASE_FRAME* m_frame;
std::vector<NET_GRID_ENTRY> m_nets; std::vector<NET_GRID_ENTRY> m_nets;
wxGridCellAttr* m_defaultAttr;
wxGridCellAttr* m_labelAttr;
}; };

View File

@ -5,6 +5,8 @@
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#include "widgets/wx_grid.h"
#include "appearance_controls_base.h" #include "appearance_controls_base.h"
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -12,7 +14,7 @@
APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name ) APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name )
{ {
this->SetFont( wxFont( 10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) ); this->SetFont( wxFont( 10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) );
this->SetMinSize( wxSize( 160,360 ) ); this->SetMinSize( wxSize( 200,360 ) );
m_sizerOuter = new wxBoxSizer( wxVERTICAL ); m_sizerOuter = new wxBoxSizer( wxVERTICAL );
@ -120,7 +122,7 @@ APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID
bSizer192->Add( bSizer17, 0, wxEXPAND, 5 ); bSizer192->Add( bSizer17, 0, wxEXPAND, 5 );
m_netsGrid = new wxGrid( m_panelNets, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); m_netsGrid = new WX_GRID( m_panelNets, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
// Grid // Grid
m_netsGrid->CreateGrid( 5, 3 ); m_netsGrid->CreateGrid( 5, 3 );
@ -130,7 +132,9 @@ APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID
m_netsGrid->SetMargins( 0, 0 ); m_netsGrid->SetMargins( 0, 0 );
// Columns // Columns
m_netsGrid->AutoSizeColumns(); m_netsGrid->SetColSize( 0, 40 );
m_netsGrid->SetColSize( 1, 40 );
m_netsGrid->SetColSize( 2, 400 );
m_netsGrid->EnableDragColMove( false ); m_netsGrid->EnableDragColMove( false );
m_netsGrid->EnableDragColSize( false ); m_netsGrid->EnableDragColSize( false );
m_netsGrid->SetColLabelSize( 0 ); m_netsGrid->SetColLabelSize( 0 );
@ -145,7 +149,7 @@ APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID
// Cell Defaults // Cell Defaults
m_netsGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); m_netsGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
bSizer192->Add( m_netsGrid, 1, wxALL|wxEXPAND, 5 ); bSizer192->Add( m_netsGrid, 0, wxALL|wxEXPAND, 5 );
m_panelNets->SetSizer( bSizer192 ); m_panelNets->SetSizer( bSizer192 );
@ -274,7 +278,6 @@ APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID
this->SetSizer( m_sizerOuter ); this->SetSizer( m_sizerOuter );
this->Layout(); this->Layout();
m_sizerOuter->Fit( this );
// Connect Events // Connect Events
this->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ) ); this->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( APPEARANCE_CONTROLS_BASE::OnSetFocus ) );

View File

@ -40,10 +40,10 @@
<property name="hidden">0</property> <property name="hidden">0</property>
<property name="id">wxID_ANY</property> <property name="id">wxID_ANY</property>
<property name="maximum_size"></property> <property name="maximum_size"></property>
<property name="minimum_size">160,360</property> <property name="minimum_size">200,360</property>
<property name="name">APPEARANCE_CONTROLS_BASE</property> <property name="name">APPEARANCE_CONTROLS_BASE</property>
<property name="pos"></property> <property name="pos"></property>
<property name="size">-1,-1</property> <property name="size">215,400</property>
<property name="subclass">; ; forward_declare</property> <property name="subclass">; ; forward_declare</property>
<property name="tooltip"></property> <property name="tooltip"></property>
<property name="window_extra_style"></property> <property name="window_extra_style"></property>
@ -1217,7 +1217,7 @@
<object class="sizeritem" expanded="1"> <object class="sizeritem" expanded="1">
<property name="border">5</property> <property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property> <property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property> <property name="proportion">0</property>
<object class="wxGrid" expanded="1"> <object class="wxGrid" expanded="1">
<property name="BottomDockable">1</property> <property name="BottomDockable">1</property>
<property name="LeftDockable">1</property> <property name="LeftDockable">1</property>
@ -1227,7 +1227,7 @@
<property name="aui_name"></property> <property name="aui_name"></property>
<property name="aui_position"></property> <property name="aui_position"></property>
<property name="aui_row"></property> <property name="aui_row"></property>
<property name="autosize_cols">1</property> <property name="autosize_cols">0</property>
<property name="autosize_rows">0</property> <property name="autosize_rows">0</property>
<property name="best_size"></property> <property name="best_size"></property>
<property name="bg"></property> <property name="bg"></property>
@ -1245,7 +1245,7 @@
<property name="col_label_values"></property> <property name="col_label_values"></property>
<property name="col_label_vert_alignment">wxALIGN_CENTER</property> <property name="col_label_vert_alignment">wxALIGN_CENTER</property>
<property name="cols">3</property> <property name="cols">3</property>
<property name="column_sizes"></property> <property name="column_sizes">40,40,400</property>
<property name="context_help"></property> <property name="context_help"></property>
<property name="context_menu">1</property> <property name="context_menu">1</property>
<property name="default_pane">0</property> <property name="default_pane">0</property>
@ -1294,7 +1294,7 @@
<property name="rows">5</property> <property name="rows">5</property>
<property name="show">1</property> <property name="show">1</property>
<property name="size"></property> <property name="size"></property>
<property name="subclass">; ; forward_declare</property> <property name="subclass">WX_GRID; widgets/wx_grid.h; forward_declare</property>
<property name="toolbar_pane">0</property> <property name="toolbar_pane">0</property>
<property name="tooltip"></property> <property name="tooltip"></property>
<property name="window_extra_style"></property> <property name="window_extra_style"></property>

View File

@ -9,6 +9,8 @@
#include <wx/artprov.h> #include <wx/artprov.h>
#include <wx/xrc/xmlres.h> #include <wx/xrc/xmlres.h>
class WX_GRID;
#include <wx/scrolwin.h> #include <wx/scrolwin.h>
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
#include <wx/font.h> #include <wx/font.h>
@ -65,7 +67,7 @@ class APPEARANCE_CONTROLS_BASE : public wxPanel
wxStaticText* m_staticTextNets; wxStaticText* m_staticTextNets;
wxTextCtrl* m_txtNetFilter; wxTextCtrl* m_txtNetFilter;
wxBitmapButton* m_btnNetInspector; wxBitmapButton* m_btnNetInspector;
wxGrid* m_netsGrid; WX_GRID* m_netsGrid;
wxPanel* m_panelNetclasses; wxPanel* m_panelNetclasses;
wxStaticText* m_staticText14; wxStaticText* m_staticText14;
wxBitmapButton* m_btnConfigureNetClasses; wxBitmapButton* m_btnConfigureNetClasses;
@ -95,7 +97,7 @@ class APPEARANCE_CONTROLS_BASE : public wxPanel
public: public:
APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); APPEARANCE_CONTROLS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 215,400 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
~APPEARANCE_CONTROLS_BASE(); ~APPEARANCE_CONTROLS_BASE();
void m_netsTabSplitterOnIdle( wxIdleEvent& ) void m_netsTabSplitterOnIdle( wxIdleEvent& )