Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window focus signals #241

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/TGUI/Backend/Window/BackendGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,11 @@ TGUI_MODULE_EXPORT namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool handleTwoFingerScroll(bool wasAlreadyScrolling);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Updates internal window focus flag and emits signal if flag state was changed.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void updateWindowFocusState(bool windowFocused);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Updates the view and changes the size of the root container when needed.
// Derived classes should update m_framebufferSize in this function and then call this function from the base class.
Expand All @@ -711,6 +716,8 @@ TGUI_MODULE_EXPORT namespace tgui
public:

SignalFloatRect onViewChange = {"ViewChanged"}; //!< The view was changed. Optional parameter: new view rectangle
Signal onWindowFocus = {"Focused"}; //!< The window was focused
Signal onWindowUnfocus = {"Unfocused"}; //!< The window was unfocused


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
22 changes: 18 additions & 4 deletions src/Backend/Window/BackendGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ namespace tgui
}
case Event::Type::LostFocus:
{
m_windowFocused = false;
break;
updateWindowFocusState(false);
return true;
}
case Event::Type::GainedFocus:
{
m_windowFocused = true;
break;
updateWindowFocusState(true);
return true;
}
case Event::Type::Resized:
{
Expand Down Expand Up @@ -626,6 +626,20 @@ namespace tgui

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void BackendGui::updateWindowFocusState(bool windowFocused)
{
if(m_windowFocused != windowFocused) {
m_windowFocused = windowFocused;
if(windowFocused) {
onWindowFocus.emit(m_container.get());
} else {
onWindowUnfocus.emit(m_container.get());
}
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void BackendGui::updateContainerSize()
{
m_viewport.updateParentSize({static_cast<float>(m_framebufferSize.x), static_cast<float>(m_framebufferSize.y)});
Expand Down
Loading