mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 04:18:36 +00:00
More focus-related simplifications. Also: ensure search field is
auto-focused when switching back.
This commit is contained in:
parent
60f52273dd
commit
a1bb0f1de3
@ -156,6 +156,7 @@ void CategorySearchLayout::OnVisibilityChanged(bool visible) {
|
||||
this->albums->Reset();
|
||||
this->artists->Reset();
|
||||
this->genres->Reset();
|
||||
this->SetFocusIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,6 +129,7 @@ void TrackSearchLayout::OnVisibilityChanged(bool visible) {
|
||||
this->SaveSession();
|
||||
this->input->SetText("");
|
||||
this->trackList->Clear();
|
||||
this->SetFocusIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,14 +65,6 @@ bool sortByFocusOrder(IWindowPtr a, IWindowPtr b) {
|
||||
return orderA < orderB;
|
||||
}
|
||||
|
||||
static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) {
|
||||
if (newFocus) {
|
||||
newFocus->Focus();
|
||||
}
|
||||
|
||||
return newFocus;
|
||||
}
|
||||
|
||||
LayoutBase::LayoutBase(IWindow* parent)
|
||||
: Window(parent)
|
||||
, focusMode(FocusModeCircular) {
|
||||
@ -85,6 +77,13 @@ LayoutBase::~LayoutBase() {
|
||||
}
|
||||
}
|
||||
|
||||
IWindowPtr LayoutBase::AdjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) {
|
||||
if (this->IsVisible() && newFocus) {
|
||||
newFocus->Focus();
|
||||
}
|
||||
return newFocus;
|
||||
}
|
||||
|
||||
void LayoutBase::OnVisibilityChanged(bool visible) {
|
||||
if (visible) {
|
||||
for (IWindowPtr window : this->children) {
|
||||
@ -257,13 +256,13 @@ IWindowPtr LayoutBase::GetWindowAt(size_t position) {
|
||||
|
||||
bool LayoutBase::SetFocus(IWindowPtr focus) {
|
||||
if (!focus) {
|
||||
adjustFocus(GetFocus(), focus);
|
||||
this->AdjustFocus(GetFocus(), focus);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
for (size_t i = 0; i < this->focusable.size(); i++) {
|
||||
if (this->focusable[i] == focus) {
|
||||
adjustFocus(GetFocus(), focus);
|
||||
this->AdjustFocus(GetFocus(), focus);
|
||||
this->focused = i;
|
||||
return true;
|
||||
}
|
||||
@ -295,7 +294,7 @@ IWindowPtr LayoutBase::FocusNext() {
|
||||
}
|
||||
|
||||
IWindowPtr newFocus = GetFocus();
|
||||
adjustFocus(oldFocus, newFocus);
|
||||
this->AdjustFocus(oldFocus, newFocus);
|
||||
|
||||
if (notify) {
|
||||
(*notify)(FocusForward);
|
||||
@ -321,7 +320,7 @@ IWindowPtr LayoutBase::FocusPrev() {
|
||||
}
|
||||
|
||||
IWindowPtr newFocus = GetFocus();
|
||||
adjustFocus(oldFocus, newFocus);
|
||||
this->AdjustFocus(oldFocus, newFocus);
|
||||
|
||||
if (notify) {
|
||||
(*notify)(FocusBackward);
|
||||
@ -333,13 +332,13 @@ IWindowPtr LayoutBase::FocusPrev() {
|
||||
IWindowPtr LayoutBase::FocusFirst() {
|
||||
IWindowPtr oldFocus = GetFocus();
|
||||
this->focused = 0;
|
||||
return adjustFocus(oldFocus, GetFocus());
|
||||
return this->AdjustFocus(oldFocus, GetFocus());
|
||||
}
|
||||
|
||||
IWindowPtr LayoutBase::FocusLast() {
|
||||
IWindowPtr oldFocus = GetFocus();
|
||||
this->focused = (int) this->focusable.size() - 1;
|
||||
return adjustFocus(oldFocus, GetFocus());
|
||||
return this->AdjustFocus(oldFocus, GetFocus());
|
||||
}
|
||||
|
||||
IWindowPtr LayoutBase::GetFocus() {
|
||||
@ -361,7 +360,7 @@ void LayoutBase::SetFocusIndex(int index) {
|
||||
if (this->focused != index) {
|
||||
IWindowPtr oldFocus = GetFocus();
|
||||
this->focused = index;
|
||||
adjustFocus(oldFocus, GetFocus());
|
||||
this->AdjustFocus(oldFocus, GetFocus());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,6 @@ Window::Window(IWindow *parent) {
|
||||
this->focusedFrameColor = Color(Color::FrameColorFocused);
|
||||
this->drawFrame = true;
|
||||
this->isVisibleInParent = false;
|
||||
this->isFocused = false;
|
||||
this->isDirty = true;
|
||||
this->focusOrder = -1;
|
||||
this->id = NEXT_ID++;
|
||||
@ -166,7 +165,7 @@ bool Window::IsVisible() {
|
||||
}
|
||||
|
||||
bool Window::IsFocused() {
|
||||
return this->isFocused;
|
||||
return ::focused == this;
|
||||
}
|
||||
|
||||
void Window::BringToTop() {
|
||||
@ -772,8 +771,8 @@ void Window::Clear() {
|
||||
wmove(this->content, 0, 0);
|
||||
|
||||
bool focused = this->IsFocused();
|
||||
int64_t contentColor = isFocused ? this->focusedContentColor : this->contentColor;
|
||||
int64_t frameColor = isFocused ? this->focusedFrameColor : this->frameColor;
|
||||
int64_t contentColor = focused ? this->focusedContentColor : this->contentColor;
|
||||
int64_t frameColor = focused ? this->focusedFrameColor : this->frameColor;
|
||||
|
||||
if (this->content == this->frame) {
|
||||
wbkgd(this->frame, contentColor);
|
||||
@ -809,12 +808,9 @@ bool Window::IsParentVisible() {
|
||||
}
|
||||
|
||||
void Window::Focus() {
|
||||
if (!this->isFocused) {
|
||||
if (::focused && ::focused != this) {
|
||||
::focused->Blur();
|
||||
}
|
||||
if (::focused != this) {
|
||||
if (::focused) { ::focused->Blur(); }
|
||||
::focused = this;
|
||||
this->isFocused = true;
|
||||
this->isDirty = true;
|
||||
this->OnFocusChanged(true);
|
||||
this->RepaintBackground();
|
||||
@ -823,11 +819,8 @@ void Window::Focus() {
|
||||
}
|
||||
|
||||
void Window::Blur() {
|
||||
if (this->isFocused) {
|
||||
if (::focused == this) {
|
||||
::focused = nullptr;
|
||||
}
|
||||
this->isFocused = false;
|
||||
if (::focused = this) {
|
||||
::focused = nullptr;
|
||||
this->isDirty = true;
|
||||
this->OnFocusChanged(false);
|
||||
this->RepaintBackground();
|
||||
|
@ -105,6 +105,8 @@ namespace cursespp {
|
||||
virtual void OnVisibilityChanged(bool visible);
|
||||
virtual void OnLayout();
|
||||
|
||||
IWindowPtr AdjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus);
|
||||
|
||||
private:
|
||||
void AddFocusable(IWindowPtr window);
|
||||
void RemoveFocusable(IWindowPtr window);
|
||||
|
@ -169,7 +169,7 @@ namespace cursespp {
|
||||
WINDOW* content;
|
||||
bool badBounds;
|
||||
bool drawFrame;
|
||||
bool isVisibleInParent, isFocused, isDirty;
|
||||
bool isVisibleInParent, isDirty;
|
||||
int focusOrder;
|
||||
int id;
|
||||
Color contentColor, frameColor;
|
||||
|
Loading…
x
Reference in New Issue
Block a user