Automatic container resizing when packing widgets.

master
Peter Nelson 2013-02-08 15:51:26 +00:00
parent 313f8a61ed
commit de4987eee1
3 changed files with 18 additions and 0 deletions

View File

@ -138,6 +138,7 @@ void HBox::Pack(Widget *widget)
widget->y = this->y;
widget->h = this->h;
if (widget->w < 0) widget->w = this->w - (widget->x - this->x);
if (this->x + this->w < widget->x + widget->w) this->w = widget->x + widget->w - this->x;
Container::Pack(widget);
}
@ -148,5 +149,6 @@ void VBox::Pack(Widget *widget)
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);
if (this->y + this->h < widget->y + widget->h) this->h = widget->y + widget->h - this->y;
Container::Pack(widget);
}

View File

@ -47,6 +47,18 @@ enum SliderPart {
SP_HRIGHT,
};
HSlider::HSlider(bool big, int h)
{
this->h = h;
this->big = big;
}
VSlider::VSlider(bool big, int w)
{
this->w = w;
this->big = big;
}
float HSlider::GetNewValue(int x, int y)
{
int x2 = this->x + pad;

View File

@ -22,12 +22,16 @@ struct Slider : Widget {
};
struct HSlider : Slider {
HSlider(bool big = false, int h = 24);
/* virtual */ float GetNewValue(int x, int y);
/* virtual */ void OnPaint(const PUi *pui) const;
};
struct VSlider : Slider {
VSlider(bool big = false, int w = 24);
/* virtual */ float GetNewValue(int x, int y);
/* virtual */ void OnPaint(const PUi *pui) const;