Added a Spinner control

master
Jason von Nieda 12 years ago
parent 180ad11e7f
commit d16bcced8d
  1. 37
      ScreenUi.cpp
  2. 17
      ScreenUi.h

@ -386,6 +386,43 @@ bool List::handleInputEvent(int x, int y, bool selected, bool cancelled) {
return captured_;
}
////////////////////////////////////////////////////////////////////////////////
// Spinner
////////////////////////////////////////////////////////////////////////////////
Spinner::Spinner(int value, int low, int high, int increment, bool rollover) : Label(NULL) {
value_ = value;
low_ = low;
high_ = high;
increment_ = increment;
rollover_ = rollover;
sprintf(buffer_, "%d", value_);
setText(buffer_);
}
int Spinner::intValue() {
return value_;
}
bool Spinner::handleInputEvent(int x, int y, bool selected, bool cancelled) {
if (captured_ && y) {
value_ += (y * increment_);
if (value_ < low_) {
value_ = rollover_ ? high_ : low_;
}
else if (value_ > high_) {
value_ = rollover_ ? low_ : high_;
}
sprintf(buffer_, "%d", value_);
setText(buffer_);
repaint();
}
if (selected) {
captured_ = !captured_;
repaint();
}
}
////////////////////////////////////////////////////////////////////////////////
// Input
////////////////////////////////////////////////////////////////////////////////

@ -274,6 +274,23 @@ class List : public Label {
uint8_t selectedIndex_;
};
// A Component that allows the user to scroll through a range of Integers
// or floats.
class Spinner : public Label {
public:
Spinner(int value, int low, int high, int increment, bool rollover);
int intValue();
virtual bool acceptsFocus() { return true; }
virtual bool handleInputEvent(int x, int y, bool selected, bool cancelled);
#ifdef SCREENUI_DEBUG
virtual char *description() { return "Spinner"; }
#endif
private:
char buffer_[10];
int value_, low_, high_, increment_;
bool rollover_;
};
// allows text input. Each character can be clicked to scroll through the alphabet.
class Input : public Label {
public:

Loading…
Cancel
Save