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) { void Container::update(Screen *screen) {
if (!firstUpdateCompleted_) {
offsetChildren(0, y_);
firstUpdateCompleted_ = true;
}
for (int i = 0; i < componentCount_; i++) { for (int i = 0; i < componentCount_; i++) {
components_[i]->update(screen); components_[i]->update(screen);
} }
@ -155,10 +159,33 @@ void Container::add(Component *component, int8_t x, int8_t y) {
componentsLength_ = newComponentsLength; componentsLength_ = newComponentsLength;
} }
components_[componentCount_++] = component; 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->setLocation(x, y);
component->repaint(); 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) { Component *Container::nextFocusHolder(Component *focusHolder, bool reverse) {
bool focusHolderFound = false; bool focusHolderFound = false;
return nextFocusHolder(focusHolder, reverse, &focusHolderFound); return nextFocusHolder(focusHolder, reverse, &focusHolderFound);
@ -437,14 +464,6 @@ ScrollContainer::~ScrollContainer() {
free(clearLine); 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() { bool ScrollContainer::dirty() {
if (Container::dirty()) { if (Container::dirty()) {
return true; return true;
@ -452,32 +471,6 @@ bool ScrollContainer::dirty() {
return scrollNeeded(); 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() { bool ScrollContainer::scrollNeeded() {
// see if the focus holder has changed since the last check // see if the focus holder has changed since the last check
Component *focusHolder = screen_->focusHolder(); Component *focusHolder = screen_->focusHolder();

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

Loading…
Cancel
Save