Skip to content

Commit

Permalink
page/ListPage: remove the "size" parameter
Browse files Browse the repository at this point in the history
Carrying this parameter around doesn't seem worth the trouble; let's just
call Window::GetSize() instead.
  • Loading branch information
MaxKellermann committed Sep 11, 2024
1 parent f624a03 commit 016bb21
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 74 deletions.
8 changes: 4 additions & 4 deletions src/ChatPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class ChatPage final : public TextPage {
std::string prefix;

public:
ChatPage(ScreenManager &_screen, const Window _window, Size size)
:TextPage(_screen, _window, size, _screen.find_support),
ChatPage(ScreenManager &_screen, const Window _window)
:TextPage(_screen, _window, _screen.find_support),
screen(_screen) {}

private:
Expand Down Expand Up @@ -81,9 +81,9 @@ ChatPage::CheckChatSupport(struct mpdclient &c)
}

static std::unique_ptr<Page>
screen_chat_init(ScreenManager &screen, const Window window, Size size)
screen_chat_init(ScreenManager &screen, const Window window)
{
return std::make_unique<ChatPage>(screen, window, size);
return std::make_unique<ChatPage>(screen, window);
}

void
Expand Down
8 changes: 4 additions & 4 deletions src/EditPlaylistPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class EditPlaylistPage final : public FileListPage {
SongPtr selected_song;

public:
EditPlaylistPage(ScreenManager &_screen, const Window _window, Size size) noexcept
:FileListPage(_screen, _screen, _window, size,
EditPlaylistPage(ScreenManager &_screen, const Window _window) noexcept
:FileListPage(_screen, _screen, _window,
options.list_format.c_str())
{
}
Expand Down Expand Up @@ -108,9 +108,9 @@ EditPlaylistPage::RestoreSelection() noexcept
}

static std::unique_ptr<Page>
edit_playlist_page_init(ScreenManager &_screen, const Window window, Size size)
edit_playlist_page_init(ScreenManager &_screen, const Window window)
{
return std::make_unique<EditPlaylistPage>(_screen, window, size);
return std::make_unique<EditPlaylistPage>(_screen, window);
}

std::string_view
Expand Down
9 changes: 4 additions & 5 deletions src/FileBrowserPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ class FileBrowserPage final : public FileListPage {
std::string current_path;

public:
FileBrowserPage(ScreenManager &_screen, const Window _window,
Size size) noexcept
:FileListPage(_screen, _screen, _window, size,
FileBrowserPage(ScreenManager &_screen, const Window _window) noexcept
:FileListPage(_screen, _screen, _window,
options.list_format.c_str()) {}

bool GotoSong(struct mpdclient &c, const struct mpd_song &song) noexcept;
Expand Down Expand Up @@ -265,9 +264,9 @@ FileBrowserPage::HandleDelete(struct mpdclient &c)
}

static std::unique_ptr<Page>
screen_file_init(ScreenManager &_screen, const Window window, Size size) noexcept
screen_file_init(ScreenManager &_screen, const Window window) noexcept
{
return std::make_unique<FileBrowserPage>(_screen, window, size);
return std::make_unique<FileBrowserPage>(_screen, window);
}

std::string_view
Expand Down
3 changes: 1 addition & 2 deletions src/FileListPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ static constexpr unsigned HIGHLIGHT = 0x01;
#endif

FileListPage::FileListPage(PageContainer &_parent, ScreenManager &_screen, Window _window,
Size size,
const char *_song_format) noexcept
:ListPage(_parent, _window, size),
:ListPage(_parent, _window),
screen(_screen),
song_format(_song_format)
{
Expand Down
1 change: 0 additions & 1 deletion src/FileListPage.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ protected:

public:
FileListPage(PageContainer &_parent, ScreenManager &_screen, Window _window,
Size size,
const char *_song_format) noexcept;

~FileListPage() noexcept override;
Expand Down
8 changes: 4 additions & 4 deletions src/HelpPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ class HelpPage final : public ListPage, ListRenderer, ListText {
ScreenManager &screen;

public:
HelpPage(ScreenManager &_screen, const Window _window, Size size)
:ListPage(_screen, _window, size), screen(_screen) {
HelpPage(ScreenManager &_screen, const Window _window)
:ListPage(_screen, _window), screen(_screen) {
lw.HideCursor();
lw.SetLength(std::size(help_text));
}
Expand Down Expand Up @@ -251,9 +251,9 @@ HelpPage::GetListItemText(std::span<char>, unsigned i) const noexcept
}

static std::unique_ptr<Page>
help_init(ScreenManager &screen, const Window window, Size size)
help_init(ScreenManager &screen, const Window window)
{
return std::make_unique<HelpPage>(screen, window, size);
return std::make_unique<HelpPage>(screen, window);
}

void
Expand Down
18 changes: 9 additions & 9 deletions src/KeyDefPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class CommandKeysPage final : public ListPage, ListText {

public:
CommandKeysPage(PageContainer &_container, ScreenManager &_screen, Page *_parent,
const Window _window, Size size) noexcept
:ListPage(_container, _window, size), screen(_screen), parent(_parent) {}
const Window _window) noexcept
:ListPage(_container, _window), screen(_screen), parent(_parent) {}

void SetCommand(KeyBindings *_bindings, unsigned _cmd) {
bindings = _bindings;
Expand Down Expand Up @@ -291,8 +291,8 @@ class CommandListPage final : public ListPage, ListText {
static constexpr size_t command_n_commands = size_t(Command::NONE);

public:
CommandListPage(PageContainer &_container, ScreenManager &_screen, const Window _window, Size size)
:ListPage(_container, _window, size), screen(_screen) {}
CommandListPage(PageContainer &_container, ScreenManager &_screen, const Window _window)
:ListPage(_container, _window), screen(_screen) {}

~CommandListPage() override {
delete bindings;
Expand Down Expand Up @@ -495,10 +495,10 @@ class KeyDefPage final : public ProxyPage {
CommandKeysPage command_keys_page;

public:
KeyDefPage(ScreenManager &screen, const Window _window, Size size)
KeyDefPage(ScreenManager &screen, const Window _window)
:ProxyPage(screen, _window),
command_list_page(*this, screen, _window, size),
command_keys_page(*this, screen, this, _window, size) {}
command_list_page(*this, screen, _window),
command_keys_page(*this, screen, this, _window) {}

public:
/* virtual methods from class Page */
Expand All @@ -508,9 +508,9 @@ class KeyDefPage final : public ProxyPage {
};

static std::unique_ptr<Page>
keydef_init(ScreenManager &screen, const Window window, Size size)
keydef_init(ScreenManager &screen, const Window window)
{
return std::make_unique<KeyDefPage>(screen, window, size);
return std::make_unique<KeyDefPage>(screen, window);
}

void
Expand Down
19 changes: 9 additions & 10 deletions src/LibraryPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class SongListPage final : public FileListPage {

public:
SongListPage(PageContainer &_container, ScreenManager &_screen, Page *_parent,
const Window _window, Size size) noexcept
:FileListPage(_container, _screen, _window, size,
const Window _window) noexcept
:FileListPage(_container, _screen, _window,
options.list_format.c_str()),
parent(_parent) {}

Expand Down Expand Up @@ -105,8 +105,8 @@ class LibraryTagListPage final : public TagListPage {
Page *_parent,
const enum mpd_tag_type _tag,
const char *_all_text,
const Window _window, Size size) noexcept
:TagListPage(_container, _screen.find_support, _parent, _tag, _all_text, _window, size),
const Window _window) noexcept
:TagListPage(_container, _screen.find_support, _parent, _tag, _all_text, _window),
library_page(_library_page) {}

protected:
Expand All @@ -120,19 +120,18 @@ class ArtistBrowserPage final : public ProxyPage {
SongListPage song_list_page;

public:
ArtistBrowserPage(ScreenManager &_screen, const Window _window,
Size size)
ArtistBrowserPage(ScreenManager &_screen, const Window _window)
:ProxyPage(_screen, _window),
song_list_page(*this, _screen, this,
_window, size) {
_window) {

bool first = true;
for (const auto &tag : options.library_page_tags) {
tag_list_pages.emplace_back(*this, _screen, *this,
first ? nullptr : this,
tag,
first ? nullptr : _("All"),
_window, size);
_window);
first = false;
}
}
Expand Down Expand Up @@ -199,9 +198,9 @@ ArtistBrowserPage::OpenSongList(struct mpdclient &c, TagFilter &&filter)
}

static std::unique_ptr<Page>
InitLibraryPage(ScreenManager &_screen, const Window window, Size size)
InitLibraryPage(ScreenManager &_screen, const Window window)
{
return std::make_unique<ArtistBrowserPage>(_screen, window, size);
return std::make_unique<ArtistBrowserPage>(_screen, window);
}

std::string_view
Expand Down
8 changes: 4 additions & 4 deletions src/LyricsPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class LyricsPage final : public TextPage, PluginResponseHandler {

public:
LyricsPage(EventLoop &event_loop,
PageContainer &_parent, const Window _window, Size size,
PageContainer &_parent, const Window _window,
FindSupport &_find_support) noexcept
:TextPage(_parent, _window, size, _find_support),
:TextPage(_parent, _window, _find_support),
plugin_timeout(event_loop,
BIND_THIS_METHOD(OnTimeout)) {}

Expand Down Expand Up @@ -273,10 +273,10 @@ LyricsPage::Reload() noexcept
}

static std::unique_ptr<Page>
lyrics_screen_init(ScreenManager &_screen, const Window window, Size size) noexcept
lyrics_screen_init(ScreenManager &_screen, const Window window) noexcept
{
return std::make_unique<LyricsPage>(_screen.GetEventLoop(),
_screen, window, size,
_screen, window,
_screen.find_support);
}

Expand Down
8 changes: 4 additions & 4 deletions src/OutputsPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class OutputsPage final : public ListPage, ListRenderer {
#endif

public:
OutputsPage(ScreenManager &_screen, const Window window, Size size)
:ListPage(_screen, window, size), screen(_screen) {}
OutputsPage(ScreenManager &_screen, const Window window)
:ListPage(_screen, window), screen(_screen) {}

private:
void Clear();
Expand Down Expand Up @@ -351,9 +351,9 @@ OutputsPage::Reload(struct mpdclient &c) noexcept
}

static std::unique_ptr<Page>
outputs_init(ScreenManager &screen, const Window window, Size size)
outputs_init(ScreenManager &screen, const Window window)
{
return std::make_unique<OutputsPage>(screen, window, size);
return std::make_unique<OutputsPage>(screen, window);
}

std::string_view
Expand Down
4 changes: 1 addition & 3 deletions src/PageMeta.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#pragma once

#include "ui/Size.hxx"

#include <memory>

enum class Command : unsigned;
Expand All @@ -26,5 +24,5 @@ struct PageMeta {
*/
Command command;

std::unique_ptr<Page> (*init)(ScreenManager &screen, Window window, Size size);
std::unique_ptr<Page> (*init)(ScreenManager &screen, Window window);
};
11 changes: 5 additions & 6 deletions src/QueuePage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ class QueuePage final : public ListPage, ListRenderer, ListText {
bool playing = false;

public:
QueuePage(ScreenManager &_screen, Window _window,
Size size)
:ListPage(_screen, _window, size),
QueuePage(ScreenManager &_screen, Window _window)
:ListPage(_screen, _window),
screen(_screen),
#ifndef NCMPC_MINI
hscroll(screen.GetEventLoop(),
Expand All @@ -77,7 +76,7 @@ class QueuePage final : public ListPage, ListRenderer, ListText {
BIND_THIS_METHOD(OnHideCursorTimer))
{
#ifndef NCMPC_MINI
table_layout.Calculate(size.width);
table_layout.Calculate(GetWidth());
#endif
}

Expand Down Expand Up @@ -318,9 +317,9 @@ handle_add_to_playlist(ScreenManager &screen, struct mpdclient &c)
}

static std::unique_ptr<Page>
screen_queue_init(ScreenManager &_screen, Window window, Size size)
screen_queue_init(ScreenManager &_screen, Window window)
{
return std::make_unique<QueuePage>(_screen, window, size);
return std::make_unique<QueuePage>(_screen, window);
}

inline void
Expand Down
8 changes: 4 additions & 4 deletions src/SearchPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class SearchPage final : public FileListPage {
std::string pattern;

public:
SearchPage(ScreenManager &_screen, const Window _window, Size size) noexcept
:FileListPage(_screen, _screen, _window, size,
SearchPage(ScreenManager &_screen, const Window _window) noexcept
:FileListPage(_screen, _screen, _window,
!options.search_format.empty()
? options.search_format.c_str()
: options.list_format.c_str()) {
Expand Down Expand Up @@ -431,9 +431,9 @@ SearchPage::Start(struct mpdclient &c)
}

static std::unique_ptr<Page>
screen_search_init(ScreenManager &_screen, const Window window, Size size)
screen_search_init(ScreenManager &_screen, const Window window)
{
return std::make_unique<SearchPage>(_screen, window, size);
return std::make_unique<SearchPage>(_screen, window);
}

void
Expand Down
8 changes: 4 additions & 4 deletions src/SongPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class SongPage final : public ListPage, ListText {
std::vector<std::string> lines;

public:
SongPage(ScreenManager &_screen, const Window _window, Size size) noexcept
:ListPage(_screen, _window, size),
SongPage(ScreenManager &_screen, const Window _window) noexcept
:ListPage(_screen, _window),
screen(_screen) {
lw.HideCursor();
}
Expand Down Expand Up @@ -181,7 +181,7 @@ SongPage::GetListItemText(std::span<char>, unsigned idx) const noexcept
}

static std::unique_ptr<Page>
screen_song_init(ScreenManager &_screen, const Window window, Size size) noexcept
screen_song_init(ScreenManager &_screen, const Window window) noexcept
{
for (unsigned i = 0; tag_labels[i].label != nullptr; ++i) {
unsigned width = StringWidthMB(my_gettext(tag_labels[i].label));
Expand All @@ -198,7 +198,7 @@ screen_song_init(ScreenManager &_screen, const Window window, Size size) noexcep
}
}

return std::make_unique<SongPage>(_screen, window, size);
return std::make_unique<SongPage>(_screen, window);
}

std::string_view
Expand Down
4 changes: 2 additions & 2 deletions src/TagListPage.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public:
FindSupport &_find_support, Page *_parent,
const enum mpd_tag_type _tag,
const char *_all_text,
Window _window, Size size) noexcept
:ListPage(_container, _window, size),
Window _window) noexcept
:ListPage(_container, _window),
find_support(_find_support), parent(_parent),
tag(_tag), all_text(_all_text) {}

Expand Down
8 changes: 6 additions & 2 deletions src/page/ListPage.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ class ListPage : public Page {
protected:
ListWindow lw;

ListPage(PageContainer &_parent, Window window, Size size) noexcept
:Page(_parent), lw(window, size) {}
ListPage(PageContainer &_parent, Window window) noexcept
:Page(_parent), lw(window, window.GetSize()) {}

public:
unsigned GetWidth() const noexcept {
return lw.GetWidth();
}

/* virtual methods from class Page */
void OnResize(Size size) noexcept override {
lw.Resize(size);
Expand Down
Loading

0 comments on commit 016bb21

Please sign in to comment.