diff --git a/code/classeine-lib/clsn/core/system.cpp b/code/classeine-lib/clsn/core/system.cpp index d5cfdfe35..71afe333f 100644 --- a/code/classeine-lib/clsn/core/system.cpp +++ b/code/classeine-lib/clsn/core/system.cpp @@ -85,11 +85,10 @@ namespace clsn::core } else { - static std::string build_id = strings::format("{}-{}.{}", - get_version(), - get_compilation_date(), - get_compilation_time()); - return build_id; + return strings::format("{}-{}.{}", + get_version(), + get_compilation_date(), + get_compilation_time()); } } diff --git a/code/classeine-lib/clsn/ui/default_ui_layer_manager.cpp b/code/classeine-lib/clsn/ui/default_ui_layer_manager.cpp index 9c48ffead..464a4a9b1 100644 --- a/code/classeine-lib/clsn/ui/default_ui_layer_manager.cpp +++ b/code/classeine-lib/clsn/ui/default_ui_layer_manager.cpp @@ -7,6 +7,8 @@ #include #include +#include + #include @@ -96,6 +98,18 @@ namespace clsn::ui auto next_layer = _layer.get_next_layer(); auto prev_layer = _layer.get_previous_layer(); + if (m_layer_count == 1) + { + get_ui_manager().get_system_backend().defer_removal(m_first_layer); + } + else + { + auto this_layer_ptr = + _layer.get_previous_layer().get_ref().get_next_layer(); + + get_ui_manager().get_system_backend().defer_removal(this_layer_ptr); + } + if (&m_last_layer.get_ref() == &_layer) m_last_layer = prev_layer; diff --git a/code/classeine-lib/clsn/ui/impl/sdl2/ui_system_backend_sdl2_impl.cpp b/code/classeine-lib/clsn/ui/impl/sdl2/ui_system_backend_sdl2_impl.cpp index 2c072e8fc..0040ccb96 100644 --- a/code/classeine-lib/clsn/ui/impl/sdl2/ui_system_backend_sdl2_impl.cpp +++ b/code/classeine-lib/clsn/ui/impl/sdl2/ui_system_backend_sdl2_impl.cpp @@ -203,6 +203,8 @@ namespace clsn::ui::impl::sdl2 repaint_all(); SDL_Delay(4); + + m_items_to_remove.clear(); return true; } @@ -212,7 +214,6 @@ namespace clsn::ui::impl::sdl2 { // Do nothing here } - } void ui_system_backend_sdl2_impl::trigger_mouse_click_event(const SDL_Event& e, Uint32 type) @@ -229,6 +230,16 @@ namespace clsn::ui::impl::sdl2 m_ui_manager.get_layer_manager().process_mouse_click_event(_mouse_click_event); } + void ui_system_backend_sdl2_impl::defer_removal(const std::shared_ptr& ctrl) + { + m_items_to_remove.push_back(ctrl); + } + + void ui_system_backend_sdl2_impl::defer_removal(const std::shared_ptr& _layer) + { + m_items_to_remove.push_back(_layer); + } + void ui_system_backend_sdl2_impl::trigger_mouse_moved_event(const SDL_Event& e) { events::mouse_moved_event _mouse_moved_event{{e.motion.x, e.motion.y}}; diff --git a/code/classeine-lib/clsn/ui/impl/sdl2/ui_system_backend_sdl2_impl.h b/code/classeine-lib/clsn/ui/impl/sdl2/ui_system_backend_sdl2_impl.h index 8d6f80cc7..992b370b0 100644 --- a/code/classeine-lib/clsn/ui/impl/sdl2/ui_system_backend_sdl2_impl.h +++ b/code/classeine-lib/clsn/ui/impl/sdl2/ui_system_backend_sdl2_impl.h @@ -15,6 +15,8 @@ #include #endif +#include + #undef main #include @@ -39,6 +41,10 @@ namespace clsn::ui::impl::sdl2 draw::dimension m_size; + std::vector, std::shared_ptr>> + m_items_to_remove; + public: explicit ui_system_backend_sdl2_impl(ui_manager& ui_mgr); @@ -50,6 +56,9 @@ namespace clsn::ui::impl::sdl2 [[nodiscard]] auto get_size() const -> const draw::dimension& override; + void defer_removal(const std::shared_ptr& ctrl) override; + void defer_removal(const std::shared_ptr& ctrl) override; + private: void resize_graphics(); diff --git a/code/classeine-lib/clsn/ui/ui_system_backend.h b/code/classeine-lib/clsn/ui/ui_system_backend.h index 65011675d..5cef92128 100644 --- a/code/classeine-lib/clsn/ui/ui_system_backend.h +++ b/code/classeine-lib/clsn/ui/ui_system_backend.h @@ -5,8 +5,13 @@ #pragma once +#include + namespace clsn::ui { + class control; + class layer_base; + class ui_system_backend { protected: @@ -20,6 +25,9 @@ namespace clsn::ui virtual void repaint_all() = 0; + virtual void defer_removal(const std::shared_ptr& ctrl) = 0; + virtual void defer_removal(const std::shared_ptr& ctrl) = 0; + [[nodiscard]] virtual auto get_size() const -> const draw::dimension& = 0; }; } \ No newline at end of file