Skip to content

Commit

Permalink
Added deferred to removal list
Browse files Browse the repository at this point in the history
  • Loading branch information
ebasconp committed Jan 4, 2025
1 parent 9533a0c commit faeb2ba
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
9 changes: 4 additions & 5 deletions code/classeine-lib/clsn/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
14 changes: 14 additions & 0 deletions code/classeine-lib/clsn/ui/default_ui_layer_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <clsn/ui/default_ui_layer_manager.h>
#include <clsn/ui/layer.h>
#include <clsn/ui/ui_system_backend.h>


#include <ranges>

Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ namespace clsn::ui::impl::sdl2
repaint_all();

SDL_Delay(4);

m_items_to_remove.clear();
return true;
}

Expand All @@ -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)
Expand All @@ -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<control>& ctrl)
{
m_items_to_remove.push_back(ctrl);
}

void ui_system_backend_sdl2_impl::defer_removal(const std::shared_ptr<layer_base>& _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}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <emscripten.h>
#endif

#include <variant>

#undef main

#include <clsn/ui/ui_system_backend.h>
Expand All @@ -39,6 +41,10 @@ namespace clsn::ui::impl::sdl2

draw::dimension m_size;

std::vector<std::variant<
std::shared_ptr<control>, std::shared_ptr<layer_base>>>
m_items_to_remove;

public:
explicit ui_system_backend_sdl2_impl(ui_manager& ui_mgr);

Expand All @@ -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<control>& ctrl) override;
void defer_removal(const std::shared_ptr<layer_base>& ctrl) override;

private:
void resize_graphics();

Expand Down
8 changes: 8 additions & 0 deletions code/classeine-lib/clsn/ui/ui_system_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@

#pragma once

#include <memory>

namespace clsn::ui
{
class control;
class layer_base;

class ui_system_backend
{
protected:
Expand All @@ -20,6 +25,9 @@ namespace clsn::ui

virtual void repaint_all() = 0;

virtual void defer_removal(const std::shared_ptr<control>& ctrl) = 0;
virtual void defer_removal(const std::shared_ptr<layer_base>& ctrl) = 0;

[[nodiscard]] virtual auto get_size() const -> const draw::dimension& = 0;
};
}

0 comments on commit faeb2ba

Please sign in to comment.