KiCad PCB EDA Suite
INCREMENTAL_TEXT_CTRL Class Referenceabstract

Class that governs a textual control holding a number that can be incremented/decremented according to some scheme (often just a constant step). More...

#include <incremental_text_ctrl.h>

Inheritance diagram for INCREMENTAL_TEXT_CTRL:
SPIN_INCREMENTAL_TEXT_CTRL

Public Types

using STEP_FUNCTION = std::function< double(bool aUp, double aCurrVal)>
 A callable object type that can be used to provide a step value. More...
 

Public Member Functions

 INCREMENTAL_TEXT_CTRL ()
 
virtual ~INCREMENTAL_TEXT_CTRL ()
 
void SetValue (double aValue)
 Set the value of the text control, but obey the limits currently set. More...
 
double GetValue ()
 Get the current value of the control. More...
 
void SetStep (double aMin, double aMax, STEP_FUNCTION aNewFunc)
 Function SetStep() More...
 
void SetStep (double aMin, double aMax, double aStep)
 Function SetStep() More...
 
void SetPrecision (int aPrecision)
 Set the number of decimal places to display. More...
 

Protected Member Functions

void incrementCtrlBy (double aInc)
 Increment the control by the given amount. More...
 
void incrementCtrl (bool aUp)
 Single increment up or down by one step. More...
 
void updateTextValue ()
 Update the text control value with the current value, clamping to limits as needed. More...
 
virtual void setTextCtrl (const wxString &aVal)=0
 Set the text control string value after an increment. More...
 
virtual wxString getCtrlText () const =0
 

Private Attributes

double m_minVal
 
double m_maxVal
 Current value of the control. More...
 
double m_currentValue
 Precision to display. More...
 
int m_precision
 The function used to determine the step. More...
 
STEP_FUNCTION m_stepFunc
 

Detailed Description

Class that governs a textual control holding a number that can be incremented/decremented according to some scheme (often just a constant step).

Definition at line 38 of file incremental_text_ctrl.h.

Member Typedef Documentation

using INCREMENTAL_TEXT_CTRL::STEP_FUNCTION = std::function<double(bool aUp, double aCurrVal)>

A callable object type that can be used to provide a step value.

Client can provide one of these to use for implementing non-linear stepping, or stepping based on external parameters, such as unit selection.

Parameters
aUptrue if the next step is upwards
aCurrValthe current value of the control

Definition at line 51 of file incremental_text_ctrl.h.

Constructor & Destructor Documentation

INCREMENTAL_TEXT_CTRL::INCREMENTAL_TEXT_CTRL ( )

Definition at line 49 of file incremental_text_ctrl.cpp.

49  :
50  m_minVal( 0.0 ),
51  m_maxVal( 1.0 ),
52  m_currentValue( 0.0 ),
53  m_precision( 4 )
54 {}
double m_maxVal
Current value of the control.
double m_currentValue
Precision to display.
int m_precision
The function used to determine the step.
virtual INCREMENTAL_TEXT_CTRL::~INCREMENTAL_TEXT_CTRL ( )
inlinevirtual

Definition at line 55 of file incremental_text_ctrl.h.

55 {}

Member Function Documentation

virtual wxString INCREMENTAL_TEXT_CTRL::getCtrlText ( ) const
protectedpure virtual
Returns
the current string value of the text control

Implemented in SPIN_INCREMENTAL_TEXT_CTRL.

Referenced by incrementCtrlBy().

double INCREMENTAL_TEXT_CTRL::GetValue ( )

Get the current value of the control.

Definition at line 116 of file incremental_text_ctrl.cpp.

References incrementCtrlBy(), and m_currentValue.

117 {
118  // sanitise before handing the value - if the user did something
119  // like close a window with outstanding text changes, we need
120  // to clamp the value and re-interpret the text
121  incrementCtrlBy( 0.0 );
122 
123  return m_currentValue;
124 }
double m_currentValue
Precision to display.
void incrementCtrlBy(double aInc)
Increment the control by the given amount.
void INCREMENTAL_TEXT_CTRL::incrementCtrl ( bool  aUp)
protected

Single increment up or down by one step.

Definition at line 97 of file incremental_text_ctrl.cpp.

References incrementCtrlBy(), m_currentValue, and m_stepFunc.

Referenced by SPIN_INCREMENTAL_TEXT_CTRL::SPIN_INCREMENTAL_TEXT_CTRL().

98 {
100 }
double m_currentValue
Precision to display.
void incrementCtrlBy(double aInc)
Increment the control by the given amount.
void INCREMENTAL_TEXT_CTRL::incrementCtrlBy ( double  aInc)
protected

Increment the control by the given amount.

Definition at line 84 of file incremental_text_ctrl.cpp.

References getCtrlText(), m_currentValue, updateTextValue(), and validateFloatField().

Referenced by GetValue(), incrementCtrl(), and SPIN_INCREMENTAL_TEXT_CTRL::onFocusLoss().

