diff options
| author | Matthias Melcher <github@matthiasm.com> | 2026-01-04 15:50:49 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2026-01-04 15:50:56 +0100 |
| commit | 0e570fb6729ff6b97249256c2c9d5f3aa58c7bb4 (patch) | |
| tree | 7140e3b2d97c6f7852e915759918d14bf6b35b00 /src/Fl_Valuator.cxx | |
| parent | 357336bd40d868fd65e95c61d1adaf9de0fb7811 (diff) | |
Add C++11 Fl_Valuator::format API.
This is helpful for writing language wrapper, in
this particular case for PyFLTK.
Diffstat (limited to 'src/Fl_Valuator.cxx')
| -rw-r--r-- | src/Fl_Valuator.cxx | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/Fl_Valuator.cxx b/src/Fl_Valuator.cxx index 38383551e..90fa23325 100644 --- a/src/Fl_Valuator.cxx +++ b/src/Fl_Valuator.cxx @@ -1,7 +1,7 @@ // // Valuator widget for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2016 by Bill Spitzak and others. +// Copyright 1998-2026 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -175,7 +175,7 @@ int Fl_Valuator::format(char* buffer) { int i, c = 0; char temp[32]; // output a number with many digits after the decimal point. This - // seems to be needed to get high precission + // seems to be needed to get high precision snprintf(temp, sizeof(temp), "%.12f", A/B); // strip all trailing 0's for (i=(int) strlen(temp)-1; i>0; i--) { @@ -190,3 +190,16 @@ int Fl_Valuator::format(char* buffer) { // MRS: THIS IS A HACK - RECOMMEND ADDING BUFFER SIZE ARGUMENT return snprintf(buffer, 128, "%.*f", c, v); } + +/** + \brief C++11 API for Fl_Valuator::format(char* buffer). + Users can override either version to change the format of the text output + in the valuator. + \return the formatted text of the current value + \see Fl_Valuator::format(char* buffer) + */ +std::string Fl_Valuator::format_str() { + char buffer[129]; + int size = format(buffer); + return std::string(buffer, size); +} |
