Skip to content

Commit

Permalink
Focus system: ability to get exact information about focusable (if it…
Browse files Browse the repository at this point in the history
…'s valuable or not)
  • Loading branch information
Xottab-DUTY committed Jan 12, 2025
1 parent 9038828 commit 55a6f11
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/xrUICore/Windows/UIWindow_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ SCRIPT_EXPORT(CUIFocusSystem, (),
.def("RegisterFocusable", &CUIFocusSystem::RegisterFocusable)
.def("UnregisterFocusable", &CUIFocusSystem::UnregisterFocusable)
.def("IsRegistered", &CUIFocusSystem::IsRegistered)
.def("IsValuable", &CUIFocusSystem::IsValuable)
.def("IsNonValuable", &CUIFocusSystem::IsNonValuable)
.def("Update", &CUIFocusSystem::Update)
.def("GetFocused", &CUIFocusSystem::GetFocused)
.def("SetFocused", &CUIFocusSystem::SetFocused)
Expand Down
17 changes: 14 additions & 3 deletions src/xrUICore/ui_focus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,25 @@ void CUIFocusSystem::UnregisterFocusable(const CUIWindow* focusable)
}

bool CUIFocusSystem::IsRegistered(const CUIWindow* focusable) const
{
return IsValuable(focusable) || IsNonValuable(focusable);
}

bool CUIFocusSystem::IsValuable(const CUIWindow* focusable) const
{
if (!focusable)
return false;

const auto it = std::find(m_valuable.begin(), m_valuable.end(), focusable);
const auto it2 = std::find(m_non_valuable.begin(), m_non_valuable.end(), focusable);
return it != m_valuable.end();
}

bool CUIFocusSystem::IsNonValuable(const CUIWindow* focusable) const
{
if (!focusable)
return false;
const auto it = std::find(m_non_valuable.begin(), m_non_valuable.end(), focusable);
return it != m_non_valuable.end();

return it != m_valuable.end() || it2 != m_non_valuable.end();
}

void CUIFocusSystem::Update(const CUIWindow* root)
Expand Down
3 changes: 3 additions & 0 deletions src/xrUICore/ui_focus.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ class XRUICORE_API CUIFocusSystem

void RegisterFocusable(const CUIWindow* focusable);
void UnregisterFocusable(const CUIWindow* focusable);

bool IsRegistered(const CUIWindow* focusable) const;
bool IsValuable(const CUIWindow* focusable) const;
bool IsNonValuable(const CUIWindow* focusable) const;

void Update(const CUIWindow* root);

Expand Down

0 comments on commit 55a6f11

Please sign in to comment.