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> T* addWidget(Args&&... args) {
29  return dynamic_cast<T*>(addWidget(std::make_unique<T>(std::forward<Args>(args)...)));
30  }
31 
34 
35 private:
37  std::set<Widget*> needToRemove;
38 };
39 
40 } // namespace jngl
Helper class to handle multiple instances of Widget.
Definition: Container.hpp:16
void draw() const
Calls Widget::draw of every widget.
T * addWidget(Args &&... args)
The same as addWidget(std::unique_ptr<Widget>) but creates the Widget for you.
Definition: Container.hpp:28
void removeWidget(Widget *)
Marks a Widget to be removed by Container::step.
Widget * addWidget(std::unique_ptr< Widget >)
Immediately adds a Widget to the container.
void step()
Calls Widget::step of every widget and removes the once which request it.
JNGL's main namespace.
Definition: App.hpp:10