bwidgets/src/w/base/layout.cpp

43 lines
888 B
C++
Raw Normal View History

#include <basic_widgets/w/base/layout.hpp>
using namespace bwidgets;
2021-08-06 14:22:56 +02:00
Layout::~Layout() noexcept
{
2021-08-06 14:22:56 +02:00
for (auto* widget_ptr : _widgets) delete widget_ptr;
}
2021-08-06 14:22:56 +02:00
auto Layout::add_widget(Widget* widget_ptr) -> Layout*
{
2021-07-23 20:08:52 +02:00
widget_ptr->renderer(_renderer);
2021-08-06 14:22:56 +02:00
_widgets.emplace_back(widget_ptr);
_update_layout(_viewport);
2021-07-19 23:50:50 +02:00
return this;
}
2021-08-06 14:22:56 +02:00
void Layout::for_widgets(const std::function<void(Widget*)>& f)
2021-07-23 20:08:52 +02:00
{
for (auto* w : _widgets) f(w);
2021-07-23 20:08:52 +02:00
}
2021-08-06 14:22:56 +02:00
auto Layout::handle_event(const SDL_Event& ev) -> Layout*
{
2021-08-06 14:22:56 +02:00
for (auto* widget_ptr : _widgets) widget_ptr->handle_event(ev);
2021-07-19 23:50:50 +02:00
return this;
}
2021-08-06 14:22:56 +02:00
void Layout::_handle_geometry_change(const SDL_Rect& vp) noexcept
{
_update_layout(vp);
}
2021-08-06 14:22:56 +02:00
void Layout::_handle_renderer_change(Renderer* r)
{
for (auto* w : _widgets) w->renderer(r);
}
2021-08-06 14:22:56 +02:00
void Layout::_handle_rendering()
{
2021-08-06 14:22:56 +02:00
for (auto* widget_ptr : _widgets) widget_ptr->render();
}