Add HBox and VBox with automatic widget placement

master
Peter Nelson 2013-02-04 08:20:39 +00:00
parent f9417010be
commit d559b129fe
2 changed files with 29 additions and 0 deletions

View File

@ -114,3 +114,23 @@ void Container::Pack(Widget *widget)
{
this->children.push_back(widget);
}
void HBox::Pack(Widget *widget)
{
Widget *last = this->children.empty() ? NULL : this->children.back();
widget->x = (last == NULL) ? this->x : (last->x + last->w + this->padding);
widget->y = this->y;
widget->h = this->h;
if (widget->w < 0) widget->w = this->w - (widget->x - this->x);
Container::Pack(widget);
}
void VBox::Pack(Widget *widget)
{
Widget *last = this->children.empty() ? NULL : this->children.back();
widget->x = this->x;
widget->y = (last == NULL) ? this->y : (last->y + last->h + this->padding);
widget->w = this->w;
if (widget->h < 0) widget->h = this->h - (widget->y - this->y);
Container::Pack(widget);
}

View File

@ -11,6 +11,7 @@ public:
Colour colour;
Colour frame;
bool back;
int padding;
~Container();
@ -20,6 +21,14 @@ public:
/* virtual */ void OnPaint(const PUi *pui) const;
virtual void Pack(Widget *widget);
};
struct VBox : Container {
/* virtual */ void Pack(Widget *widget);
};
struct HBox : Container {
/* virtual */ void Pack(Widget *widget);
};