Move GUI font code to common.

This also allows the Mac fixes for font facenames to be more
compartmentalized.

Fixes https://gitlab.com/kicad/code/kicad/issues/8657
This commit is contained in:
Jeff Young 2021-06-29 18:27:05 +01:00
parent 64f07ea9c6
commit 0c2ac9a711
23 changed files with 64 additions and 64 deletions

View File

@ -136,9 +136,7 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, NETCLASSE
attr->SetEditor( new GRID_CELL_ICON_TEXT_POPUP( g_lineStyleIcons, g_lineStyleNames ) );
m_netclassGrid->SetColAttr( GRID_LINESTYLE, attr );
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_colorDefaultHelpText->SetFont( infoFont );
m_colorDefaultHelpText->SetFont( KIUI::GetInfoFont() );
}
else
{

View File

@ -50,14 +50,7 @@ SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString
{
// Set a monospace font with a tab width of 4. This is the closest we can get to having
// Scintilla mimic the stroke font's tab positioning.
int size = wxNORMAL_FONT->GetPointSize();
wxFont fixedFont( size, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL );
#ifdef __WXMAC__
// I think wxFONTFAMILY_TELETYPE worked on wxWidgets 3.0, but it doesn't on 3.1. Set a
// monospaced font by hand. (https://trac.wxwidgets.org/ticket/19210)
fixedFont.SetFaceName( "Menlo" );
#endif
wxFont fixedFont = KIUI::GetMonospacedUIFont();
for( size_t i = 0; i < wxSTC_STYLE_MAX; ++i )
m_te->StyleSetFont( i, fixedFont );

View File

@ -26,6 +26,7 @@
#include <algorithm>
#include <dialog_shim.h>
#include <pgm_base.h>
#include <wx/settings.h>
int KIUI::GetStdMargin()
{
@ -71,6 +72,37 @@ wxSize KIUI::GetTextSize( const wxString& aSingleLine, wxWindow* aWindow )
}
wxFont KIUI::GetMonospacedUIFont()
{
static int guiFontSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
wxFont font( guiFontSize, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL );
#ifdef __WXMAC__
// https://trac.wxwidgets.org/ticket/19210
if( font.GetFaceName().IsEmpty() )
font.SetFaceName( "Menlo" );
#endif
return font;
}
wxFont KIUI::GetInfoFont()
{
wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
font.SetSymbolicSize( wxFONTSIZE_SMALL );
#ifdef __WXMAC__
// https://trac.wxwidgets.org/ticket/19210
if( font.GetFaceName().IsEmpty() )
font.SetFaceName( "Lucida Grande" );
#endif
return font;
}
bool KIUI::EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
{
wxWindow* window = aCtrl->GetParent();

View File

@ -132,11 +132,9 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
wxStaticLine* staticline1 = new wxStaticLine( bottomPanel );
panelSizer->Add( staticline1, 0, wxEXPAND, 5 );
wxFont statusFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
statusFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_statusLine1->SetFont( statusFont );
m_statusLine2->SetFont( statusFont );
m_statusLine3->SetFont( statusFont );
m_statusLine1->SetFont( KIUI::GetInfoFont() );
m_statusLine2->SetFont( KIUI::GetInfoFont() );
m_statusLine3->SetFont( KIUI::GetInfoFont() );
// Add buttons:
auto buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
@ -883,8 +881,7 @@ void CVPCB_MAINFRAME::BuildFootprintsListBox()
if( m_footprintListBox == NULL )
{
m_footprintListBox = new FOOTPRINTS_LISTBOX( this, ID_CVPCB_FOOTPRINT_LIST );
m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
m_footprintListBox->SetFont( KIUI::GetMonospacedUIFont() );
}
m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL, wxEmptyString,
@ -902,8 +899,7 @@ void CVPCB_MAINFRAME::BuildSymbolsListBox()
if( m_symbolsListBox == NULL )
{
m_symbolsListBox = new COMPONENTS_LISTBOX( this, ID_CVPCB_COMPONENT_LIST );
m_symbolsListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
m_symbolsListBox->SetFont( KIUI::GetMonospacedUIFont() );
}
m_symbolsListBox->m_ComponentList.Clear();
@ -937,8 +933,7 @@ void CVPCB_MAINFRAME::BuildLibrariesListBox()
if( m_librariesListBox == NULL )
{
m_librariesListBox = new LIBRARY_LISTBOX( this, ID_CVPCB_LIBRARY_LIST );
m_librariesListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
m_librariesListBox->SetFont( KIUI::GetMonospacedUIFont() );
}
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();

View File

@ -115,7 +115,7 @@ DIALOG_LABEL_EDITOR::DIALOG_LABEL_EDITOR( SCH_EDIT_FRAME* aParent, SCH_TEXT* aTe
if( m_CurrentText->Type() == SCH_GLOBAL_LABEL_T )
{
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
wxFont infoFont = KIUI::GetInfoFont();
infoFont.SetSymbolicSize( wxFONTSIZE_X_SMALL );
m_note1->SetFont( infoFont );
m_note2->SetFont( infoFont );

View File

@ -44,9 +44,7 @@ DIALOG_LIB_EDIT_TEXT::DIALOG_LIB_EDIT_TEXT( SYMBOL_EDIT_FRAME* aParent, LIB_TEXT
m_TextValueSelectButton->Hide();
m_PowerComponentValues->Show( false );
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_PowerComponentValues->SetFont( infoFont );
m_PowerComponentValues->SetFont( KIUI::GetInfoFont() );
SetInitialFocus( m_TextCtrl );
m_StyledTextCtrl->Show( false );

View File

@ -81,9 +81,7 @@ DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_S
m_bpMoveDown->SetBitmap( KiBitmap( BITMAPS::small_down ) );
// Set font sizes
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_hierarchicalPathLabel->SetFont( infoFont );
m_hierarchicalPathLabel->SetFont( KIUI::GetInfoFont() );
// wxFormBuilder doesn't include this event...
m_grid->Connect( wxEVT_GRID_CELL_CHANGING,

View File

@ -37,9 +37,7 @@ PANEL_EESCHEMA_DISPLAY_OPTIONS::PANEL_EESCHEMA_DISPLAY_OPTIONS( SCH_EDIT_FRAME*
m_galOptionsSizer->Add( m_galOptsPanel, 1, wxEXPAND, 0 );
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_highlightColorNote->SetFont( infoFont );
m_highlightColorNote->SetFont( KIUI::GetInfoFont() );
}

View File

@ -56,9 +56,6 @@ PANEL_SETUP_PINMAP::PANEL_SETUP_PINMAP( wxWindow* aWindow, SCH_EDIT_FRAME* paren
m_parent = parent;
m_schematic = &parent->Schematic();
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
reBuildMatrixPanel();
}

View File

@ -1512,9 +1512,7 @@ void SIM_PLOT_FRAME::onShowNetlist( wxCommandEvent& event )
text->StyleSetBackground( wxSTC_STYLE_LINENUMBER, wxColour( 220, 220, 220 ) );
text->SetMarginType( MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER );
wxFont font = wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_TELETYPE,
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString );
text->StyleSetFont( wxSTC_STYLE_DEFAULT, font );
text->StyleSetFont( wxSTC_STYLE_DEFAULT, KIUI::GetMonospacedUIFont() );
text->SetWrapMode( wxSTC_WRAP_WORD );

View File

@ -27,6 +27,7 @@
#define UI_COMMON_H
#include <wx/string.h>
#include <wx/font.h>
class wxSize;
class wxTextCtrl;
@ -48,6 +49,10 @@ int GetStdMargin();
*/
wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow );
wxFont GetMonospacedUIFont();
wxFont GetInfoFont();
/**
* Set the minimum pixel width on a text control in order to make a text
* string be fully visible within it.

View File

@ -64,7 +64,7 @@ PROPERTIES_FRAME::PROPERTIES_FRAME( PL_EDITOR_FRAME* aParent ) :
m_stcText->SetUseHorizontalScrollBar( false );
m_scintillaTricks = new SCINTILLA_TRICKS( m_stcText, wxT( "{}" ), false );
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
wxFont infoFont = KIUI::GetInfoFont();
infoFont.SetSymbolicSize( wxFONTSIZE_X_SMALL );
m_staticTextSizeInfo->SetFont( infoFont );

View File

@ -73,9 +73,7 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_attenuator_list.push_back( new ATTENUATOR_SPLITTER() );
m_currAttenuator = m_attenuator_list[0];
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_staticTextAttMsg->SetFont( infoFont );
m_staticTextAttMsg->SetFont( KIUI::GetInfoFont() );
m_IadjUnitLabel->SetLabel( wxT( "µA" ) );

View File

@ -87,8 +87,7 @@ DIALOG_BOARD_STATISTICS::DIALOG_BOARD_STATISTICS( PCB_EDIT_FRAME* aParentFrame )
m_checkBoxSubtractHoles->SetValue( s_savedDialogState.subtractHoles );
// Make labels for grids
wxFont headingFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
headingFont.SetSymbolicSize( wxFONTSIZE_SMALL );
wxFont headingFont = KIUI::GetInfoFont();
m_gridComponents->SetCellValue( ROW_LABEL, COL_FRONT_SIDE, _( "Front Side" ) );
m_gridComponents->SetCellFont( ROW_LABEL, COL_FRONT_SIDE, headingFont );
m_gridComponents->SetCellValue( ROW_LABEL, COL_BOTTOM_SIDE, _( "Back Side" ) );

View File

@ -130,8 +130,7 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen
bLowerSizer3D->Add( m_previewPane, 1, wxEXPAND, 5 );
// Set font size for items showing long strings:
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
wxFont infoFont = KIUI::GetInfoFont();
#if __WXMAC__
m_allow90Label->SetFont( infoFont );
m_allow180Label->SetFont( infoFont );
@ -155,7 +154,9 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen
m_delayedFocusColumn = 0;
}
else if ( m_page == 1 )
{
SetInitialFocus( m_NetClearanceCtrl );
}
else
{
m_delayedFocusGrid = m_modelsGrid;

View File

@ -116,8 +116,7 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR( FO
m_FootprintNameCtrl->SetValidator( FOOTPRINT_NAME_VALIDATOR() );
// Set font sizes
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
wxFont infoFont = KIUI::GetInfoFont();
#if __WXMAC__
m_allow90Label->SetFont( infoFont );
m_allow180Label->SetFont( infoFont );

View File

@ -46,7 +46,7 @@ public:
m_sdbSizerOK->SetDefault();
m_choiceFpList->Append( aFpList );
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
wxFont infoFont = KIUI::GetInfoFont();
infoFont.SetSymbolicSize( wxFONTSIZE_X_SMALL );
m_multipleHint->SetFont( infoFont );

View File

@ -138,9 +138,7 @@ DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS( PCB_
m_LayerCtrl->Resync();
m_grid->SetCellHighlightPenWidth( 0 );
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_grid->SetDefaultCellFont( infoFont );
m_grid->SetDefaultCellFont( KIUI::GetInfoFont() );
m_sdbSizerButtonsOK->SetDefault();

View File

@ -127,9 +127,7 @@ DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS( PCB_EDIT
m_layerBox->SetUndefinedLayerName( INDETERMINATE_ACTION );
m_layerBox->Resync();
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_netclassGrid->SetDefaultCellFont( infoFont );
m_netclassGrid->SetDefaultCellFont( KIUI::GetInfoFont() );
buildNetclassesGrid();
m_netclassGrid->SetCellHighlightPenWidth( 0 );

View File

@ -183,8 +183,7 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, PAD* aPad
initValues();
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
wxFont infoFont = KIUI::GetInfoFont();
m_copperLayersLabel->SetFont( infoFont );
m_techLayersLabel->SetFont( infoFont );
m_parentInfo->SetFont( infoFont );

View File

@ -130,7 +130,7 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( PCB_BASE_EDIT_FRAME* aParent, BO
m_OrientCtrl->SetString( ii, wxString::Format( "%.1f", rot_list[ii] ) );
// Set font sizes
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
wxFont infoFont = KIUI::GetInfoFont();
infoFont.SetSymbolicSize( wxFONTSIZE_X_SMALL );
m_statusLine->SetFont( infoFont );

View File

@ -199,9 +199,7 @@ PANEL_FP_EDITOR_DEFAULTS::PANEL_FP_EDITOR_DEFAULTS( FOOTPRINT_EDIT_FRAME* aFrame
m_graphicsGrid->PushEventHandler( new GRID_TRICKS( m_graphicsGrid ) );
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_staticTextInfo->SetFont( infoFont );
m_staticTextInfo->SetFont( KIUI::GetInfoFont() );
}

View File

@ -51,9 +51,7 @@ PANEL_SETUP_CONSTRAINTS::PANEL_SETUP_CONSTRAINTS( PAGED_DIALOG* aParent, PCB_EDI
m_Frame = aFrame;
m_BrdSettings = &m_Frame->GetBoard()->GetDesignSettings();
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
m_stCircleToPolyWarning->SetFont( infoFont );
m_stCircleToPolyWarning->SetFont( KIUI::GetInfoFont() );
}