Skip to content

Commit

Permalink
Added RAII helper struct to manage a floating label's lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Mar 18, 2018
1 parent 07844f4 commit 92d51b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/floating_label.cpp
Expand Up @@ -230,6 +230,18 @@ SDL_Rect get_floating_label_rect(int handle)
return sdl::empty_rect;
}

floating_label_scope_helper::floating_label_scope_helper(int handle)
: id(handle)
{
}

floating_label_scope_helper::~floating_label_scope_helper()
{
if(id != 0) {
remove_floating_label(id);
}
}

floating_label_context::floating_label_context()
{
label_contexts.push(std::set<int>());
Expand Down
9 changes: 9 additions & 0 deletions src/floating_label.hpp
Expand Up @@ -21,6 +21,15 @@

namespace font
{
/** Helper struct which removes the floating label with the given id upon destruction. */
struct floating_label_scope_helper
{
floating_label_scope_helper(int handle = 0);
~floating_label_scope_helper();

int id;
};

/**
* Struct which will hide all current floating labels, and cause floating labels
* instantiated after it is created to be displayed.
Expand Down

0 comments on commit 92d51b8

Please sign in to comment.