mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Experimental focus stuff, take two.
This commit is contained in:
parent
2e1ea995cf
commit
0cb83b94d1
@ -148,7 +148,6 @@ void CategorySearchLayout::OnVisibilityChanged(bool visible) {
|
|||||||
LayoutBase::OnVisibilityChanged(visible);
|
LayoutBase::OnVisibilityChanged(visible);
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
this->SetFocus(this->input);
|
|
||||||
this->Requery();
|
this->Requery();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -306,7 +306,6 @@ IWindowPtr LibraryLayout::FocusNext() {
|
|||||||
return this->transportView;
|
return this->transportView;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->transportView->Blur();
|
|
||||||
return this->visibleLayout->FocusFirst();
|
return this->visibleLayout->FocusFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,7 +318,6 @@ IWindowPtr LibraryLayout::FocusPrev() {
|
|||||||
return this->transportView;
|
return this->transportView;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->transportView->Blur();
|
|
||||||
return this->visibleLayout->FocusLast();
|
return this->visibleLayout->FocusLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,12 +450,10 @@ bool LibraryLayout::KeyPress(const std::string& key) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (this->GetFocus() == this->transportView && Hotkeys::Is(Hotkeys::Up, key)) {
|
else if (this->GetFocus() == this->transportView && Hotkeys::Is(Hotkeys::Up, key)) {
|
||||||
this->transportView->Blur();
|
|
||||||
this->visibleLayout->FocusLast();
|
this->visibleLayout->FocusLast();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (this->GetFocus() == this->transportView && Hotkeys::Is(Hotkeys::Down, key)) {
|
else if (this->GetFocus() == this->transportView && Hotkeys::Is(Hotkeys::Down, key)) {
|
||||||
this->transportView->Blur();
|
|
||||||
this->visibleLayout->FocusFirst();
|
this->visibleLayout->FocusFirst();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -542,7 +542,6 @@ void SettingsLayout::OnVisibilityChanged(bool visible) {
|
|||||||
LayoutBase::OnVisibilityChanged(visible);
|
LayoutBase::OnVisibilityChanged(visible);
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
this->FocusFirst();
|
|
||||||
this->RefreshAddedPaths();
|
this->RefreshAddedPaths();
|
||||||
this->LoadPreferences();
|
this->LoadPreferences();
|
||||||
this->CheckShowFirstRunDialog();
|
this->CheckShowFirstRunDialog();
|
||||||
|
@ -123,7 +123,6 @@ void TrackSearchLayout::OnVisibilityChanged(bool visible) {
|
|||||||
LayoutBase::OnVisibilityChanged(visible);
|
LayoutBase::OnVisibilityChanged(visible);
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
this->SetFocus(this->input);
|
|
||||||
this->Requery();
|
this->Requery();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -360,7 +360,6 @@ void TransportWindow::SetFocus(FocusTarget target) {
|
|||||||
|
|
||||||
if (this->focus == FocusNone) {
|
if (this->focus == FocusNone) {
|
||||||
this->lastFocus = last;
|
this->lastFocus = last;
|
||||||
this->Blur();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->Focus();
|
this->Focus();
|
||||||
|
@ -449,10 +449,6 @@ process:
|
|||||||
|
|
||||||
void App::UpdateFocusedWindow(IWindowPtr window) {
|
void App::UpdateFocusedWindow(IWindowPtr window) {
|
||||||
if (this->state.focused != window) {
|
if (this->state.focused != window) {
|
||||||
if (this->state.focused) {
|
|
||||||
this->state.focused->Blur();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->state.focused = window;
|
this->state.focused = window;
|
||||||
this->state.input = dynamic_cast<IInput*>(window.get());
|
this->state.input = dynamic_cast<IInput*>(window.get());
|
||||||
this->state.keyHandler = dynamic_cast<IKeyHandler*>(window.get());
|
this->state.keyHandler = dynamic_cast<IKeyHandler*>(window.get());
|
||||||
@ -496,6 +492,7 @@ void App::CheckShowOverlay() {
|
|||||||
newTopLayout->Layout();
|
newTopLayout->Layout();
|
||||||
newTopLayout->Show();
|
newTopLayout->Show();
|
||||||
newTopLayout->BringToTop();
|
newTopLayout->BringToTop();
|
||||||
|
newTopLayout->FocusFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,13 +146,8 @@ IWindowPtr AppLayout::FocusPrev() {
|
|||||||
void AppLayout::SetLayout(std::shared_ptr<cursespp::LayoutBase> layout) {
|
void AppLayout::SetLayout(std::shared_ptr<cursespp::LayoutBase> layout) {
|
||||||
if (layout != this->layout) {
|
if (layout != this->layout) {
|
||||||
if (this->layout) {
|
if (this->layout) {
|
||||||
if (this->lastFocus) {
|
|
||||||
this->layout->SetFocus(this->lastFocus);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->RemoveWindow(this->layout);
|
this->RemoveWindow(this->layout);
|
||||||
last(this->layout.get(), this->layout->GetFocusIndex());
|
last(this->layout.get(), this->layout->GetFocusIndex());
|
||||||
this->layout->SetFocusIndex(-1);
|
|
||||||
this->layout->Hide();
|
this->layout->Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +168,12 @@ void AppLayout::SetLayout(std::shared_ptr<cursespp::LayoutBase> layout) {
|
|||||||
|
|
||||||
this->AddWindow(this->layout);
|
this->AddWindow(this->layout);
|
||||||
this->layout->SetFocusOrder(0);
|
this->layout->SetFocusOrder(0);
|
||||||
this->layout->SetFocusIndex(last(this->layout.get()));
|
|
||||||
|
if (!this->shortcuts->IsFocused()) {
|
||||||
|
auto lastFocusIndex = last(this->layout.get());
|
||||||
|
this->layout->SetFocusIndex(lastFocusIndex);
|
||||||
|
}
|
||||||
|
|
||||||
this->Layout();
|
this->Layout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ cursespp::IWindowPtr AppLayout::BlurShortcuts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!refocused) {
|
if (!refocused) {
|
||||||
this->layout->FocusNext();
|
this->layout->FocusFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,11 +203,6 @@ void AppLayout::FocusShortcuts() {
|
|||||||
|
|
||||||
if (this->layout) {
|
if (this->layout) {
|
||||||
this->lastFocus = this->layout->GetFocus();
|
this->lastFocus = this->layout->GetFocus();
|
||||||
|
|
||||||
if (this->lastFocus) {
|
|
||||||
this->lastFocus->Blur();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->layout->SetFocus(IWindowPtr());
|
this->layout->SetFocus(IWindowPtr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,6 @@ InputOverlay& InputOverlay::SetInputAcceptedCallback(InputAcceptedCallback cb) {
|
|||||||
|
|
||||||
void InputOverlay::OnVisibilityChanged(bool visible) {
|
void InputOverlay::OnVisibilityChanged(bool visible) {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
this->SetFocus(this->textInput);
|
|
||||||
this->Redraw();
|
this->Redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
|
|
||||||
using namespace cursespp;
|
using namespace cursespp;
|
||||||
|
|
||||||
static const int AUTO_FOCUS = -1;
|
|
||||||
static const int NO_FOCUS = -2;
|
static const int NO_FOCUS = -2;
|
||||||
|
|
||||||
template <typename T> static int find(std::vector<T>& haystack, T& needle) {
|
template <typename T> static int find(std::vector<T>& haystack, T& needle) {
|
||||||
@ -67,10 +66,6 @@ bool sortByFocusOrder(IWindowPtr a, IWindowPtr b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) {
|
static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) {
|
||||||
if (oldFocus) {
|
|
||||||
oldFocus->Blur();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newFocus) {
|
if (newFocus) {
|
||||||
newFocus->Focus();
|
newFocus->Focus();
|
||||||
}
|
}
|
||||||
@ -81,7 +76,6 @@ static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) {
|
|||||||
LayoutBase::LayoutBase(IWindow* parent)
|
LayoutBase::LayoutBase(IWindow* parent)
|
||||||
: Window(parent)
|
: Window(parent)
|
||||||
, focusMode(FocusModeCircular) {
|
, focusMode(FocusModeCircular) {
|
||||||
this->focused = AUTO_FOCUS;
|
|
||||||
this->SetFrameVisible(false);
|
this->SetFrameVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,11 +235,6 @@ void LayoutBase::SortFocusables() {
|
|||||||
if (focusedWindow) {
|
if (focusedWindow) {
|
||||||
this->focused = find(this->focusable, focusedWindow);
|
this->focused = find(this->focusable, focusedWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (focused == AUTO_FOCUS && this->focusable.size() > 0) {
|
|
||||||
this->focused = 0;
|
|
||||||
adjustFocus(IWindowPtr(), this->focusable[this->focused]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutBase::RemoveFocusable(IWindowPtr window) {
|
void LayoutBase::RemoveFocusable(IWindowPtr window) {
|
||||||
@ -269,7 +258,6 @@ IWindowPtr LayoutBase::GetWindowAt(size_t position) {
|
|||||||
bool LayoutBase::SetFocus(IWindowPtr focus) {
|
bool LayoutBase::SetFocus(IWindowPtr focus) {
|
||||||
if (!focus) {
|
if (!focus) {
|
||||||
adjustFocus(GetFocus(), focus);
|
adjustFocus(GetFocus(), focus);
|
||||||
this->focused = AUTO_FOCUS;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -292,7 +280,7 @@ IWindowPtr LayoutBase::FocusNext() {
|
|||||||
/* nothing. we're already terminated. */
|
/* nothing. we're already terminated. */
|
||||||
notify = &FocusTerminated;
|
notify = &FocusTerminated;
|
||||||
}
|
}
|
||||||
else if (this->focused + 1 >= AUTO_FOCUS) {
|
else {
|
||||||
++this->focused;
|
++this->focused;
|
||||||
if (this->focused >= (int) this->focusable.size()) {
|
if (this->focused >= (int) this->focusable.size()) {
|
||||||
if (this->focusMode == FocusModeCircular) {
|
if (this->focusMode == FocusModeCircular) {
|
||||||
|
@ -278,9 +278,7 @@ bool ListOverlay::KeyPress(const std::string& key) {
|
|||||||
|
|
||||||
void ListOverlay::OnVisibilityChanged(bool visible) {
|
void ListOverlay::OnVisibilityChanged(bool visible) {
|
||||||
LayoutBase::OnVisibilityChanged(visible);
|
LayoutBase::OnVisibilityChanged(visible);
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
this->LayoutBase::SetFocus(this->listWindow);
|
|
||||||
this->UpdateContents();
|
this->UpdateContents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ static int NEXT_ID = 0;
|
|||||||
static bool drawPending = false;
|
static bool drawPending = false;
|
||||||
static bool freeze = false;
|
static bool freeze = false;
|
||||||
static Window* top = nullptr;
|
static Window* top = nullptr;
|
||||||
|
static Window* focused = nullptr;
|
||||||
|
|
||||||
static MessageQueue messageQueue;
|
static MessageQueue messageQueue;
|
||||||
static std::shared_ptr<INavigationKeys> keys;
|
static std::shared_ptr<INavigationKeys> keys;
|
||||||
@ -147,6 +148,8 @@ Window::Window(IWindow *parent) {
|
|||||||
|
|
||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
messageQueue.Remove(this);
|
messageQueue.Remove(this);
|
||||||
|
if (::top == this) { top = nullptr; }
|
||||||
|
if (::focused == this) { focused = nullptr; }
|
||||||
this->Destroy();
|
this->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,6 +810,10 @@ bool Window::IsParentVisible() {
|
|||||||
|
|
||||||
void Window::Focus() {
|
void Window::Focus() {
|
||||||
if (!this->isFocused) {
|
if (!this->isFocused) {
|
||||||
|
if (::focused && ::focused != this) {
|
||||||
|
::focused->Blur();
|
||||||
|
}
|
||||||
|
::focused = this;
|
||||||
this->isFocused = true;
|
this->isFocused = true;
|
||||||
this->isDirty = true;
|
this->isDirty = true;
|
||||||
this->OnFocusChanged(true);
|
this->OnFocusChanged(true);
|
||||||
@ -817,6 +824,9 @@ void Window::Focus() {
|
|||||||
|
|
||||||
void Window::Blur() {
|
void Window::Blur() {
|
||||||
if (this->isFocused) {
|
if (this->isFocused) {
|
||||||
|
if (::focused == this) {
|
||||||
|
::focused = nullptr;
|
||||||
|
}
|
||||||
this->isFocused = false;
|
this->isFocused = false;
|
||||||
this->isDirty = true;
|
this->isDirty = true;
|
||||||
this->OnFocusChanged(false);
|
this->OnFocusChanged(false);
|
||||||
|
@ -55,6 +55,8 @@ namespace cursespp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
virtual ~ILayout() { }
|
virtual ~ILayout() { }
|
||||||
|
virtual IWindowPtr FocusFirst() = 0;
|
||||||
|
virtual IWindowPtr FocusLast() = 0;
|
||||||
virtual IWindowPtr FocusNext() = 0;
|
virtual IWindowPtr FocusNext() = 0;
|
||||||
virtual IWindowPtr FocusPrev() = 0;
|
virtual IWindowPtr FocusPrev() = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user