85 {
86  const wxString txt = getCtrlText();
87  if( !validateFloatField( txt ) )
88  return;
89 
90  txt.ToDouble( &m_currentValue );
91  m_currentValue += aInc;
92 
94 }
double m_currentValue
Precision to display.
static bool validateFloatField(const wxString &aStr)
Check that a string looks like a floating point number that can be dealt with.
void updateTextValue()
Update the text control value with the current value, clamping to limits as needed.
virtual wxString getCtrlText() const =0
void INCREMENTAL_TEXT_CTRL::SetPrecision ( int  aPrecision)

Set the number of decimal places to display.

Definition at line 103 of file incremental_text_ctrl.cpp.

References m_precision.

104 {
105  m_precision = aPrecision;
106 }
int m_precision
The function used to determine the step.
void INCREMENTAL_TEXT_CTRL::SetStep ( double  aMin,
double  aMax,
STEP_FUNCTION  aNewFunc 
)

Function SetStep()

Set the stepping parameters of the control. The range is enforced by not allowing the scroll to exceed it, and on loss of focus, the control is also clamped to the range.

Parameters
aMinthe minium value allowed
aMaxthe maximum value allows
aNewFuncthe step function used to calculate the next step

Definition at line 57 of file incremental_text_ctrl.cpp.

References m_maxVal, m_minVal, m_stepFunc, max, min, and updateTextValue().

Referenced by SetStep().

59 {
60  wxASSERT( aMin <= aMax );
61 
62  m_minVal = std::min( aMin, aMax );
63  m_maxVal = std::max( aMin, aMax );
64  m_stepFunc = aStepFunc;
65 
66  // finally, clamp the current value and re-display
68 }
double m_maxVal
Current value of the control.
#define max(a, b)
Definition: auxiliary.h:86
void updateTextValue()
Update the text control value with the current value, clamping to limits as needed.
#define min(a, b)
Definition: auxiliary.h:85
void INCREMENTAL_TEXT_CTRL::SetStep ( double  aMin,
double  aMax,
double  aStep 
)
inline

Function SetStep()

Shortcut method to set step parameters when the step is constant

Parameters
aMinthe minium value allowed
aMaxthe maximum value allows
aStepthe constant step size

Definition at line 92 of file incremental_text_ctrl.h.

References SetStep().

93  {
94  SetStep( aMin, aMax,
95  [aStep] ( bool aUp, double aCurrent ) { return aUp ? aStep : -aStep; } );
96  }
void SetStep(double aMin, double aMax, STEP_FUNCTION aNewFunc)
Function SetStep()
virtual void INCREMENTAL_TEXT_CTRL::setTextCtrl ( const wxString &  aVal)
protectedpure virtual

Set the text control string value after an increment.

Implemented in SPIN_INCREMENTAL_TEXT_CTRL.

Referenced by updateTextValue().

void INCREMENTAL_TEXT_CTRL::SetValue ( double  aValue)

Set the value of the text control, but obey the limits currently set.

Parameters
aValuethe control value to set

Definition at line 109 of file incremental_text_ctrl.cpp.

References m_currentValue, and updateTextValue().

110 {
111  m_currentValue = aValue;
112  updateTextValue();
113 }
double m_currentValue
Precision to display.
void updateTextValue()
Update the text control value with the current value, clamping to limits as needed.
void INCREMENTAL_TEXT_CTRL::updateTextValue ( )
protected

Update the text control value with the current value, clamping to limits as needed.

Definition at line 71 of file incremental_text_ctrl.cpp.

References Format(), m_currentValue, m_maxVal, m_minVal, m_precision, and setTextCtrl().

Referenced by incrementCtrlBy(), SetStep(), and SetValue().

72 {
73  if( m_currentValue > m_maxVal )
75 
76  if( m_currentValue < m_minVal )
78 
79  wxString fmt = wxString::Format( "%%.%df", m_precision );
81 }
double m_maxVal
Current value of the control.
double m_currentValue
Precision to display.
virtual void setTextCtrl(const wxString &aVal)=0
Set the text control string value after an increment.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int m_precision
The function used to determine the step.

Member Data Documentation

double INCREMENTAL_TEXT_CTRL::m_currentValue
private

Precision to display.

Definition at line 141 of file incremental_text_ctrl.h.

Referenced by GetValue(), incrementCtrl(), incrementCtrlBy(), SetValue(), and updateTextValue().

double INCREMENTAL_TEXT_CTRL::m_maxVal
private

Current value of the control.

Definition at line 138 of file incremental_text_ctrl.h.

Referenced by SetStep(), and updateTextValue().

double INCREMENTAL_TEXT_CTRL::m_minVal
private

Definition at line 137 of file incremental_text_ctrl.h.

Referenced by SetStep(), and updateTextValue().

int INCREMENTAL_TEXT_CTRL::m_precision
private

The function used to determine the step.

Definition at line 144 of file incremental_text_ctrl.h.

Referenced by SetPrecision(), and updateTextValue().

STEP_FUNCTION INCREMENTAL_TEXT_CTRL::m_stepFunc
private

Definition at line 147 of file incremental_text_ctrl.h.

Referenced by incrementCtrl(), and SetStep().


The documentation for this class was generated from the following files: