Moved offsetChildren logic from ScrollContainer to Container so that they work properly for child components, too, now.

master
Jason von Nieda 12 years ago
parent 105f82f9bc
commit 1a143e5083
  1. 61
      ScreenUi.cpp
  2. 6
      ScreenUi.h

@ -124,6 +124,10 @@ Container::~Container() {
}
void Container::update(Screen *screen) {
if (!firstUpdateCompleted_) {
offsetChildren(0, y_);
firstUpdateCompleted_ = true;
}
for (int i = 0; i < componentCount_; i++) {
components_[i]->update(screen);
}
@ -155,10 +159,33 @@ void Container::add(Component *component, int8_t x, int8_t y) {
componentsLength_ = newComponentsLength;
}
components_[componentCount_++] = component;
if (firstUpdateCompleted_) {
// TODO: if the first update has already completed we need to update
// incoming components locations as they are added
}
component->setLocation(x, y);
component->repaint();
}
void Container::offsetChildren(int x, int y) {
for (int i = 0; i < componentCount_; i++) {
Component *c = components_[i];
/*
Serial.print("Moving ");
Serial.print(c->description());
Serial.print(" from ");
Serial.print(c->x(), DEC);
Serial.print(", ");
Serial.print(c->y(), DEC);
Serial.print(" to ");
Serial.print(c->x() + x, DEC);
Serial.print(", ");
Serial.println(c->y() + y, DEC);
*/
c->setLocation(c->x() + x, c->y() + y);
}
}
Component *Container::nextFocusHolder(Component *focusHolder, bool reverse) {
bool focusHolderFound = false;
return nextFocusHolder(focusHolder, reverse, &focusHolderFound);
@ -437,14 +464,6 @@ ScrollContainer::~ScrollContainer() {
free(clearLine);
}
void ScrollContainer::add(Component *component, int8_t x, int8_t y) {
Container::add(component, x, y);
if (firstUpdateCompleted_) {
// TODO: if the first update has already completed we need to update
// incoming components locations as they are added
}
}
bool ScrollContainer::dirty() {
if (Container::dirty()) {
return true;
@ -452,32 +471,6 @@ bool ScrollContainer::dirty() {
return scrollNeeded();
}
void ScrollContainer::update(Screen *screen) {
if (!firstUpdateCompleted_) {
offsetChildren(0, y_);
firstUpdateCompleted_ = true;
}
}
void ScrollContainer::offsetChildren(int x, int y) {
for (int i = 0; i < componentCount_; i++) {
Component *c = components_[i];
/*
Serial.print("Moving ");
Serial.print(c->description());
Serial.print(" from ");
Serial.print(c->x(), DEC);
Serial.print(", ");
Serial.print(c->y(), DEC);
Serial.print(" to ");
Serial.print(c->x() + x, DEC);
Serial.print(", ");
Serial.println(c->y() + y, DEC);
*/
c->setLocation(c->x() + x, c->y() + y);
}
}
bool ScrollContainer::scrollNeeded() {
// see if the focus holder has changed since the last check
Component *focusHolder = screen_->focusHolder();

@ -110,10 +110,12 @@ class Container : public Component {
protected:
Component *nextFocusHolder(Component *focusHolder, bool reverse);
Component *nextFocusHolder(Component *focusHolder, bool reverse, bool *focusHolderFound);
void offsetChildren(int x, int y);
Component **components_;
uint8_t componentsLength_;
uint8_t componentCount_;
bool firstUpdateCompleted_;
};
// The main entry point into the ScreenUi system. A Screen instance represents
@ -280,8 +282,6 @@ class ScrollContainer : public Container {
// the tree to find it.
ScrollContainer(Screen *screen, uint8_t width, uint8_t height);
~ScrollContainer();
virtual void update(Screen *screen);
virtual void add(Component *component, int8_t x, int8_t y);
virtual void paint(Screen *screen);
virtual bool dirty();
#ifdef SCREENUI_DEBUG
@ -289,12 +289,10 @@ class ScrollContainer : public Container {
#endif
private:
bool scrollNeeded();
void offsetChildren(int x, int y);
Component *lastFocusHolder_;
Screen *screen_;
char *clearLine;
bool firstUpdateCompleted_;
};
// A specialization of ScrollContainer that contains only Buttons and provides

Loading…
Cancel
Save