mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Fixes a bug where if a nested child was focused, then the container lost
focus, then the user tabbed back to the nested layout it would not focus the first/last subview correctly.
This commit is contained in:
parent
b7ba7eb6bc
commit
b821f6a293
@ -91,32 +91,29 @@ IWindowPtr LayoutBase::EnsureValidFocus() {
|
||||
return newFocus;
|
||||
}
|
||||
|
||||
IWindowPtr LayoutBase::EnsureValidFocusFromNext() {
|
||||
auto newFocus = this->GetFocus();
|
||||
if (newFocus && this->IsVisible()) {
|
||||
LayoutBase* layout = dynamic_cast<LayoutBase*>(newFocus.get());
|
||||
if (layout) {
|
||||
layout->FocusFirst();
|
||||
}
|
||||
else {
|
||||
newFocus->Focus();
|
||||
}
|
||||
LayoutBase* LayoutBase::GetLayoutAtFocusIndex() {
|
||||
if (this->focused >= 0 && (int) this->focusable.size() > this->focused) {
|
||||
return dynamic_cast<LayoutBase*>(this->focusable.at(this->focused).get());
|
||||
}
|
||||
return newFocus;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IWindowPtr LayoutBase::EnsureValidFocusFromNext() {
|
||||
/* if the item we just focused is a layout, then we ask it to focus its
|
||||
first child. otherwise we call through to our default logic to make sure
|
||||
the regular view at the focus index is focused. */
|
||||
IWindowPtr result;
|
||||
const auto layoutAtFocus = GetLayoutAtFocusIndex();
|
||||
if (layoutAtFocus) { result = layoutAtFocus->FocusFirst(); }
|
||||
return result ? result : this->EnsureValidFocus();
|
||||
}
|
||||
|
||||
IWindowPtr LayoutBase::EnsureValidFocusFromPrev() {
|
||||
auto newFocus = this->GetFocus();
|
||||
if (newFocus && this->IsVisible()) {
|
||||
LayoutBase* layout = dynamic_cast<LayoutBase*>(newFocus.get());
|
||||
if (layout) {
|
||||
layout->FocusLast();
|
||||
}
|
||||
else {
|
||||
newFocus->Focus();
|
||||
}
|
||||
}
|
||||
return newFocus;
|
||||
/* see comment in EnsureValidFocusFromNext() */
|
||||
IWindowPtr result;
|
||||
const auto layoutAtFocus = GetLayoutAtFocusIndex();
|
||||
if (layoutAtFocus) { result = layoutAtFocus->FocusLast(); }
|
||||
return result ? result : this->EnsureValidFocus();
|
||||
}
|
||||
|
||||
void LayoutBase::OnVisibilityChanged(bool visible) {
|
||||
|
@ -115,6 +115,7 @@ namespace cursespp {
|
||||
void RemoveFocusable(IWindowPtr window);
|
||||
void SortFocusables();
|
||||
void IndexFocusables();
|
||||
LayoutBase* GetLayoutAtFocusIndex();
|
||||
|
||||
std::vector<IWindowPtr> children;
|
||||
std::vector<IWindowPtr> focusable;
|
||||
|
Loading…
Reference in New Issue
Block a user