Added RAII helper struct to manage a floating label's lifetime

This commit is contained in:
Charles Dang 2017-07-19 15:39:06 +11:00
parent 07844f471b
commit 92d51b866d
2 changed files with 21 additions and 0 deletions

View file

@ -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>());

View file

@ -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.