JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Container.hpp
Go to the documentation of this file.
1// Copyright 2020-2023 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include <memory>
8#include <set>
9#include <vector>
10
11namespace jngl {
12
13class Widget;
14
16class Container {
17public:
19 void step();
20
22 void draw() const;
23
26
28 template <class T, class... Args> T* addWidget(Args&&... args) {
29 return dynamic_cast<T*>(addWidget(std::make_unique<T>(std::forward<Args>(args)...)));
30 }
31
34
35private:
38 std::set<Widget*> needToRemove;
39 uint8_t iterating = 0;
40};
41
42} // namespace jngl
Helper class to handle multiple instances of Widget.
Definition: Container.hpp:16
Widget * addWidget(std::unique_ptr< Widget >)
Adds a Widget to the container (safe to call during Container::step)
void draw() const
Calls Widget::draw of every widget.
void removeWidget(Widget *)
Removes a Widget from the Container (safe to call during Container::step)
void step()
Calls Widget::step of every widget and removes the once which request it.
T * addWidget(Args &&... args)
The same as addWidget(std::unique_ptr<Widget>) but creates the Widget for you.
Definition: Container.hpp:28
JNGL's main namespace.
Definition: Achievement.hpp:10