From d7768b76d042eaa6cdce97976e96315d0bceccb2 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Mon, 6 Nov 2023 19:09:48 +0100 Subject: FLUID: Adds template for tutorial. Tutorial still to be written. Also adds convenience methods to Fl_Input_ for getting and setting numeric values. --- src/Fl_Input_.cxx | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src') diff --git a/src/Fl_Input_.cxx b/src/Fl_Input_.cxx index 4fc429aa3..52fa8cb84 100644 --- a/src/Fl_Input_.cxx +++ b/src/Fl_Input_.cxx @@ -1462,6 +1462,54 @@ int Fl_Input_::value(const char* str) { return value(str, str ? (int) strlen(str) : 0); } +/** + Changes the widget text to a signed integer number. + + \param [in] v the new value + \return non-zero if the new value is different than the current one + \see Fl_Input_::value(const char* str), Fl_Input_::ivalue() + */ +int Fl_Input_::value(int v) { + char buf[64]; + snprintf(buf, sizeof(buf)-1, "%d", v); + return value(buf); +} + +/** + Changes the widget text to a floating point number ("%g"). + + \param [in] v the new value + \return non-zero if the new value is different than the current one + \see Fl_Input_::value(const char* str), Fl_Input_::ivalue() + */ +int Fl_Input_::value(double v) { + char buf[64]; + snprintf(buf, sizeof(buf)-1, "%g", v); + return value(buf); +} + +/** + Returns the widget text interpreted as a signed integer. + + \return signed integer value + \see Fl_Input_::dvalue() + \see Fl_Input_::value(int) + */ +int Fl_Input_::ivalue() const { + return atoi(value()); +} + +/** + Returns the widget text interpreted as a floating point number. + + \return double precision floating point value + \see Fl_Input_::ivalue() + \see Fl_Input_::value(double) + */ +int Fl_Input_::dvalue() const { + return atof(value()); +} + /** Changes the size of the widget. This call updates the text layout so that the cursor is visible. -- cgit v1.2.3