Skip to content

Commit

Permalink
Better navigation in the scroll view when using focus system (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 17, 2025
1 parent 0af24eb commit e789aea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/xrUICore/ListBox/UIListBoxItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ void CUIListBoxItem::OnFocusReceive()
{
inherited::OnFocusReceive();
GetMessageTarget()->SendMessage(this, LIST_ITEM_FOCUS_RECEIVED);
if (UI().Focus().GetFocused() == this)
{
smart_cast<CUIScrollView*>(GetParent()->GetParent())->SetSelected(this);
GetMessageTarget()->SendMessage(this, LIST_ITEM_SELECT, &tag);
}
}

void CUIListBoxItem::InitDefault() { InitTexture("ui_listline"); }
Expand Down
36 changes: 30 additions & 6 deletions src/xrUICore/ScrollView/UIScrollView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,31 @@ CUIScrollView::~CUIScrollView() { Clear(); }
void CUIScrollView::SendMessage(CUIWindow* pWnd, s16 msg, void* pData)
{
CUIWndCallback::OnEvent(pWnd, msg, pData);
if (CHILD_CHANGED_SIZE == msg && m_pad->IsChild(pWnd))
m_flags.set(eNeedRecalc, true);

switch (msg)
{
case CHILD_CHANGED_SIZE:
{
if (m_pad->IsChild(pWnd))
m_flags.set(eNeedRecalc, true);
break;
}
case WINDOW_FOCUS_RECEIVED:
{
if (UI().Focus().GetFocused() != pWnd)
break;

if (const auto& item = pWnd->GetWindowBeforeParent(m_pad);
item && item != GetSelected())
{
const auto prevPos = GetCurrentScrollPos();
ScrollToWindow(item);
if (prevPos != GetCurrentScrollPos())
UI().GetUICursor().WarpToWindow(item);
}
break;
}
} // switch (msg)
}

void CUIScrollView::ForceUpdate() { m_flags.set(eNeedRecalc, true); }
Expand Down Expand Up @@ -115,7 +138,11 @@ void CUIScrollView::Update()
if (m_flags.test(eNeedRecalc))
RecalcSize();

if (const auto focused = CursorOverWindow() ? UI().Focus().GetFocused() : nullptr)
CUIWindow* focused{};
if (m_pad->CursorOverWindow() && !m_flags.test(eItemsSelectabe))
focused = UI().Focus().GetFocused();

if (focused)
{
const auto scrollItem = focused->GetWindowBeforeParent(m_pad);

Expand All @@ -125,9 +152,6 @@ void CUIScrollView::Update()

ScrollToWindow(scrollItem);

if (m_flags.test(eItemsSelectabe))
scrollItem->OnMouseDown(MOUSE_1);

if (prevPos != GetCurrentScrollPos())
UI().GetUICursor().WarpToWindow(focused);
}
Expand Down

0 comments on commit e789aea

Please sign in to comment.