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