Provide GuiStack class
This class is meant as an alternative to the existing manual screen handling done via GfuiScreenActivate/GfuiScreenDeactivate and GfuiScreenReplace, which is error-prone and might lead to double-free errors. Instead, GuiStack is a singleton class based in std::stack which provides push/pop functions to allow switching easily between screens.
This commit is contained in:
parent
7aa114efb1
commit
1567936498
|
@ -0,0 +1,46 @@
|
|||
#include "guistack.h"
|
||||
#include "tgfclient.h"
|
||||
#include <stack>
|
||||
#include <cstddef>
|
||||
|
||||
GuiStack &
|
||||
GuiStack::get()
|
||||
{
|
||||
static GuiStack stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
void *
|
||||
GuiStack::top()
|
||||
{
|
||||
GuiStack &g = get();
|
||||
|
||||
return g.screens.empty() ? NULL : g.screens.top();
|
||||
}
|
||||
|
||||
void
|
||||
GuiStack::push(void *screen)
|
||||
{
|
||||
get().screens.push(screen);
|
||||
GfuiScreenActivate(screen);
|
||||
}
|
||||
|
||||
void *
|
||||
GuiStack::pop()
|
||||
{
|
||||
void *ret;
|
||||
GuiStack &g = get();
|
||||
|
||||
if (g.screens.empty())
|
||||
return NULL;
|
||||
|
||||
GfuiScreenRelease(g.screens.top());
|
||||
g.screens.pop();
|
||||
|
||||
if (g.screens.empty())
|
||||
return NULL;
|
||||
|
||||
ret = g.screens.top();
|
||||
GfuiScreenActivate(ret);
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef GUI_STACK_H
|
||||
#define GUI_STACK_H
|
||||
|
||||
#include <stack>
|
||||
|
||||
class GuiStack
|
||||
{
|
||||
public:
|
||||
static void *top();
|
||||
static void push(void *screen);
|
||||
static void *pop();
|
||||
|
||||
private:
|
||||
static GuiStack &get();
|
||||
GuiStack() {};
|
||||
void operator=(const GuiStack &);
|
||||
std::stack<void *> screens;
|
||||
};
|
||||
|
||||
#endif /* GUI_STACK_H */
|
Loading…
Reference in New Issue