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-2026 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 <cstdint>
8#include <memory>
9#include <set>
10#include <vector>
11
12namespace jngl {
13
14class Widget;
15
17class Container {
18public:
20 void step();
21
23 void draw() const;
24
29
31 template <class T, class... Args> T* addWidget(Args&&... args) {
32 return dynamic_cast<T*>(addWidget(std::make_unique<T>(std::forward<Args>(args)...)));
33 }
34
37
38private:
41 std::set<Widget*> needToRemove;
42 uint8_t iterating = 0;
43};
44
45} // namespace jngl
Helper class to handle multiple instances of Widget.
Definition Container.hpp:17
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 ones which request it.
T * addWidget(Args &&... args)
The same as addWidget(std::unique_ptr<Widget>) but creates the Widget for you.
Definition Container.hpp:31
T forward(T... args)
T make_unique(T... args)
JNGL's main namespace.