Moved indexOf from RangeCharSet to CharSet.

Added more documentation.
Started work on IntegerInput.
master
Jason von Nieda 13 years ago
parent eb224d34b0
commit b364affd0e
  1. 43
      ScreenUi.cpp
  2. 23
      ScreenUi.h

@ -452,6 +452,26 @@ bool Input::handleInputEvent(int x, int y, bool selected, bool cancelled) {
return captured_; return captured_;
} }
////////////////////////////////////////////////////////////////////////////////
// IntegerInput
////////////////////////////////////////////////////////////////////////////////
IntegerInput::IntegerInput(long value, unsigned char width, unsigned char base) : Input(NULL) {
signed_ = true;
base_ = base;
if (!width) {
// count the digits
}
}
IntegerInput::IntegerInput(unsigned long value, unsigned char width, unsigned char base) : Input(NULL) {
signed_ = false;
base_ = base;
if (!width) {
// count the digits
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ScrollContainer // ScrollContainer
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -539,6 +559,19 @@ void ScrollContainer::paint(Screen *screen) {
} }
} }
////////////////////////////////////////////////////////////////////////////////
// CharSet
////////////////////////////////////////////////////////////////////////////////
int CharSet::indexOf(unsigned char ch) {
for (int i = 0; i < size(); i++) {
if (charAt(i) == ch) {
return i;
}
}
return -1;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// RangeCharSet // RangeCharSet
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -559,16 +592,6 @@ RangeCharSet::~RangeCharSet() {
free(ranges_); free(ranges_);
} }
// TODO: move to CharSet
int RangeCharSet::indexOf(unsigned char ch) {
for (int i = 0; i < size(); i++) {
if (charAt(i) == ch) {
return i;
}
}
return -1;
}
int RangeCharSet::charAt(int index) { int RangeCharSet::charAt(int index) {
// determine which range the index falls within by iterating the ranges // determine which range the index falls within by iterating the ranges
// and then use that plus the index to determine the character // and then use that plus the index to determine the character

@ -39,7 +39,7 @@ class CharSet {
virtual bool contains(unsigned char ch) { return indexOf(ch) != -1; } virtual bool contains(unsigned char ch) { return indexOf(ch) != -1; }
// Returns the index in the character set for the given character. // Returns the index in the character set for the given character.
// Return -1 if the character is not part of the character set. // Return -1 if the character is not part of the character set.
virtual int indexOf(unsigned char ch) = 0; virtual int indexOf(unsigned char ch);
// Returns the character at the given index for the character set. // Returns the character at the given index for the character set.
// Return -1 if the index is not within the range of the character set. // Return -1 if the index is not within the range of the character set.
virtual int charAt(int index) = 0; virtual int charAt(int index) = 0;
@ -54,7 +54,6 @@ class RangeCharSet : public CharSet {
public: public:
RangeCharSet(int rangeCount, ...); RangeCharSet(int rangeCount, ...);
~RangeCharSet(); ~RangeCharSet();
virtual int indexOf(unsigned char ch);
virtual int charAt(int index); virtual int charAt(int index);
virtual unsigned char size(); virtual unsigned char size();
private: private:
@ -206,6 +205,7 @@ class Screen : public Container {
class Label : public Component { class Label : public Component {
public: public:
Label(const char *text); Label(const char *text);
virtual const char *text() { return (const char *) text_; }
virtual void setText(const char *text); virtual void setText(const char *text);
virtual void paint(Screen *screen); virtual void paint(Screen *screen);
#ifdef SCREENUI_DEBUG #ifdef SCREENUI_DEBUG
@ -292,12 +292,27 @@ class Input : public Label {
CharSet *charSet_; CharSet *charSet_;
}; };
// allows input of a floating point number. // A Component that accepts input of a floating or fixed point decimal
// number.
class DecimalInput : public Input { class DecimalInput : public Input {
}; };
// allows input of an integer number with a certain base. // A Component that accepts input of an integer value with a given base.
class IntegerInput : public Input { class IntegerInput : public Input {
public:
// Create a signed IntegerInput with the given value, width and base.
// If width is 0 the width will be determined by the number of digits in
// the incoming value, with one additional space for the negative.
// If base is not specified, the default is base 10.
IntegerInput(long value, unsigned char width = 0, unsigned char base = 10);
// Create a signed IntegerInput with the given value, width and base.
// If width is 0 the width will be determined by the number of digits in
// the incoming value.
// If base is not specified, the default is base 10.
IntegerInput(unsigned long value, unsigned char width = 0, unsigned char base = 10);
private:
bool signed_;
unsigned char base_;
}; };
// Component that allows the user to enter a time with up to three fields // Component that allows the user to enter a time with up to three fields

Loading…
Cancel
Save