Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Diff: Widgets/ContainerWidget.cpp
- Revision:
- 13:6714534e7974
- Parent:
- 12:63db16fea709
diff -r 63db16fea709 -r 6714534e7974 Widgets/ContainerWidget.cpp --- a/Widgets/ContainerWidget.cpp Sun May 08 14:42:08 2016 +0000 +++ b/Widgets/ContainerWidget.cpp Sat May 21 14:40:09 2016 +0000 @@ -24,7 +24,14 @@ Window::setSize(width, height); } - +void ContainerWidget::attach(Widget *child) +{ + Window::attach(child); + if(_layout == FIXED) { + // Re-interpret child's location referenced to the container + child->setOffset(x(), y()); + } +} void ContainerWidget::_adjust() { @@ -36,57 +43,65 @@ int width = 0; int height = 0; - + Widget *w; - + _widgets.reset(); while((w = _widgets.next()) != NULL) { - // Position the widgets - w->setLocation(wx, wy); + if(_layout == FIXED) { + w->setOffset(wx, wy); + } else { + + // Position the widgets + w->setLocation(wx, wy); - if(_layout == HORIZONTAL) { - wx += w->width(); - if(w->height() > height) { - height = w->height(); - } - } else { - wy += w->height(); - if(w->width() > width) { - width = w->width(); + if(_layout == HORIZONTAL) { + wx += w->width(); + if(w->height() > height) { + height = w->height(); + } + } else { + wy += w->height(); + if(w->width() > width) { + width = w->width(); + } } } } - int neededWidth; - int neededHeight; + if(_layout != FIXED) { + + int neededWidth; + int neededHeight; + + if(_layout == HORIZONTAL) { + neededWidth = _padding + _borderWidth + wx - _outer.x; + neededHeight = 2 * (_padding + _borderWidth) + height; + } else { + neededWidth = 2 * (_padding + _borderWidth) + width; + neededHeight = _padding + _borderWidth + wy - _outer.y; + } - if(_layout == HORIZONTAL) { - neededWidth = _padding + _borderWidth + wx - _outer.x; - neededHeight = 2 * (_padding + _borderWidth) + height; - } else { - neededWidth = 2 * (_padding + _borderWidth) + width; - neededHeight = _padding + _borderWidth + wy - _outer.y; - } + if(neededWidth > _outer.width) { + setWidth(neededWidth); + } + + if(neededHeight > _outer.height) { + setHeight(neededHeight); + } - if(neededWidth > _outer.width) { - setWidth(neededWidth); + if(_layout == VERTICAL_CENTER) { + // layout again to center the widgets + int center = (_outer.width/2) + _outer.x; + _widgets.reset(); + while((w = _widgets.next()) != NULL) { + w->setLocation(center - (w->width() / 2), w->y()); + } + } } - if(neededHeight > _outer.height) { - setHeight(neededHeight); - } - - if(_layout == VERTICAL_CENTER) { - // layout again to center the widgets - int center = (_outer.width/2) + _outer.x; - _widgets.reset(); - while((w = _widgets.next()) != NULL) { - w->setLocation(center - (w->width() / 2), w->y()); - } - } - Window::_adjust(); }