Skip to content

Commit

Permalink
Fixed container would not draw child objects when draw was called on it
Browse files Browse the repository at this point in the history
If we had a container with child objects, they would not be updated/drawn when the container's "draw" function was called.
  • Loading branch information
midwan committed Nov 9, 2024
1 parent 265fde6 commit 0a1bc3e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/guisan/widgets/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ namespace gcn

void draw(Graphics* graphics) override;
Rectangle getChildrenArea() override;
void drawChildren(Graphics* graphics);

protected:
/**
Expand Down
36 changes: 33 additions & 3 deletions src/widgets/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ namespace gcn
{

Container::~Container()
{

}
= default;

void Container::draw(Graphics* graphics)
{
Expand All @@ -78,6 +76,7 @@ namespace gcn
graphics->setColor(getBaseColor());
graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight()));
}
drawChildren(graphics);
}

void Container::setOpaque(bool opaque)
Expand Down Expand Up @@ -162,4 +161,35 @@ namespace gcn
{
return Rectangle(0, 0, getWidth(), getHeight());
}

void Container::drawChildren(Graphics* graphics)
{
graphics->pushClipArea(getChildrenArea());

std::list<Widget*> children = getChildren();
std::list<Widget*>::iterator iter;
for (iter = children.begin(); iter != children.end(); ++iter)
{
if ((*iter)->isVisible())
{
// If the widget has a frame,
// draw it before drawing the widget
if ((*iter)->getFrameSize() > 0)
{
Rectangle rec = (*iter)->getDimension();
rec.x -= (*iter)->getFrameSize();
rec.y -= (*iter)->getFrameSize();
rec.width += 2 * (*iter)->getFrameSize();
rec.height += 2 * (*iter)->getFrameSize();
graphics->pushClipArea(rec);
(*iter)->drawFrame(graphics);
graphics->popClipArea();
}
graphics->pushClipArea((*iter)->getDimension());
(*iter)->draw(graphics);
graphics->popClipArea();
}
}
graphics->popClipArea();
}
} // namespace gcn

0 comments on commit 0a1bc3e

Please sign in to comment.