Skip to content

Commit

Permalink
Remove trailing decimals from Surface Inspector text boxes
Browse files Browse the repository at this point in the history
For some reason the std::to_string standard library function converts floating
point values into something like fixed-precision, with multiple trailing
zeroes. This makes the displayed values in the Surface Inspector difficult to
read.

The new code is using the fmt::format function which produces more readable
output similar to what std::cout would produce.
  • Loading branch information
Matthew Mott committed Jul 20, 2021
1 parent 50d683d commit 8d35134
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 10 additions & 7 deletions radiant/ui/surfaceinspector/SurfaceInspector.cpp
Expand Up @@ -88,6 +88,11 @@ namespace
const double MAX_FLOAT_RESOLUTION = 1.0E-5;
}

void SurfaceInspector::ManipulatorRow::setValue(double v)
{
value->SetValue(fmt::format("{}", v));
}

SurfaceInspector::SurfaceInspector() :
wxutil::TransientWindow(_(WINDOW_TITLE), GlobalMainFrame().getWxTopLevelWindow(), true),
_callbackActive(false),
Expand Down Expand Up @@ -486,13 +491,11 @@ void SurfaceInspector::updateTexDef()
texdef.rotate = float_snapped(texdef.rotate, MAX_FLOAT_RESOLUTION);

// Load the values into the widgets
_manipulators[HSHIFT].value->SetValue(string::to_string(texdef.shift[0]));
_manipulators[VSHIFT].value->SetValue(string::to_string(texdef.shift[1]));

_manipulators[HSCALE].value->SetValue(string::to_string(texdef.scale[0]));
_manipulators[VSCALE].value->SetValue(string::to_string(texdef.scale[1]));

_manipulators[ROTATION].value->SetValue(string::to_string(texdef.rotate));
_manipulators[HSHIFT].setValue(texdef.shift[0]);
_manipulators[VSHIFT].setValue(texdef.shift[1]);
_manipulators[HSCALE].setValue(texdef.scale[0]);
_manipulators[VSCALE].setValue(texdef.scale[1]);
_manipulators[ROTATION].setValue(texdef.rotate);
}
}

Expand Down
4 changes: 4 additions & 0 deletions radiant/ui/surfaceinspector/SurfaceInspector.h
Expand Up @@ -34,12 +34,16 @@ class SurfaceInspector :
public wxutil::TransientWindow,
public sigc::trackable
{
// Manipulatable value field with nudge buttons and a step size selector
struct ManipulatorRow
{
wxTextCtrl* value;
wxutil::ControlButton* smaller;
wxutil::ControlButton* larger;
wxTextCtrl* stepEntry;

// Set the text control to show the given value
void setValue(double val);
};

// This are the named manipulator rows (shift, scale, rotation, etc)
Expand Down

0 comments on commit 8d35134

Please sign in to comment.