use unique_ptr in layout
This commit is contained in:
parent
d7abc49d07
commit
494b638e2c
2 changed files with 8 additions and 8 deletions
|
@ -25,7 +25,7 @@ concept WidgetType = std::derived_from<T, bwidgets::Widget>;
|
|||
|
||||
template<WidgetType W>
|
||||
void run_example(
|
||||
const std::function<void(const std::shared_ptr<W>&, std::shared_ptr<bwidgets::Font>,
|
||||
const std::function<void(W*, std::shared_ptr<bwidgets::Font>,
|
||||
int, int)>& setup,
|
||||
int w = 3, int h = 3)
|
||||
{
|
||||
|
@ -54,14 +54,14 @@ void run_example(
|
|||
bwidgets::AlignedLayout layout(bwidgets::AlignedLayout::Alignment::HORIZONTAL);
|
||||
|
||||
for (auto x = 0; x < w; x++) {
|
||||
auto col = std::make_shared<bwidgets::AlignedLayout>(
|
||||
auto col = std::make_unique<bwidgets::AlignedLayout>(
|
||||
bwidgets::AlignedLayout::Alignment::VERTICAL);
|
||||
for (auto y = 0; y < h; y++) {
|
||||
auto widget = std::make_shared<W>();
|
||||
setup(widget, font, x, y);
|
||||
col->add_widget(widget);
|
||||
auto widget = std::make_unique<W>();
|
||||
setup(widget.get(), font, x, y);
|
||||
col->add_widget(std::move(widget));
|
||||
}
|
||||
layout.add_widget(col);
|
||||
layout.add_widget(std::move(col));
|
||||
}
|
||||
|
||||
layout.renderer(renderer);
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace bwidgets
|
|||
class Layout : public Widget
|
||||
{
|
||||
protected:
|
||||
std::vector<std::shared_ptr<Widget>> _widgets;
|
||||
std::vector<std::unique_ptr<Widget>> _widgets;
|
||||
|
||||
void _handle_geometry_change(const SDL_Rect&) override;
|
||||
void _handle_renderer_change(const std::shared_ptr<Renderer>&) override;
|
||||
|
@ -35,7 +35,7 @@ namespace bwidgets
|
|||
auto handle_event(const SDL_Event&) -> Layout* override;
|
||||
[[nodiscard]] auto size() const noexcept -> Size override = 0;
|
||||
|
||||
virtual auto add_widget(const std::shared_ptr<Widget>&) -> Layout*;
|
||||
virtual auto add_widget(std::unique_ptr<Widget>) -> Layout*;
|
||||
virtual void for_widgets(const std::function<void(Widget*)>&);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue