Make UNIT_BINDER sensitive to parent frame user unit changes.
Fixes https://gitlab.com/kicad/code/kicad/issues/4243
This commit is contained in:
parent
fe383efb93
commit
5bc6ad9786
|
@ -38,12 +38,12 @@ wxDEFINE_EVENT( DELAY_FOCUS, wxCommandEvent );
|
|||
UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent,
|
||||
wxStaticText* aLabel, wxWindow* aValue, wxStaticText* aUnitLabel,
|
||||
bool aUseMils, bool allowEval ) :
|
||||
m_frame( aParent ),
|
||||
m_label( aLabel ),
|
||||
m_value( aValue ),
|
||||
m_unitLabel( aUnitLabel ),
|
||||
m_eval( aParent->GetUserUnits(), aUseMils )
|
||||
{
|
||||
// Fix the units (to the current units) for the life of the binder
|
||||
m_units = aParent->GetUserUnits();
|
||||
m_useMils = aUseMils;
|
||||
m_allowEval = allowEval && dynamic_cast<wxTextEntry*>( m_value );
|
||||
|
@ -63,6 +63,14 @@ UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent,
|
|||
m_value->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ), NULL, this );
|
||||
m_value->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( UNIT_BINDER::onKillFocus ), NULL, this );
|
||||
Connect( DELAY_FOCUS, wxCommandEventHandler( UNIT_BINDER::delayedFocusHandler ), NULL, this );
|
||||
|
||||
m_frame->Connect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ), nullptr, this );
|
||||
}
|
||||
|
||||
|
||||
UNIT_BINDER::~UNIT_BINDER()
|
||||
{
|
||||
m_frame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ), nullptr, this );
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,6 +82,18 @@ void UNIT_BINDER::SetUnits( EDA_UNITS aUnits, bool aUseMils )
|
|||
}
|
||||
|
||||
|
||||
void UNIT_BINDER::onUnitsChanged( wxCommandEvent& aEvent )
|
||||
{
|
||||
int temp = (int) GetValue();
|
||||
|
||||
SetUnits( m_frame->GetUserUnits(), m_useMils );
|
||||
|
||||
SetValue( temp );
|
||||
|
||||
aEvent.Skip();
|
||||
}
|
||||
|
||||
|
||||
void UNIT_BINDER::onSetFocus( wxFocusEvent& aEvent )
|
||||
{
|
||||
auto textEntry = dynamic_cast<wxTextEntry*>( m_value );
|
||||
|
|
|
@ -56,6 +56,8 @@ public:
|
|||
wxStaticText* aLabel, wxWindow* aValue, wxStaticText* aUnitLabel,
|
||||
bool aUseMils = false, bool aAllowEval = true );
|
||||
|
||||
~UNIT_BINDER() override;
|
||||
|
||||
/**
|
||||
* Function SetUnits
|
||||
* Normally not needed (as the UNIT_BINDER inherits from the parent frame), but can be
|
||||
|
@ -148,6 +150,10 @@ protected:
|
|||
void onKillFocus( wxFocusEvent& aEvent );
|
||||
void delayedFocusHandler( wxCommandEvent& aEvent );
|
||||
|
||||
void onUnitsChanged( wxCommandEvent& aEvent );
|
||||
|
||||
EDA_DRAW_FRAME* m_frame;
|
||||
|
||||
///> The bound widgets
|
||||
wxStaticText* m_label;
|
||||
wxWindow* m_value;
|
||||
|
|
Loading…
Reference in New Issue