mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-14 18:40:48 +00:00
- Modified LayoutBase to emit events on focus terminate or wrap
- Updated LibraryLayout to use FocusTerminated event to simplify logic around focusing the transport, instead of using null checks in FocusNext() and FocusPrev().
This commit is contained in:
parent
935ed10de9
commit
c9945d5af8
src/musikbox
@ -105,10 +105,15 @@ void LibraryLayout::ChangeMainLayout(std::shared_ptr<cursespp::LayoutBase> newLa
|
||||
|
||||
if (this->visibleLayout) {
|
||||
this->RemoveWindow(this->visibleLayout);
|
||||
this->visibleLayout->FocusTerminated.disconnect(this);
|
||||
this->visibleLayout->Hide();
|
||||
}
|
||||
|
||||
this->visibleLayout = newLayout;
|
||||
|
||||
this->visibleLayout->FocusTerminated.connect(
|
||||
this, &LibraryLayout::OnMainLayoutFocusTerminated);
|
||||
|
||||
this->AddWindow(this->visibleLayout);
|
||||
this->visibleLayout->Layout();
|
||||
this->visibleLayout->Show();
|
||||
@ -229,15 +234,7 @@ IWindowPtr LibraryLayout::FocusNext() {
|
||||
return this->FocusTransportNext();
|
||||
}
|
||||
|
||||
IWindowPtr focus = this->visibleLayout->FocusNext();
|
||||
|
||||
/* no next focus? kick over to the transport */
|
||||
if (!focus) {
|
||||
this->transportView->FocusFirst();
|
||||
focus = this->transportView;
|
||||
}
|
||||
|
||||
return focus;
|
||||
return this->visibleLayout->FocusNext();
|
||||
}
|
||||
|
||||
IWindowPtr LibraryLayout::FocusPrev() {
|
||||
@ -245,14 +242,18 @@ IWindowPtr LibraryLayout::FocusPrev() {
|
||||
return this->FocusTransportPrev();
|
||||
}
|
||||
|
||||
IWindowPtr focus = this->visibleLayout->FocusPrev();
|
||||
return this->visibleLayout->FocusPrev();
|
||||
}
|
||||
|
||||
if (!focus) {
|
||||
this->transportView->FocusLast();
|
||||
focus = this->transportView;
|
||||
void LibraryLayout::OnMainLayoutFocusTerminated(
|
||||
LayoutBase::FocusDirection direction)
|
||||
{
|
||||
if (direction == LayoutBase::FocusForward) {
|
||||
this->transportView->FocusFirst();
|
||||
}
|
||||
else {
|
||||
this->transportView->FocusLast();
|
||||
}
|
||||
|
||||
return focus;
|
||||
}
|
||||
|
||||
IWindowPtr LibraryLayout::GetFocus() {
|
||||
@ -260,16 +261,7 @@ IWindowPtr LibraryLayout::GetFocus() {
|
||||
return this->transportView;
|
||||
}
|
||||
|
||||
/* if nothing in the visible layout is focused, go
|
||||
ahead and focus the transport so the user has something
|
||||
to interact with. */
|
||||
IWindowPtr focused = this->visibleLayout->GetFocus();
|
||||
if (!focused) {
|
||||
this->transportView->FocusFirst();
|
||||
return this->transportView;
|
||||
}
|
||||
|
||||
return focused;
|
||||
return this->visibleLayout->GetFocus();
|
||||
}
|
||||
|
||||
bool LibraryLayout::SetFocus(cursespp::IWindowPtr window) {
|
||||
|
@ -82,6 +82,9 @@ namespace musik {
|
||||
std::string fieldType,
|
||||
DBID fieldId);
|
||||
|
||||
void OnMainLayoutFocusTerminated(
|
||||
LayoutBase::FocusDirection direction);
|
||||
|
||||
void InitializeWindows();
|
||||
|
||||
void ShowNowPlaying();
|
||||
|
@ -247,38 +247,61 @@ bool LayoutBase::SetFocus(IWindowPtr focus) {
|
||||
}
|
||||
|
||||
IWindowPtr LayoutBase::FocusNext() {
|
||||
sigslot::signal1<FocusDirection>* notify = nullptr;
|
||||
|
||||
IWindowPtr oldFocus = GetFocus();
|
||||
if (this->focused == NO_FOCUS && this->focusMode == FocusModeTerminating) {
|
||||
/* nothing. we're already terminated. */
|
||||
notify = &FocusTerminated;
|
||||
}
|
||||
else if (this->focused + 1 >= AUTO_FOCUS) {
|
||||
++this->focused;
|
||||
if (this->focused >= (int) this->focusable.size()) {
|
||||
if (this->focusMode == FocusModeCircular) {
|
||||
this->focused = 0;
|
||||
notify = &FocusWrapped;
|
||||
}
|
||||
else {
|
||||
this->focused = NO_FOCUS;
|
||||
notify = &FocusTerminated;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return adjustFocus(oldFocus, GetFocus());
|
||||
IWindowPtr newFocus = GetFocus();
|
||||
adjustFocus(oldFocus, newFocus);
|
||||
|
||||
if (notify) {
|
||||
(*notify)(FocusForward);
|
||||
}
|
||||
|
||||
return newFocus;
|
||||
}
|
||||
|
||||
IWindowPtr LayoutBase::FocusPrev() {
|
||||
sigslot::signal1<FocusDirection>* notify = nullptr;
|
||||
|
||||
IWindowPtr oldFocus = GetFocus();
|
||||
--this->focused;
|
||||
if (this->focused < 0) {
|
||||
if (this->focusMode == FocusModeCircular) {
|
||||
this->focused = (int) this->focusable.size() - 1;
|
||||
notify = &FocusWrapped;
|
||||
}
|
||||
else {
|
||||
this->focused = NO_FOCUS;
|
||||
notify = &FocusTerminated;
|
||||
}
|
||||
}
|
||||
|
||||
return adjustFocus(oldFocus, GetFocus());
|
||||
IWindowPtr newFocus = GetFocus();
|
||||
adjustFocus(oldFocus, newFocus);
|
||||
|
||||
if (notify) {
|
||||
(*notify)(FocusBackward);
|
||||
}
|
||||
|
||||
return newFocus;
|
||||
}
|
||||
|
||||
IWindowPtr LayoutBase::FocusFirst() {
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "ILayout.h"
|
||||
#include "Window.h"
|
||||
|
||||
#include <sigslot/sigslot.h>
|
||||
#include <vector>
|
||||
|
||||
namespace cursespp {
|
||||
@ -48,6 +49,14 @@ namespace cursespp {
|
||||
public ILayout
|
||||
{
|
||||
public:
|
||||
enum FocusDirection {
|
||||
FocusForward,
|
||||
FocusBackward
|
||||
};
|
||||
|
||||
sigslot::signal1<FocusDirection> FocusTerminated;
|
||||
sigslot::signal1<FocusDirection> FocusWrapped;
|
||||
|
||||
LayoutBase(IWindow* parent = NULL);
|
||||
virtual ~LayoutBase();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user