Browse Source

Add Window::onFocus event

Signed-off-by: falkTX <falktx@falktx.com>
pull/272/head
falkTX 4 years ago
parent
commit
74680dedcf
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 34 additions and 12 deletions
  1. +12
    -6
      dgl/Window.hpp
  2. +8
    -4
      dgl/src/Window.cpp
  3. +13
    -2
      dgl/src/WindowPrivateData.cpp
  4. +1
    -0
      dgl/src/WindowPrivateData.hpp

+ 12
- 6
dgl/Window.hpp View File

@@ -241,12 +241,6 @@ public:
inline double getScaling() const noexcept { return getScaling(); }

protected:
/**
A function called when the window is resized.
If there is a top-level widget associated with this window, its size will be set right after this function.
*/
virtual void onReshape(uint width, uint height);

/**
A function called when the window is attempted to be closed.
Returning true closes the window, which is the default behaviour.
@@ -254,6 +248,18 @@ protected:
*/
virtual bool onClose();

/**
A function called when the window gains or loses the keyboard focus.
The default implementation does nothing.
*/
virtual void onFocus(bool focus);

/**
A function called when the window is resized.
If there is a top-level widget associated with this window, its size will be set right after this function.
*/
virtual void onReshape(uint width, uint height);

private:
struct PrivateData;
PrivateData* const pData;


+ 8
- 4
dgl/src/Window.cpp View File

@@ -227,14 +227,18 @@ void Window::setGeometryConstraints(const uint minimumWidth,
}
}

void Window::onReshape(uint, uint)
bool Window::onClose()
{
puglFallbackOnResize(pData->view);
return true;
}

bool Window::onClose()
void Window::onFocus(bool)
{
return true;
}

void Window::onReshape(uint, uint)
{
puglFallbackOnResize(pData->view);
}

#if 0


+ 13
- 2
dgl/src/WindowPrivateData.cpp View File

@@ -384,6 +384,18 @@ void Window::PrivateData::onPuglClose()
close();
}

void Window::PrivateData::onPuglFocus(const bool focus)
{
DGL_DBGp("onPuglFocus : %i %u %u\n", focus);

// if (fModal.childFocus != nullptr)
// return fModal.childFocus->focus();

#ifndef DPF_TEST_WINDOW_CPP
self->onFocus(focus);
#endif
}

void Window::PrivateData::onPuglKey(const Events::KeyboardEvent& ev)
{
DGL_DBGp("onPuglKey : %i %u %u\n", ev.press, ev.key, ev.keycode);
@@ -518,10 +530,9 @@ PuglStatus Window::PrivateData::puglEventCallback(PuglView* const view, const Pu

///< Keyboard focus entered view, a #PuglEventFocus
case PUGL_FOCUS_IN:
break;

///< Keyboard focus left view, a #PuglEventFocus
case PUGL_FOCUS_OUT:
pData->onPuglFocus(event->type == PUGL_FOCUS_IN);
break;

///< Key pressed, a #PuglEventKey


+ 1
- 0
dgl/src/WindowPrivateData.hpp View File

@@ -109,6 +109,7 @@ struct Window::PrivateData : IdleCallback {
void onPuglConfigure(int width, int height);
void onPuglExpose();
void onPuglClose();
void onPuglFocus(bool focus);
void onPuglKey(const Events::KeyboardEvent& ev);
void onPuglSpecial(const Events::SpecialEvent& ev);
void onPuglText(const Events::CharacterInputEvent& ev);


Loading…
Cancel
Save