Skip to content

Commit

Permalink
- Fixed floating point value formatting for Fl_Spinner (STR #1331)
Browse files Browse the repository at this point in the history
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5348 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Matthias Melcher committed Aug 23, 2006
1 parent 74b91fe commit 2c22cfd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions 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)
Expand Down
32 changes: 23 additions & 9 deletions FL/Fl_Spinner.H
Expand Up @@ -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

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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());
}
Expand All @@ -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(); }
};
Expand Down

0 comments on commit 2c22cfd

Please sign in to comment.