lxgui
Loading...
Searching...
No Matches
gui_frame_container.cpp
1#include "lxgui/gui_frame_container.hpp"
2
3#include "lxgui/gui_factory.hpp"
4#include "lxgui/gui_frame.hpp"
5#include "lxgui/gui_frame_renderer.hpp"
6#include "lxgui/gui_manager.hpp"
7#include "lxgui/gui_out.hpp"
8#include "lxgui/gui_registry.hpp"
9#include "lxgui/utils_std.hpp"
10
11namespace lxgui::gui {
12
14 factory& fac, registry& reg, utils::observer_ptr<frame_renderer> rdr) :
15 factory_(fac), registry_(reg), renderer_(rdr) {}
16
18 attr.rdr = renderer_;
19
20 auto new_frame = factory_.create_frame(registry_, attr);
21 if (!new_frame)
22 return nullptr;
23
24 return add_root_frame(std::move(new_frame));
25}
26
28 utils::observer_ptr<frame> added_frame = obj;
29 root_frames_.push_back(std::move(obj));
30 return added_frame;
31}
32
33utils::owner_ptr<frame> frame_container::remove_root_frame(const utils::observer_ptr<frame>& obj) {
34 frame* frame_raw = obj.get();
35 if (!frame_raw)
36 return nullptr;
37
38 auto iter = utils::find_if(
39 root_frames_, [&](const auto& root_frame) { return root_frame.get() == frame_raw; });
40
41 if (iter == root_frames_.end())
42 return nullptr;
43
44 // NB: the iterator is not removed yet; it will be removed later in garbage_collect().
45 return std::move(*iter);
46}
47
51
55
57 auto iter_remove = std::remove_if(
58 root_frames_.begin(), root_frames_.end(), [](auto& obj) { return obj == nullptr; });
59
60 root_frames_.erase(iter_remove, root_frames_.end());
61}
62
64 root_frames_.clear();
65}
66
67} // namespace lxgui::gui
Handles the creation of new UI objects.
utils::owner_ptr< frame > create_frame(registry &reg, const frame_core_attributes &attr)
Creates a new frame.
virtual utils::observer_ptr< frame > create_root_frame_(frame_core_attributes attr)
void garbage_collect()
Clean deleted entries from the frame list.
utils::owner_ptr< frame > remove_root_frame(const utils::observer_ptr< frame > &obj)
Remove a frame from the list of frames owned by this frame_container.
frame_container(factory &fac, registry &reg, utils::observer_ptr< frame_renderer > rdr)
Constructor.
utils::view::adaptor< const root_frame_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter > const_root_frame_list_view
utils::view::adaptor< root_frame_list, utils::view::smart_ptr_dereferencer, utils::view::non_null_filter > root_frame_list_view
root_frame_list_view get_root_frames()
Returns the root frame list.
utils::observer_ptr< frame > add_root_frame(utils::owner_ptr< frame > obj)
Make a frame owned by this frame_container.
A region that can contain other regions and react to events.
Keeps track of created UI objects and records their names for lookup.
Allow iterating over a container without access to the container itself.
auto find_if(C &v, T &&f)
Definition utils_std.hpp:19
oup::observable_sealed_ptr< T > owner_ptr
Struct holding all the core information about a frame necessary for its creation.
utils::observer_ptr< frame_renderer > rdr