11#include <unordered_map>
17#include "SD/export.hpp"
31 template<
typename T,
typename...
Args>
32 requires std::is_base_of_v<View, T>
34 if (m_view_name_to_id.contains(name))
37 ViewId id = m_next_view_id++;
38 auto view = std::make_unique<T>(std::move(name), std::forward<Args>(
args)...);
42 m_views_by_id.emplace(
id, std::move(view));
43 m_view_name_to_id.emplace(
ref.get_name(),
id);
51 std::expected<ViewId, ViewError> get_id(
const std::string& name)
const;
54 ViewError remove(
const std::string& name);
56 template<
typename T,
typename...
Args>
57 requires std::is_base_of_v<Layer, T>
59 auto it = m_views_by_id.find(
id);
60 if (
it == m_views_by_id.end())
62 return it->second->push_layer<T>(std::forward<Args>(
args)...);
65 const std::unordered_map<ViewId, std::unique_ptr<View>>&
get_views()
const {
72 for (
auto& [
id, view] : m_views_by_id) {
79 for (
const auto& [
id, view] : m_views_by_id) {
84 std::vector<Scene*> get_scenes();
86 void update_views(
float dt);
87 void render_views(vk::CommandBuffer
cmd);
88 void cleanup_closed_views();
Definition ViewManager.hpp:26
ViewId m_next_view_id
Definition ViewManager.hpp:94
const std::unordered_map< ViewId, std::unique_ptr< View > > & get_views() const
Definition ViewManager.hpp:65
std::unordered_map< std::string, ViewId > m_view_name_to_id
Definition ViewManager.hpp:93
void for_each(F &&fn)
Definition ViewManager.hpp:71
std::expected< std::reference_wrapper< View >, ViewError > ViewResult
Definition ViewManager.hpp:47
std::unordered_map< ViewId, std::unique_ptr< View > > m_views_by_id
Definition ViewManager.hpp:92
void for_each(F &&fn) const
Definition ViewManager.hpp:78
T & create(std::string name, Args &&... args)
Definition ViewManager.hpp:33
auto & get_views()
Definition ViewManager.hpp:68
std::expected< std::reference_wrapper< T >, ViewError > push_layer(ViewId id, Args &&... args)
Definition ViewManager.hpp:58
Definition Application.hpp:28
void engine_abort(const std::string &message)
Definition base.hpp:41
ViewError
Definition View.hpp:26
@ VIEW_DOES_NOT_EXIST
Definition View.hpp:29
Definition id_types.hpp:7
constexpr T g_type_max
Definition types.hpp:21