bwidgets/src/w/base/layout.cpp

40 lines
878 B
C++

#include <basic_widgets/w/base/layout.hpp>
using namespace bwidgets;
const Size Layout::default_margins {8, 8};
auto Layout::add_widget(std::unique_ptr<Widget> widget_ptr) -> Layout*
{
widget_ptr->renderer(_renderer);
_widgets.emplace_back(std::move(widget_ptr));
_update_layout(_viewport);
return this;
}
void Layout::for_widgets(const std::function<void(Widget*)>& f)
{
for (const auto& w : _widgets) f(w.get());
}
auto Layout::handle_event(const SDL_Event& ev) -> Layout*
{
for (const auto& w : _widgets) w->handle_event(ev);
return this;
}
void Layout::_handle_geometry_change(const SDL_Rect& vp)
{
_update_layout(vp);
}
void Layout::_handle_renderer_change(const std::shared_ptr<Renderer>& r)
{
for (const auto& w : _widgets) w->renderer(r);
}
void Layout::_handle_rendering()
{
for (const auto& w : _widgets) w->render();
}