Improve grid cell editors appearance.
This commit is contained in:
parent
94847e89c3
commit
76b7cdd128
|
@ -34,6 +34,7 @@
|
|||
#include <pgm_base.h>
|
||||
#include <widgets/wx_grid.h>
|
||||
#include <widgets/grid_text_button_helpers.h>
|
||||
#include <widgets/grid_text_helpers.h>
|
||||
#include <widgets/std_bitmap_button.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <project.h>
|
||||
#include <grid_tricks.h>
|
||||
#include <widgets/std_bitmap_button.h>
|
||||
#include <widgets/grid_text_helpers.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
|
|
@ -39,35 +39,6 @@
|
|||
#include <wx/log.h>
|
||||
#include <wx/combo.h>
|
||||
|
||||
GRID_CELL_TEXT_EDITOR::GRID_CELL_TEXT_EDITOR() : wxGridCellTextEditor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GRID_CELL_TEXT_EDITOR::SetValidator( const wxValidator& validator )
|
||||
{
|
||||
// keep our own copy because wxGridCellTextEditor's is annoyingly private
|
||||
m_validator.reset( static_cast<wxValidator*>( validator.Clone() ) );
|
||||
|
||||
wxGridCellTextEditor::SetValidator( *m_validator );
|
||||
}
|
||||
|
||||
|
||||
void GRID_CELL_TEXT_EDITOR::StartingKey( wxKeyEvent& event )
|
||||
{
|
||||
if( m_validator )
|
||||
{
|
||||
m_validator.get()->SetWindow( Text() );
|
||||
m_validator.get()->ProcessEvent( event );
|
||||
}
|
||||
|
||||
if( event.GetSkipped() )
|
||||
{
|
||||
wxGridCellTextEditor::StartingKey( event );
|
||||
event.Skip( false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FOOTPRINT_NAME_VALIDATOR::FOOTPRINT_NAME_VALIDATOR( wxString* aValue ) :
|
||||
wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
|
||||
|
|
|
@ -41,16 +41,6 @@
|
|||
#include <eda_doc.h>
|
||||
|
||||
|
||||
static void setTextMargins( wxTextEntryBase* aEntry )
|
||||
{
|
||||
#if defined( __WXMSW__ )
|
||||
aEntry->SetMargins( 2, 2 );
|
||||
#elif defined( __WXGTK__ )
|
||||
aEntry->SetMargins( 0, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-------- Renderer ---------------------------------------------------------------------
|
||||
// None required; just render as normal text.
|
||||
|
||||
|
@ -69,7 +59,10 @@ wxString GRID_CELL_TEXT_BUTTON::GetValue() const
|
|||
|
||||
void GRID_CELL_TEXT_BUTTON::SetSize( const wxRect& aRect )
|
||||
{
|
||||
Combo()->SetSize( aRect, wxSIZE_ALLOW_MINUS_ONE );
|
||||
wxRect rect( aRect );
|
||||
WX_GRID::CellEditorTransformSizeRect( rect );
|
||||
|
||||
wxGridCellEditor::SetSize( rect );
|
||||
}
|
||||
|
||||
|
||||
|
@ -227,7 +220,7 @@ void GRID_CELL_SYMBOL_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
|
|||
wxEvtHandler* aEventHandler )
|
||||
{
|
||||
m_control = new TEXT_BUTTON_SYMBOL_CHOOSER( aParent, m_dlg, m_preselect );
|
||||
setTextMargins( Combo() );
|
||||
WX_GRID::CellEditorSetMargins( Combo() );
|
||||
|
||||
wxGridCellEditor::Create( aParent, aId, aEventHandler );
|
||||
}
|
||||
|
@ -295,7 +288,7 @@ void GRID_CELL_FPID_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
|
|||
wxEvtHandler* aEventHandler )
|
||||
{
|
||||
m_control = new TEXT_BUTTON_FP_CHOOSER( aParent, m_dlg, m_symbolNetlist, m_preselect );
|
||||
setTextMargins( Combo() );
|
||||
WX_GRID::CellEditorSetMargins( Combo() );
|
||||
|
||||
#if wxUSE_VALIDATORS
|
||||
// validate text in textctrl, if validator is set
|
||||
|
@ -347,7 +340,7 @@ void GRID_CELL_URL_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
|
|||
wxEvtHandler* aEventHandler )
|
||||
{
|
||||
m_control = new TEXT_BUTTON_URL( aParent, m_dlg, m_searchStack );
|
||||
setTextMargins( Combo() );
|
||||
WX_GRID::CellEditorSetMargins( Combo() );
|
||||
|
||||
#if wxUSE_VALIDATORS
|
||||
// validate text in textctrl, if validator is set
|
||||
|
@ -505,7 +498,7 @@ void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
|
|||
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, m_fileFilter,
|
||||
m_normalize, m_normalizeBasePath );
|
||||
|
||||
setTextMargins( Combo() );
|
||||
WX_GRID::CellEditorSetMargins( Combo() );
|
||||
|
||||
#if wxUSE_VALIDATORS
|
||||
// validate text in textctrl, if validator is set
|
||||
|
|
|
@ -21,9 +21,56 @@
|
|||
#include <string_utils.h>
|
||||
#include <wx/stc/stc.h>
|
||||
#include <widgets/grid_text_helpers.h>
|
||||
#include <widgets/wx_grid.h>
|
||||
#include <scintilla_tricks.h>
|
||||
|
||||
|
||||
//-------- GRID_CELL_TEXT_EDITOR ------------------------------------------------------
|
||||
//
|
||||
|
||||
GRID_CELL_TEXT_EDITOR::GRID_CELL_TEXT_EDITOR() : wxGridCellTextEditor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GRID_CELL_TEXT_EDITOR::SetValidator( const wxValidator& validator )
|
||||
{
|
||||
// keep our own copy because wxGridCellTextEditor's is annoyingly private
|
||||
m_validator.reset( static_cast<wxValidator*>( validator.Clone() ) );
|
||||
|
||||
wxGridCellTextEditor::SetValidator( *m_validator );
|
||||
}
|
||||
|
||||
|
||||
void GRID_CELL_TEXT_EDITOR::StartingKey( wxKeyEvent& event )
|
||||
{
|
||||
if( m_validator )
|
||||
{
|
||||
m_validator.get()->SetWindow( Text() );
|
||||
m_validator.get()->ProcessEvent( event );
|
||||
}
|
||||
|
||||
if( event.GetSkipped() )
|
||||
{
|
||||
wxGridCellTextEditor::StartingKey( event );
|
||||
event.Skip( false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GRID_CELL_TEXT_EDITOR::SetSize( const wxRect& aRect )
|
||||
{
|
||||
wxRect rect( aRect );
|
||||
WX_GRID::CellEditorTransformSizeRect( rect );
|
||||
|
||||
#if defined( __WXMSW__ )
|
||||
rect.Offset( 0, 1 );
|
||||
#endif
|
||||
|
||||
wxGridCellEditor::SetSize( rect );
|
||||
}
|
||||
|
||||
|
||||
//-------- GRID_CELL_ESCAPED_TEXT_RENDERER ------------------------------------------------------
|
||||
//
|
||||
|
||||
|
@ -69,9 +116,23 @@ GRID_CELL_STC_EDITOR::GRID_CELL_STC_EDITOR(
|
|||
{ }
|
||||
|
||||
|
||||
void GRID_CELL_STC_EDITOR::SetSize( const wxRect& aRect )
|
||||
{
|
||||
wxRect rect( aRect );
|
||||
WX_GRID::CellEditorTransformSizeRect( rect );
|
||||
|
||||
#if defined( __WXMSW__ )
|
||||
rect.Offset( -1, 1 );
|
||||
#endif
|
||||
|
||||
wxGridCellEditor::SetSize( rect );
|
||||
}
|
||||
|
||||
|
||||
void GRID_CELL_STC_EDITOR::Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler )
|
||||
{
|
||||
m_control = new wxStyledTextCtrl( aParent );
|
||||
m_control = new wxStyledTextCtrl( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
||||
wxBORDER_NONE );
|
||||
|
||||
stc_ctrl()->SetTabIndents( false );
|
||||
stc_ctrl()->SetBackSpaceUnIndents( false );
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <wx/tokenzr.h>
|
||||
#include <wx/dc.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/event.h> // Needed for textentry.h on MSW
|
||||
#include <wx/textentry.h>
|
||||
|
||||
#include <widgets/wx_grid.h>
|
||||
#include <widgets/ui_common.h>
|
||||
|
@ -39,6 +41,21 @@
|
|||
#define MIN_GRIDCELL_MARGIN FromDIP( 3 )
|
||||
|
||||
|
||||
void WX_GRID::CellEditorSetMargins( wxTextEntryBase* aEntry )
|
||||
{
|
||||
// This is consistent with wxGridCellTextEditor. But works differently across platforms or course.
|
||||
aEntry->SetMargins( 0, 0 );
|
||||
}
|
||||
|
||||
|
||||
void WX_GRID::CellEditorTransformSizeRect( wxRect& aRect )
|
||||
{
|
||||
#if defined( __WXMSW__ ) || defined( __WXGTK__ )
|
||||
aRect.Deflate( 2 );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
wxColour getBorderColour()
|
||||
{
|
||||
KIGFX::COLOR4D bg = wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK );
|
||||
|
|
|
@ -50,23 +50,6 @@
|
|||
#define LABELUSERFIELD_V 200
|
||||
|
||||
|
||||
/**
|
||||
* This class works around a bug in wxGrid where the first keystroke doesn't get sent through
|
||||
* the validator if the editor wasn't already open.
|
||||
*/
|
||||
class GRID_CELL_TEXT_EDITOR : public wxGridCellTextEditor
|
||||
{
|
||||
public:
|
||||
GRID_CELL_TEXT_EDITOR();
|
||||
|
||||
virtual void SetValidator( const wxValidator& validator ) override;
|
||||
virtual void StartingKey( wxKeyEvent& event ) override;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<wxValidator> m_validator;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This class provides a custom wxValidator object for limiting the allowable characters when
|
||||
* defining footprint names. Since the introduction of the PRETTY footprint library format,
|
||||
|
|
|
@ -29,6 +29,26 @@ class wxStyledTextCtrl;
|
|||
class wxStyledTextEvent;
|
||||
class SCINTILLA_TRICKS;
|
||||
|
||||
|
||||
/**
|
||||
* This class works around a bug in wxGrid where the first keystroke doesn't get sent through
|
||||
* the validator if the editor wasn't already open.
|
||||
*/
|
||||
class GRID_CELL_TEXT_EDITOR : public wxGridCellTextEditor
|
||||
{
|
||||
public:
|
||||
GRID_CELL_TEXT_EDITOR();
|
||||
|
||||
void SetSize( const wxRect& aRect ) override;
|
||||
|
||||
virtual void SetValidator( const wxValidator& validator ) override;
|
||||
virtual void StartingKey( wxKeyEvent& event ) override;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<wxValidator> m_validator;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A text renderer that can unescape text for display
|
||||
* This is useful where it's desired to keep the underlying storage escaped.
|
||||
|
@ -51,6 +71,7 @@ public:
|
|||
GRID_CELL_STC_EDITOR( bool aIgnoreCase,
|
||||
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> onCharFn );
|
||||
|
||||
void SetSize( const wxRect& aRect ) override;
|
||||
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
|
||||
|
||||
wxGridCellEditor* Clone() const override
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include <units_provider.h>
|
||||
#include <libeval/numeric_evaluator.h>
|
||||
|
||||
class wxTextEntryBase;
|
||||
|
||||
|
||||
class WX_GRID : public wxGrid
|
||||
{
|
||||
|
@ -158,6 +160,16 @@ public:
|
|||
DeleteRows( 0, GetNumberRows() );
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper function to set OS-specific margins for text-based cell editors.
|
||||
*/
|
||||
static void CellEditorSetMargins( wxTextEntryBase* aEntry );
|
||||
|
||||
/**
|
||||
* A helper function to tweak sizes of text-based cell editors depending on OS.
|
||||
*/
|
||||
static void CellEditorTransformSizeRect( wxRect& aRect );
|
||||
|
||||
protected:
|
||||
/**
|
||||
* A re-implementation of wxGrid::DrawColLabel which left-aligns the first column and draws
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
#include <pcb_base_frame.h>
|
||||
#include <footprint.h>
|
||||
#include "grid_layer_box_helpers.h"
|
||||
#include "widgets/grid_text_button_helpers.h"
|
||||
#include <widgets/grid_text_button_helpers.h>
|
||||
#include <widgets/grid_text_helpers.h>
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue