Centralise some UI constants, use in hotkey lists

There are lot of places where constants are used in the KiCad UI
as "magic numbers". The most common one is "5", used in many
wxFormBuilder and manual UI constructions as the margin.

This commit provides a place for all UI to look up shared
constants and other functions, to help create a consistent UI using
functions that provide meaning and intent to these magic numbers.
This commit is contained in:
John Beard 2018-10-03 11:02:43 +01:00 committed by Wayne Stambaugh
parent 0be9667c96
commit 3a9e7a496a
6 changed files with 83 additions and 11 deletions

View File

@ -196,6 +196,7 @@ set( COMMON_WIDGET_SRCS
widgets/stepped_slider.cpp
widgets/text_ctrl_eval.cpp
widgets/two_column_tree_list.cpp
widgets/ui_common.cpp
widgets/unit_binder.cpp
widgets/widget_hotkey_list.cpp
widgets/wx_grid.cpp

View File

@ -24,6 +24,7 @@
#include <dialog_hotkey_list.h>
#include <panel_hotkeys_editor.h>
#include <widgets/ui_common.h>
#include <wx/sizer.h>
#include <wx/button.h>
@ -32,18 +33,20 @@
DIALOG_LIST_HOTKEYS::DIALOG_LIST_HOTKEYS( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aDescList ):
DIALOG_SHIM( aParent, wxID_ANY, _( "Hotkey List" ) )
{
const auto margin = KIUI::GetStdMargin();
auto main_sizer = new wxBoxSizer( wxVERTICAL );
m_hk_list = new PANEL_HOTKEYS_EDITOR( aParent, this, true,
aDescList, aDescList, {} );
main_sizer->Add( m_hk_list, 1, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 5 );
main_sizer->Add( m_hk_list, 1, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, margin );
auto sdb_sizer = new wxStdDialogButtonSizer;
sdb_sizer->AddButton( new wxButton( this, wxID_OK ) );
sdb_sizer->Realize();
main_sizer->Add( sdb_sizer, 0, wxEXPAND | wxALL, 5 );
main_sizer->Add( sdb_sizer, 0, wxEXPAND | wxALL, margin );
SetSizer( main_sizer );

View File

@ -30,12 +30,11 @@
#include <wx/sizer.h>
#include <widgets/button_row_panel.h>
#include <widgets/ui_common.h>
static const wxSize default_dialog_size { 500, 350 };
static const wxSize min_dialog_size { -1, 350 };
static const int widget_margins = 5;
static const int side_margins = 10;
/**
* Helper function to add a filter box to a panel, with some
@ -70,18 +69,20 @@ PANEL_HOTKEYS_EDITOR::PANEL_HOTKEYS_EDITOR( EDA_BASE_FRAME* aFrame, wxWindow* aW
m_nickname( aNickname ),
m_hotkeyStore( aShowHotkeys )
{
const auto margin = KIUI::GetStdMargin();
auto mainSizer = new wxBoxSizer( wxVERTICAL );
// Sub-sizer for setting a wider side margin
// TODO: Can this be set by the parent widget- doesn't seem to be
// this panel's responsibility?
const int side_margins = 10; // seems to be hardcoded in wxFB
auto bMargins = new wxBoxSizer( wxVERTICAL );
auto filterSearch = CreateTextFilterBox( this, _( "Type filter text" ) );
bMargins->Add( filterSearch, 0, wxBOTTOM | wxEXPAND | wxTOP, widget_margins );
bMargins->Add( filterSearch, 0, wxBOTTOM | wxEXPAND | wxTOP, margin );
m_hotkeyListCtrl = new WIDGET_HOTKEY_LIST( this, m_hotkeyStore, m_readOnly );
bMargins->Add( m_hotkeyListCtrl, 1, wxALL | wxEXPAND, widget_margins );
bMargins->Add( m_hotkeyListCtrl, 1, wxALL | wxEXPAND, margin );
if( !m_readOnly )
installButtons( bMargins );
@ -139,7 +140,7 @@ void PANEL_HOTKEYS_EDITOR::installButtons( wxSizer* aSizer )
auto btnPanel = new BUTTON_ROW_PANEL( this, l_btn_defs, r_btn_defs );
aSizer->Add( btnPanel, 0, wxEXPAND | wxTOP, widget_margins );
aSizer->Add( btnPanel, 0, wxEXPAND | wxTOP, KIUI::GetStdMargin() );
}

View File

@ -22,6 +22,7 @@
*/
#include <widgets/button_row_panel.h>
#include <widgets/ui_common.h>
#include <wx/button.h>
#include <wx/sizer.h>
@ -37,7 +38,7 @@ BUTTON_ROW_PANEL::BUTTON_ROW_PANEL( wxWindow* aWindow,
addButtons( true, aLeftBtns );
// add the spacer
m_sizer->Add( 0, 0, 1, wxEXPAND, 5 );
m_sizer->Add( 0, 0, 1, wxEXPAND, KIUI::GetStdMargin() );
addButtons( false, aRightBtns );
@ -48,9 +49,7 @@ BUTTON_ROW_PANEL::BUTTON_ROW_PANEL( wxWindow* aWindow,
void BUTTON_ROW_PANEL::addButtons( bool aLeft, const BTN_DEF_LIST& aDefs )
{
// The "normal" KiCad margin magic number
// TODO: Get this from somewhere
const int btn_margin = 5;
const int btn_margin = KIUI::GetStdMargin();
// No button expands to fill horizontally
const int btn_proportion = 0;

View File

@ -0,0 +1,27 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <widgets/ui_common.h>
int KIUI::GetStdMargin()
{
// This is the value used in (most) wxFB dialogs
return 5;
}

View File

@ -0,0 +1,41 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file ui_common.h
* Functions to provide common constants and other functions to assist
* in making a consistent UI
*/
#ifndef UI_COMMON_H
#define UI_COMMON_H
namespace KIUI
{
/**
* Get the standard margin around a widget in the KiCad UI
* @return margin in pixels
*/
int GetStdMargin();
}
#endif // UI_COMMON_H