summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2006-08-23 14:37:28 +0000
committerMatthias Melcher <fltk@matthiasm.com>2006-08-23 14:37:28 +0000
commit2c22cfd94a6b46515f4dd23ecb5f5589c31e2b7d (patch)
tree024eb663c2c17b86d7e4623a1bfc0dab5a976169
parent74b91fe3718e47df5c09fe29bb82341b6c77ccb4 (diff)
- Fixed floating point value formatting for Fl_Spinner (STR #1331)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5348 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--CHANGES2
-rw-r--r--FL/Fl_Spinner.H32
2 files changed, 25 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index 296fedf3a..74498f6d8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,7 @@
CHANGES IN FLTK 1.1.8
+ - Fixed floating point value formatting
+ for Fl_Spinner (STR #1331)
- Fixed Fl_Positioner callback
when released (STR #1387)
- Fixed WIN32 zero size window issue (STR #1387)
diff --git a/FL/Fl_Spinner.H b/FL/Fl_Spinner.H
index c475681de..a2da3a3cf 100644
--- a/FL/Fl_Spinner.H
+++ b/FL/Fl_Spinner.H
@@ -56,6 +56,7 @@ class Fl_Spinner : public Fl_Group
up_button_, // Up button
down_button_; // Down button
+
static void sb_cb(Fl_Widget *w, Fl_Spinner *sb) {
double v; // New value
@@ -93,7 +94,20 @@ class Fl_Spinner : public Fl_Group
void update() {
char s[255]; // Value string
- sprintf(s, format_, value_);
+ if (format_[0]=='%'&&format_[1]=='.'&&format_[2]=='*') { // precision argument
+ // this code block is a simplified version of
+ // Fl_Valuator::format() and works well (but looks ugly)
+ int c = 0;
+ char temp[64], *sp = temp;
+ sprintf(temp, "%.12f", step_);
+ while (*sp) sp++;
+ sp--;
+ while (sp>temp && *sp=='0') sp--;
+ while (sp>temp && (*sp>='0' && *sp<='9')) { sp--; c++; }
+ sprintf(s, format_, c, value_);
+ } else {
+ sprintf(s, format_, value_);
+ }
input_.value(s);
}
@@ -144,7 +158,7 @@ class Fl_Spinner : public Fl_Group
H / 2 + 2, H / 2);
}
double step() const { return (step_); }
- void step(double s) { step_ = s; }
+ void step(double s) { step_ = s; update(); }
Fl_Color textcolor() const {
return (input_.textcolor());
}
@@ -165,13 +179,13 @@ class Fl_Spinner : public Fl_Group
}
uchar type() const { return (input_.type()); }
void type(uchar v) {
- if (v==FL_FLOAT_INPUT) {
- format("%g");
- } else {
- format("%.0f");
- }
- input_.type(v);
- }
+ if (v==FL_FLOAT_INPUT) {
+ format("%.*f");
+ } else {
+ format("%.0f");
+ }
+ input_.type(v);
+ }
double value() const { return (value_); }
void value(double v) { value_ = v; update(); }
};