Skip to content

Commit

Permalink
add Precision property to Spinner for set number of decimal places in…
Browse files Browse the repository at this point in the history
… FloatingPoint mode
  • Loading branch information
rpaciorek committed Sep 2, 2019
1 parent 9486b94 commit 17f7f61
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
25 changes: 25 additions & 0 deletions cegui/include/CEGUI/widgets/Spinner.h
Expand Up @@ -173,6 +173,18 @@ namespace CEGUI
*/
double getMinimumValue(void) const;

/*!
\brief
Set precision (number of decimal places)
\param val
The floating point precision using by the spinner.
\return
Nothing.
*/
int getPrecision(void) const;

/*!
\brief
Return the current text input / display mode setting.
Expand Down Expand Up @@ -235,6 +247,18 @@ namespace CEGUI
*/
void setMinimumValue(double minVaue);

/*!
\brief
Set precision (number of decimal places)
\param val
The floating point precision using by the spinner.
\return
Nothing.
*/
void setPrecision(int val);

/*!
\brief
Set the spinner input / display mode.
Expand Down Expand Up @@ -403,6 +427,7 @@ namespace CEGUI
double d_currentValue; //!< Numerical copy of the text in d_editbox.
double d_maxValue; //!< Maximum value for spinner.
double d_minValue; //!< Minimum value for spinner.
int i_precision; //!< precision (number of decimal places)
TextInputMode d_inputMode; //!< Current text display/input mode.

private:
Expand Down
18 changes: 17 additions & 1 deletion cegui/src/widgets/Spinner.cpp
Expand Up @@ -66,6 +66,7 @@ namespace CEGUI
d_currentValue(1.0f),
d_maxValue(32767.0f),
d_minValue(-32768.0f),
i_precision(6),
d_inputMode(static_cast<TextInputMode>(-1))
{
addSpinnerProperties();
Expand Down Expand Up @@ -124,6 +125,11 @@ namespace CEGUI
return d_minValue;
}

int Spinner::getPrecision(void) const
{
return i_precision;
}

Spinner::TextInputMode Spinner::getTextInputMode(void) const
{
return d_inputMode;
Expand Down Expand Up @@ -176,6 +182,11 @@ namespace CEGUI
}
}

void Spinner::setPrecision(int val)
{
i_precision = val;
}

void Spinner::setTextInputMode(TextInputMode mode)
{
if (mode != d_inputMode)
Expand Down Expand Up @@ -234,6 +245,11 @@ namespace CEGUI
"TextInputMode", "Property to get/set the TextInputMode setting for the spinner. Value is \"FloatingPoint\", \"Integer\", \"Hexadecimal\", or \"Octal\".",
&Spinner::setTextInputMode, &Spinner::getTextInputMode, Spinner::TextInputMode::Integer
);

CEGUI_DEFINE_PROPERTY(Spinner, int,
"Precision", "Property to get/set the precision of display the floating point values. Value is a int.",
&Spinner::setPrecision, &Spinner::getPrecision, 6
);
}

double Spinner::getValueFromText(void) const
Expand Down Expand Up @@ -289,7 +305,7 @@ namespace CEGUI
switch (d_inputMode)
{
case TextInputMode::FloatingPoint:
return CEGUI::PropertyHelper<float>::toString( static_cast<float>(d_currentValue) );
tmp << std::fixed << std::setprecision(i_precision) << d_currentValue << std::setprecision(6) << std::defaultfloat;
break;
case TextInputMode::Integer:
tmp << static_cast<int>(d_currentValue);
Expand Down

0 comments on commit 17f7f61

Please sign in to comment.