JNGL
Container.hpp
Go to the documentation of this file.
1 // Copyright 2020-2021 Jan Niklas Hasse <[email protected]>
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 
11 namespace jngl {
12 
13 class Widget;
14 
16 class Container {
17 public:
19  void step();
20 
22  void draw() const;
23 
26 
28  template <class T, class... Args>
29  void addWidget(Args&&... args) {
30  addWidget(std::make_unique<T>(std::forward<Args>(args)...));
31  }
32 
35 
36 private:
38  std::set<Widget*> needToRemove;
39 };
40 
41 } // namespace jngl
Helper class to handle multiple instances of Widget.
Definition: Container.hpp:16
void addWidget(std::unique_ptr< Widget >)
Immediately adds a Widget to the container.
void draw() const
Calls Widget::draw of every widget.
void addWidget(Args &&... args)
The same as addWidget(std::unique_ptr<Widget>) but creates the Widget for you.
Definition: Container.hpp:29
void removeWidget(Widget *)
Marks a Widget to be removed by Container::step.
void step()
Calls Widget::step of every widget and removes the once which request it.
JNGL's main namespace.
Definition: App.hpp:10