- Ensure NowPlayingLayout always scrolls to the playing item when shown

- Fixed some resize bugs in LibraryLayout
- Automatically convert ALT_ keys to M- (meta) keys for Win32 builds.
This commit is contained in:
casey 2016-06-03 18:32:25 -07:00
parent ffcc110430
commit b286d83c78
9 changed files with 56 additions and 33 deletions

View File

@ -147,6 +147,13 @@ static inline std::string readKeyPress(int64 ch) {
kn = std::string("M-") + std::string(keyname((int)next));
}
}
#ifdef WIN32
/* transform alt->meta for uniform handling */
else if (kn.find("ALT_") == 0) {
std::transform(kn.begin(), kn.end(), kn.begin(), tolower);
kn.replace(0, 4, "M-");
}
#endif
/* multi-byte UTF8 character */
else if (ch >= 194 && ch <= 223) {
kn = "";

View File

@ -46,7 +46,9 @@ void LibraryLayout::Layout() {
this->MoveAndResize(x, y, cx, cy);
this->browseLayout->MoveAndResize(x, y, cx, cy - TRANSPORT_HEIGHT);
this->browseLayout->Layout();
this->nowPlayingLayout->MoveAndResize(x, y, cx, cy - TRANSPORT_HEIGHT);
this->nowPlayingLayout->Layout();
this->transportView->MoveAndResize(
1,

View File

@ -24,9 +24,9 @@ namespace musik {
virtual ~LibraryLayout();
virtual void Layout();
virtual cursespp::IWindowPtr FocusNext();
virtual cursespp::IWindowPtr FocusPrev();
virtual cursespp::IWindowPtr FocusNext();
virtual cursespp::IWindowPtr FocusPrev();
virtual cursespp::IWindowPtr GetFocus();
virtual bool KeyPress(const std::string& key);

View File

@ -43,6 +43,7 @@ void NowPlayingLayout::Layout() {
void NowPlayingLayout::InitializeWindows() {
this->trackList.reset(new TrackListView(this->playback, this->library));
this->trackList->Requeried.connect(this, &NowPlayingLayout::OnTrackListRequeried);
this->AddWindow(this->trackList);
this->Layout();
}
@ -55,7 +56,18 @@ void NowPlayingLayout::OnVisibilityChanged(bool visible) {
LayoutBase::OnVisibilityChanged(visible);
if (visible) {
this->RequeryTrackList();
this->RequeryTrackList();
}
else {
this->trackList->Clear();
}
}
void NowPlayingLayout::OnTrackListRequeried() {
if (playback.Count()) {
size_t index = playback.GetIndex();
this->trackList->SetSelectedIndex(index);
this->trackList->ScrollTo(index);
}
}

View File

@ -34,6 +34,7 @@ namespace musik {
virtual bool KeyPress(const std::string& key);
private:
void OnTrackListRequeried();
void InitializeWindows();
void RequeryTrackList();

View File

@ -59,6 +59,13 @@ TrackListView::TrackList TrackListView::GetTrackList() {
return this->metadata;
}
void TrackListView::Clear() {
this->query.reset();
this->metadata.reset(new std::vector<TrackPtr>());
this->headers.reset(new std::set<size_t>());
this->OnAdapterChanged();
}
void TrackListView::ProcessMessage(IMessage &message) {
if (message.Type() == WINDOW_MESSAGE_QUERY_COMPLETED) {
if (this->query && this->query->GetStatus() == IQuery::Finished) {
@ -74,7 +81,8 @@ void TrackListView::ProcessMessage(IMessage &message) {
this->lastQueryHash = this->query->GetQueryHash();
this->query.reset();
this->OnAdapterChanged();
this->OnAdapterChanged(); /* internal handling */
this->Requeried(); /* for external handlers */
}
}
}

View File

@ -21,6 +21,8 @@ namespace musik {
public sigslot::has_slots<>
{
public:
sigslot::signal0<> Requeried;
typedef std::shared_ptr<std::vector<musik::core::TrackPtr> > TrackList;
typedef std::shared_ptr<std::set<size_t> > Headers;
@ -32,6 +34,7 @@ namespace musik {
virtual void ProcessMessage(cursespp::IMessage &message);
TrackList GetTrackList();
void Clear();
void Requery(std::shared_ptr<TrackListQueryBase> query);

View File

@ -19,15 +19,13 @@ ListWindow::~ListWindow() {
void ListWindow::ScrollToTop() {
this->SetSelectedIndex(0);
this->GetScrollAdapter().DrawPage(this->GetContent(), 0, &scrollPosition);
this->Repaint();
this->ScrollTo(0);
}
void ListWindow::ScrollToBottom() {
IScrollAdapter& adapter = this->GetScrollAdapter();
this->SetSelectedIndex(std::max((size_t) 0, adapter.GetEntryCount() - 1));
adapter.DrawPage(this->GetContent(), selectedIndex, &scrollPosition);
this->Repaint();
this->ScrollTo(selectedIndex);
}
void ListWindow::ScrollUp(int delta) {
@ -49,10 +47,7 @@ void ListWindow::ScrollUp(int delta) {
drawIndex = std::max(0, drawIndex);
this->SetSelectedIndex(newIndex);
adapter.DrawPage(this->GetContent(), drawIndex, &this->scrollPosition);
this->Repaint();
this->ScrollTo(drawIndex);
}
void ListWindow::OnInvalidated() {
@ -76,10 +71,7 @@ void ListWindow::ScrollDown(int delta) {
}
this->SetSelectedIndex(newIndex);
adapter.DrawPage(this->GetContent(), drawIndex, &this->scrollPosition);
this->Repaint();
this->ScrollTo(drawIndex);
}
void ListWindow::PageUp() {
@ -93,9 +85,7 @@ void ListWindow::PageUp() {
target = (target > 0) ? target + 1 : 0;
this->SetSelectedIndex((target == 0) ? 0 : target + 1);
adapter.DrawPage(this->GetContent(), target, &this->scrollPosition);
this->Repaint();
this->ScrollTo(target);
}
void ListWindow::PageDown() {
@ -108,7 +98,15 @@ void ListWindow::PageDown() {
size_t lastVisible = spos.firstVisibleEntryIndex + spos.visibleEntryCount - 1;
this->SetSelectedIndex(std::min(adapter.GetEntryCount() - 1, lastVisible + 1));
adapter.DrawPage(this->GetContent(), lastVisible, &this->scrollPosition);
this->ScrollTo(lastVisible);
}
void ListWindow::ScrollTo(size_t index) {
this->GetScrollAdapter().DrawPage(
this->GetContent(),
index,
&this->GetScrollPosition());
this->Repaint();
}
@ -144,21 +142,12 @@ void ListWindow::OnAdapterChanged() {
this->SetSelectedIndex(NO_SELECTION);
}
GetScrollAdapter().DrawPage(
this->GetContent(),
this->scrollPosition.firstVisibleEntryIndex,
&this->scrollPosition);
this->Repaint();
this->ScrollTo(this->scrollPosition.firstVisibleEntryIndex);
}
void ListWindow::OnSizeChanged() {
ScrollableWindow::OnSizeChanged();
this->GetScrollAdapter().DrawPage(
this->GetContent(),
this->selectedIndex,
&this->GetScrollPosition());
this->ScrollTo(this->selectedIndex);
}
IScrollAdapter::ScrollPosition& ListWindow::GetScrollPosition() {

View File

@ -22,11 +22,12 @@ namespace cursespp {
virtual void ScrollDown(int delta = 1);
virtual void PageUp();
virtual void PageDown();
virtual void ScrollTo(size_t index);
virtual size_t GetSelectedIndex();
virtual void SetSelectedIndex(size_t index);
protected:
virtual void SetSelectedIndex(size_t index);
virtual void OnAdapterChanged();
virtual void OnSelectionChanged(size_t newIndex, size_t oldIndex);
virtual void OnInvalidated();