From 016bb217b6bb6e5bb6f0947d2159d3f27ebcbe7c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 11 Sep 2024 11:54:17 +0200 Subject: [PATCH] page/ListPage: remove the "size" parameter Carrying this parameter around doesn't seem worth the trouble; let's just call Window::GetSize() instead. --- src/ChatPage.cxx | 8 ++++---- src/EditPlaylistPage.cxx | 8 ++++---- src/FileBrowserPage.cxx | 9 ++++----- src/FileListPage.cxx | 3 +-- src/FileListPage.hxx | 1 - src/HelpPage.cxx | 8 ++++---- src/KeyDefPage.cxx | 18 +++++++++--------- src/LibraryPage.cxx | 19 +++++++++---------- src/LyricsPage.cxx | 8 ++++---- src/OutputsPage.cxx | 8 ++++---- src/PageMeta.hxx | 4 +--- src/QueuePage.cxx | 11 +++++------ src/SearchPage.cxx | 8 ++++---- src/SongPage.cxx | 8 ++++---- src/TagListPage.hxx | 4 ++-- src/page/ListPage.hxx | 8 ++++++-- src/page/TextPage.cxx | 4 ++-- src/page/TextPage.hxx | 2 +- src/screen.cxx | 4 +--- 19 files changed, 69 insertions(+), 74 deletions(-) diff --git a/src/ChatPage.cxx b/src/ChatPage.cxx index 5fb581f8..19580dc6 100644 --- a/src/ChatPage.cxx +++ b/src/ChatPage.cxx @@ -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: @@ -81,9 +81,9 @@ ChatPage::CheckChatSupport(struct mpdclient &c) } static std::unique_ptr -screen_chat_init(ScreenManager &screen, const Window window, Size size) +screen_chat_init(ScreenManager &screen, const Window window) { - return std::make_unique(screen, window, size); + return std::make_unique(screen, window); } void diff --git a/src/EditPlaylistPage.cxx b/src/EditPlaylistPage.cxx index 3773e531..b6b5f5c8 100644 --- a/src/EditPlaylistPage.cxx +++ b/src/EditPlaylistPage.cxx @@ -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()) { } @@ -108,9 +108,9 @@ EditPlaylistPage::RestoreSelection() noexcept } static std::unique_ptr -edit_playlist_page_init(ScreenManager &_screen, const Window window, Size size) +edit_playlist_page_init(ScreenManager &_screen, const Window window) { - return std::make_unique(_screen, window, size); + return std::make_unique(_screen, window); } std::string_view diff --git a/src/FileBrowserPage.cxx b/src/FileBrowserPage.cxx index 96fd4a39..88cdf5a7 100644 --- a/src/FileBrowserPage.cxx +++ b/src/FileBrowserPage.cxx @@ -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; @@ -265,9 +264,9 @@ FileBrowserPage::HandleDelete(struct mpdclient &c) } static std::unique_ptr -screen_file_init(ScreenManager &_screen, const Window window, Size size) noexcept +screen_file_init(ScreenManager &_screen, const Window window) noexcept { - return std::make_unique(_screen, window, size); + return std::make_unique(_screen, window); } std::string_view diff --git a/src/FileListPage.cxx b/src/FileListPage.cxx index bbb90379..3cc6e7ed 100644 --- a/src/FileListPage.cxx +++ b/src/FileListPage.cxx @@ -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) { diff --git a/src/FileListPage.hxx b/src/FileListPage.hxx index b903645f..311c5fde 100644 --- a/src/FileListPage.hxx +++ b/src/FileListPage.hxx @@ -25,7 +25,6 @@ protected: public: FileListPage(PageContainer &_parent, ScreenManager &_screen, Window _window, - Size size, const char *_song_format) noexcept; ~FileListPage() noexcept override; diff --git a/src/HelpPage.cxx b/src/HelpPage.cxx index 436e22dc..77003649 100644 --- a/src/HelpPage.cxx +++ b/src/HelpPage.cxx @@ -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)); } @@ -251,9 +251,9 @@ HelpPage::GetListItemText(std::span, unsigned i) const noexcept } static std::unique_ptr -help_init(ScreenManager &screen, const Window window, Size size) +help_init(ScreenManager &screen, const Window window) { - return std::make_unique(screen, window, size); + return std::make_unique(screen, window); } void diff --git a/src/KeyDefPage.cxx b/src/KeyDefPage.cxx index e352efae..123b0182 100644 --- a/src/KeyDefPage.cxx +++ b/src/KeyDefPage.cxx @@ -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; @@ -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; @@ -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 */ @@ -508,9 +508,9 @@ class KeyDefPage final : public ProxyPage { }; static std::unique_ptr -keydef_init(ScreenManager &screen, const Window window, Size size) +keydef_init(ScreenManager &screen, const Window window) { - return std::make_unique(screen, window, size); + return std::make_unique(screen, window); } void diff --git a/src/LibraryPage.cxx b/src/LibraryPage.cxx index 3e59426d..bef0f474 100644 --- a/src/LibraryPage.cxx +++ b/src/LibraryPage.cxx @@ -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) {} @@ -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: @@ -120,11 +120,10 @@ 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) { @@ -132,7 +131,7 @@ class ArtistBrowserPage final : public ProxyPage { first ? nullptr : this, tag, first ? nullptr : _("All"), - _window, size); + _window); first = false; } } @@ -199,9 +198,9 @@ ArtistBrowserPage::OpenSongList(struct mpdclient &c, TagFilter &&filter) } static std::unique_ptr -InitLibraryPage(ScreenManager &_screen, const Window window, Size size) +InitLibraryPage(ScreenManager &_screen, const Window window) { - return std::make_unique(_screen, window, size); + return std::make_unique(_screen, window); } std::string_view diff --git a/src/LyricsPage.cxx b/src/LyricsPage.cxx index 5613d4aa..ff623017 100644 --- a/src/LyricsPage.cxx +++ b/src/LyricsPage.cxx @@ -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)) {} @@ -273,10 +273,10 @@ LyricsPage::Reload() noexcept } static std::unique_ptr -lyrics_screen_init(ScreenManager &_screen, const Window window, Size size) noexcept +lyrics_screen_init(ScreenManager &_screen, const Window window) noexcept { return std::make_unique(_screen.GetEventLoop(), - _screen, window, size, + _screen, window, _screen.find_support); } diff --git a/src/OutputsPage.cxx b/src/OutputsPage.cxx index bff0de85..315cf0fe 100644 --- a/src/OutputsPage.cxx +++ b/src/OutputsPage.cxx @@ -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(); @@ -351,9 +351,9 @@ OutputsPage::Reload(struct mpdclient &c) noexcept } static std::unique_ptr -outputs_init(ScreenManager &screen, const Window window, Size size) +outputs_init(ScreenManager &screen, const Window window) { - return std::make_unique(screen, window, size); + return std::make_unique(screen, window); } std::string_view diff --git a/src/PageMeta.hxx b/src/PageMeta.hxx index 52a7259b..bd8ec0af 100644 --- a/src/PageMeta.hxx +++ b/src/PageMeta.hxx @@ -3,8 +3,6 @@ #pragma once -#include "ui/Size.hxx" - #include enum class Command : unsigned; @@ -26,5 +24,5 @@ struct PageMeta { */ Command command; - std::unique_ptr (*init)(ScreenManager &screen, Window window, Size size); + std::unique_ptr (*init)(ScreenManager &screen, Window window); }; diff --git a/src/QueuePage.cxx b/src/QueuePage.cxx index 9deb21b8..6eac5a13 100644 --- a/src/QueuePage.cxx +++ b/src/QueuePage.cxx @@ -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(), @@ -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 } @@ -318,9 +317,9 @@ handle_add_to_playlist(ScreenManager &screen, struct mpdclient &c) } static std::unique_ptr -screen_queue_init(ScreenManager &_screen, Window window, Size size) +screen_queue_init(ScreenManager &_screen, Window window) { - return std::make_unique(_screen, window, size); + return std::make_unique(_screen, window); } inline void diff --git a/src/SearchPage.cxx b/src/SearchPage.cxx index d8848b5e..e7dd8a43 100644 --- a/src/SearchPage.cxx +++ b/src/SearchPage.cxx @@ -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()) { @@ -431,9 +431,9 @@ SearchPage::Start(struct mpdclient &c) } static std::unique_ptr -screen_search_init(ScreenManager &_screen, const Window window, Size size) +screen_search_init(ScreenManager &_screen, const Window window) { - return std::make_unique(_screen, window, size); + return std::make_unique(_screen, window); } void diff --git a/src/SongPage.cxx b/src/SongPage.cxx index 41af5461..d5df3ea1 100644 --- a/src/SongPage.cxx +++ b/src/SongPage.cxx @@ -110,8 +110,8 @@ class SongPage final : public ListPage, ListText { std::vector 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(); } @@ -181,7 +181,7 @@ SongPage::GetListItemText(std::span, unsigned idx) const noexcept } static std::unique_ptr -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)); @@ -198,7 +198,7 @@ screen_song_init(ScreenManager &_screen, const Window window, Size size) noexcep } } - return std::make_unique(_screen, window, size); + return std::make_unique(_screen, window); } std::string_view diff --git a/src/TagListPage.hxx b/src/TagListPage.hxx index 3438029f..b2a5dbd2 100644 --- a/src/TagListPage.hxx +++ b/src/TagListPage.hxx @@ -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) {} diff --git a/src/page/ListPage.hxx b/src/page/ListPage.hxx index 49509014..0c38df88 100644 --- a/src/page/ListPage.hxx +++ b/src/page/ListPage.hxx @@ -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); diff --git a/src/page/TextPage.cxx b/src/page/TextPage.cxx index a9e45922..446c439f 100644 --- a/src/page/TextPage.cxx +++ b/src/page/TextPage.cxx @@ -12,9 +12,9 @@ #include #include -TextPage::TextPage(PageContainer &_parent, Window window, Size size, +TextPage::TextPage(PageContainer &_parent, Window window, FindSupport &_find_support) noexcept - :ListPage(_parent, window, size), find_support(_find_support) + :ListPage(_parent, window), find_support(_find_support) { lw.HideCursor(); } diff --git a/src/page/TextPage.hxx b/src/page/TextPage.hxx index 865aef57..9b789893 100644 --- a/src/page/TextPage.hxx +++ b/src/page/TextPage.hxx @@ -22,7 +22,7 @@ protected: std::vector lines; public: - TextPage(PageContainer &_parent, Window window, Size size, + TextPage(PageContainer &_parent, Window window, FindSupport &_find_support) noexcept; protected: diff --git a/src/screen.cxx b/src/screen.cxx index da539cc0..8bbe9208 100644 --- a/src/screen.cxx +++ b/src/screen.cxx @@ -33,9 +33,7 @@ ScreenManager::MakePage(const PageMeta &sf) noexcept if (i != pages.end()) return i; - auto j = pages.emplace(&sf, - sf.init(*this, main_window, - layout.GetMainSize())); + auto j = pages.emplace(&sf, sf.init(*this, main_window)); assert(j.second); return j.first; }