mirror of https://github.com/WerWolv/ImHex
impr: Add hooks to let Views to get notified when they are opened or closed (#2493)
This is a trivial change which adds virtual methods to View, `onOpen()` and `onClose()`, which are called when the view is opened or closed. This information is already tracked inside the View, but not exposed via the API. There is `didWindowJustOpen()` and `didWindowJustClose()`, but these fetch and then reset the flag, so they can't be used more than once in a frame (and are sometimes called by the frame, meaning the flag has already been consumed by the time the View's draw callback gets called). The use case here is that I have a View which needs to do some work every time it's shown.
This commit is contained in:
parent
b30e2bcfa4
commit
c57f071f0c
|
|
@ -110,6 +110,17 @@ namespace hex {
|
|||
void trackViewState();
|
||||
void setFocused(bool focused);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Called when this view is opened (i.e. made visible).
|
||||
*/
|
||||
virtual void onOpen() {}
|
||||
|
||||
/**
|
||||
* @brief Called when this view is closed (i.e. made invisible).
|
||||
*/
|
||||
virtual void onClose() {}
|
||||
|
||||
public:
|
||||
class Window;
|
||||
class Special;
|
||||
|
|
|
|||
|
|
@ -75,9 +75,13 @@ namespace hex {
|
|||
|
||||
void View::trackViewState() {
|
||||
if (m_windowOpen && !m_prevWindowOpen)
|
||||
{
|
||||
this->setWindowJustOpened(true);
|
||||
else if (!m_windowOpen && m_prevWindowOpen)
|
||||
this->onOpen();
|
||||
} else if (!m_windowOpen && m_prevWindowOpen) {
|
||||
this->setWindowJustClosed(true);
|
||||
this->onClose();
|
||||
}
|
||||
m_prevWindowOpen = m_windowOpen;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue