Updated Layout focus semantics, and fixed sort order re-indexing in

LayoutBase
This commit is contained in:
casey 2016-05-14 19:15:58 -07:00
parent 95d8e8ab42
commit 2aef8ee6a4
11 changed files with 88 additions and 62 deletions

View File

@ -10,7 +10,7 @@
using musik::core::LibraryPtr;
using musik::core::IQuery;
CategoryListView::CategoryListView(IWindow *parent, LibraryPtr library)
CategoryListView::CategoryListView(LibraryPtr library, IWindow *parent)
: ListWindow(parent) {
this->library = library;
this->adapter = new Adapter(*this);

View File

@ -14,7 +14,7 @@ using musik::core::LibraryPtr;
class CategoryListView : public ListWindow, public sigslot::has_slots<> {
public:
CategoryListView(IWindow *parent, LibraryPtr library);
CategoryListView(LibraryPtr library, IWindow *parent = NULL);
~CategoryListView(); /* non-virtual for now*/
void OnIdle();

View File

@ -53,6 +53,9 @@ void LayoutBase::Show() {
for (size_t i = 0; i < this->children.size(); i++) {
this->children.at(i)->Show();
}
this->IndexFocusables();
this->SortFocusables();
}
void LayoutBase::Hide() {
@ -95,26 +98,41 @@ bool LayoutBase::RemoveWindow(IWindowPtr window) {
void LayoutBase::AddFocusable(IWindowPtr window) {
int order = window->GetFocusOrder();
if (order >= 0 && find(this->focusable, window) < 0) {
IWindowPtr focusedWindow;
if (focused >= 0 && (int) this->focusable.size() > focused) {
focusedWindow = this->focusable.at(focused);
}
this->focusable.push_back(window);
this->SortFocusables();
}
}
std::sort(
this->focusable.begin(),
this->focusable.end(),
sortByFocusOrder);
void LayoutBase::IndexFocusables() {
IWindowPtr focusedWindow;
if (focused >= 0 && (int) this->focusable.size() > focused) {
focusedWindow = this->focusable.at(focused);
}
if (focusedWindow) {
this->focused = find(this->focusable, focusedWindow);
}
this->focusable.clear();
for (size_t i = 0; i < this->children.size(); i++) {
AddFocusable(this->children.at(i));
}
}
if (focused == -1) {
this->focused = 0;
adjustFocus(NULL, this->focusable[this->focused].get());
}
void LayoutBase::SortFocusables() {
IWindowPtr focusedWindow;
if (focused >= 0 && (int) this->focusable.size() > focused) {
focusedWindow = this->focusable.at(focused);
}
std::sort(
this->focusable.begin(),
this->focusable.end(),
sortByFocusOrder);
if (focusedWindow) {
this->focused = find(this->focusable, focusedWindow);
}
if (focused == -1 && this->focusable.size() > 0) {
this->focused = 0;
adjustFocus(NULL, this->focusable[this->focused].get());
}
}
@ -155,5 +173,9 @@ IWindow* LayoutBase::FocusPrev() {
}
IWindow* LayoutBase::GetFocus() {
return this->focusable[this->focused].get();
if (this->focused >= 0 && this->focusable.size() > 0) {
return this->focusable[this->focused].get();
}
return NULL;
}

View File

@ -31,6 +31,8 @@ class LayoutBase : public Window, public ILayout {
private:
void AddFocusable(IWindowPtr window);
void RemoveFocusable(IWindowPtr window);
void SortFocusables();
void IndexFocusables();
std::vector<IWindowPtr> children;
std::vector<IWindowPtr> focusable;

View File

@ -5,20 +5,8 @@
LibraryLayout::LibraryLayout(LibraryPtr library)
: LayoutBase() {
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
this->SetPosition(0, 0);
this->Show();
this->albumList.reset(new CategoryListView(NULL, library));
this->albumList->SetFocusOrder(0);
this->trackList.reset(new TrackListView(NULL));
this->trackList->SetFocusOrder(1);
this->AddWindow(this->albumList);
this->AddWindow(this->trackList);
this->Layout();
this->library = library;
this->InitializeViews();
}
LibraryLayout::~LibraryLayout() {
@ -26,15 +14,28 @@ LibraryLayout::~LibraryLayout() {
}
void LibraryLayout::Layout() {
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
this->SetPosition(0, 0);
this->albumList->SetPosition(0, 0);
this->albumList->SetSize(20, this->GetHeight());
this->albumList->Show();
this->albumList->SetFocusOrder(0);
this->trackList->SetPosition(20, 0);
this->trackList->SetSize(this->GetWidth() - 20, this->GetHeight());
this->trackList->Show();
this->trackList->SetFocusOrder(1);
}
void LibraryLayout::OnIdle() {
this->albumList->OnIdle();
}
void LibraryLayout::InitializeViews() {
this->albumList.reset(new CategoryListView(library));
this->trackList.reset(new TrackListView());
this->AddWindow(this->albumList);
this->AddWindow(this->trackList);
this->Layout();
}

View File

@ -11,12 +11,15 @@ using musik::core::LibraryPtr;
class LibraryLayout : public LayoutBase {
public:
LibraryLayout(LibraryPtr library);
~LibraryLayout(); /* not virtual */
virtual ~LibraryLayout();
virtual void Layout();
virtual void OnIdle();
private:
void InitializeViews();
LibraryPtr library;
std::shared_ptr<CategoryListView> albumList;
std::shared_ptr<TrackListView> trackList;
};

View File

@ -79,6 +79,7 @@ void changeLayout(WindowState& current, ILayout* newLayout) {
if (newLayout) {
current.layout = newLayout;
current.layout->Layout();
current.layout->Show();
current.focused = newLayout->GetFocus();
current.input = dynamic_cast<IInput*>(current.focused);

View File

@ -5,24 +5,11 @@
#include "Screen.h"
MainLayout::MainLayout(Transport& transport, LibraryPtr library)
: LayoutBase()
{
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
this->SetPosition(0, 0);
this->SetFrameVisible(false);
this->Show();
: LayoutBase() {
this->logs.reset(new LogWindow(this));
this->logs->SetFocusOrder(2);
this->output.reset(new OutputWindow(this));
this->output->SetFocusOrder(1);
this->resources.reset(new ResourcesWindow(this));
this->commands.reset(new CommandWindow(this, transport, library, *this->output));
this->commands->SetFocusOrder(0);
this->transport.reset(new TransportWindow(this, transport));
this->AddWindow(this->commands);
@ -30,8 +17,6 @@ MainLayout::MainLayout(Transport& transport, LibraryPtr library)
this->AddWindow(this->output);
this->AddWindow(this->resources);
this->AddWindow(this->transport);
this->Layout();
}
MainLayout::~MainLayout() {
@ -39,36 +24,46 @@ MainLayout::~MainLayout() {
}
void MainLayout::Layout() {
/* this layout */
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
this->SetPosition(0, 0);
this->SetFrameVisible(false);
/* top left */
this->transport->SetSize(Screen::GetWidth() / 2, 4);
this->transport->SetPosition(0, 0);
this->transport->Show();
this->transport->Repaint();
/* middle left */
this->output->SetSize(Screen::GetWidth() / 2, Screen::GetHeight() - 3 - 4);
this->output->SetPosition(0, 4);
this->output->Show();
this->output->Repaint();
this->output->SetFocusOrder(1);
/* bottom left */
this->commands->SetSize(Screen::GetWidth() / 2, 3);
this->commands->SetPosition(0, Screen::GetHeight() - 3);
this->commands->Show();
this->commands->SetFocusOrder(0);
/* top right */
this->logs->SetSize(Screen::GetWidth() / 2, Screen::GetHeight() - 3);
this->logs->SetPosition(Screen::GetWidth() / 2, 0);
this->logs->Show();
this->logs->SetFocusOrder(2);
/* bottom right */
this->resources->SetSize(Screen::GetWidth() / 2, 3);
this->resources->SetPosition(Screen::GetWidth() / 2, Screen::GetHeight() - 3);
this->resources->Show();
this->resources->Repaint();
}
void MainLayout::Show() {
LayoutBase::Show();
this->UpdateWindows();
}
void MainLayout::OnIdle() {
this->UpdateWindows();
}
void MainLayout::UpdateWindows() {
this->logs->Update();
this->transport->Repaint();
this->resources->Repaint();

View File

@ -21,8 +21,11 @@ class MainLayout : public LayoutBase {
virtual void Layout();
virtual void OnIdle();
virtual void Show();
private:
void UpdateWindows();
std::shared_ptr<LogWindow> logs;
std::shared_ptr<CommandWindow> commands;
std::shared_ptr<OutputWindow> output;

View File

@ -8,6 +8,7 @@
#include <core/debug.h>
#include <boost/format.hpp>
#define BYTES_PER_MEGABYTE 1048576.0f
ResourcesWindow::ResourcesWindow(IWindow *parent)
: Window(parent) {
@ -18,8 +19,6 @@ ResourcesWindow::~ResourcesWindow() {
delete this->systemInfo;
}
#define BYTES_PER_MEGABYTE 1048576.0f
void ResourcesWindow::Repaint() {
this->Clear();

View File

@ -5,7 +5,7 @@
class TrackListView : public Window {
public:
TrackListView(IWindow *parent);
TrackListView(IWindow *parent = NULL);
~TrackListView();
private: