Set up stacked widget.

This commit is contained in:
jmsgrogan 2020-06-27 10:47:30 +01:00
parent 4e85edacc8
commit ee51f3ee09
51 changed files with 808 additions and 195 deletions

View file

@ -5,13 +5,16 @@
Widget::Widget()
: mLocation(DiscretePoint(0, 0)),
mWidth(100),
mHeight(100),
mMaxHeight(0),
mSize({100, 0, 0, 100, 0, 0}),
mPadding(),
mMargin(),
mMyLayers(),
mLayers(),
mChildren(),
mBackgroundColor(Color::Create(200, 0, 0))
mBorderThickness(0),
mBackgroundColor(Color::Create(255, 255, 255)),
mBorderColor(Color::Create(0, 0, 0)),
mVisible(true)
{
}
@ -31,14 +34,9 @@ void Widget::AddWidget(WidgetUPtr widget)
mChildren.push_back(std::move(widget));
}
unsigned Widget::GetWidth() const
Widget::BoundedSize Widget::GetSize() const
{
return mWidth;
}
unsigned Widget::GetHeight() const
{
return mHeight;
return mSize;
}
DiscretePoint Widget::GetLocation() const
@ -51,14 +49,29 @@ std::vector<VisualLayer*> Widget::GetLayers() const
return mLayers;
}
unsigned Widget::GetMaxHeight() const
void Widget::SetSize(const BoundedSize& size)
{
return mMaxHeight;
mSize = size;
}
void Widget::SetMaxHeight(unsigned maxHeight)
void Widget::SetMargin(unsigned margin)
{
mMaxHeight = maxHeight;
mMargin = {margin, margin, margin, margin};
}
void Widget::SetMargin(const BoundaryOffset& margin)
{
mMargin = margin;
}
void Widget::SetPadding(unsigned padding)
{
mPadding = {padding, padding, padding, padding};
}
void Widget::SetPadding(const BoundaryOffset& padding)
{
mPadding = padding;
}
void Widget::CopyMyLayers()
@ -69,11 +82,17 @@ void Widget::CopyMyLayers()
std::transform(mMyLayers.begin(), mMyLayers.end(), std::back_inserter(mLayers), getRaw);
}
void Widget::SetBounds(unsigned width, unsigned height)
{
mSize.mWidth = width;
mSize.mHeight = height;
}
void Widget::AddChildLayers(const PaintEvent* event)
{
for(auto& child: mChildren)
{
child->SetSize(mWidth, mHeight);
child->SetBounds(mSize.mWidth, mSize.mHeight);
child->SetLocation(mLocation);
child->OnPaintEvent(event);
const auto layers = child->GetLayers();
@ -84,6 +103,9 @@ void Widget::AddChildLayers(const PaintEvent* event)
void Widget::OnPaintEvent(const PaintEvent* event)
{
mMyLayers.clear();
mLayers.clear();
if(!mVisible)return;
AddBackground(event);
CopyMyLayers();
AddChildLayers(event);
@ -92,8 +114,8 @@ void Widget::OnPaintEvent(const PaintEvent* event)
bool Widget::Contains(const DiscretePoint& loc) const
{
if(loc.GetX() < mLocation.GetX()) return false;
if(loc.GetX() > mLocation.GetX() + mWidth) return false;
if(loc.GetY() > mLocation.GetY() + mHeight) return false;
if(loc.GetX() > mLocation.GetX() + mSize.mWidth) return false;
if(loc.GetY() > mLocation.GetY() + mSize.mHeight) return false;
if(loc.GetY() < mLocation.GetY()) return false;
return true;
}
@ -154,7 +176,12 @@ void Widget::OnMyMouseEvent(const MouseEvent* event)
void Widget::AddBackground(const PaintEvent* event)
{
auto shape = RectangleElement::Create(mLocation, mWidth, mHeight);
unsigned locX = mLocation.GetX() + mMargin.mLeft;
unsigned locY = mLocation.GetY() + mMargin.mTop;
unsigned deltaX = mSize.mWidth - mMargin.mLeft - mMargin.mRight;
unsigned deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom;
auto shape = RectangleElement::Create(DiscretePoint(locX, locY),
deltaX, deltaY);
shape->SetFillColor(Color::Create(*mBackgroundColor));
auto shapeLayer = VisualLayer::Create();
shapeLayer->SetShape(std::move(shape));
@ -171,8 +198,7 @@ void Widget::SetLocation(const DiscretePoint& loc)
mLocation = loc;
}
void Widget::SetSize(unsigned width, unsigned height)
void Widget::SetVisible(bool visible)
{
mWidth = width;
mHeight = height;
mVisible = visible;
}