diff --git a/src/StatusBar.cxx b/src/StatusBar.cxx index 35eb36df..e23e50b2 100644 --- a/src/StatusBar.cxx +++ b/src/StatusBar.cxx @@ -130,6 +130,26 @@ FormatStatusRightText(std::span buffer, return {buffer.data(), bitrate_string.size() + time_string.size()}; } +void +StatusBar::UpdateScrollLayout() noexcept +{ +#ifndef NCMPC_MINI + if (!options.scroll) + return; + + const unsigned window_width = window.GetWidth(); + const unsigned center_width = + StringWidthMB(center_text); + if (window_width > 3 && center_width > window_width) { + hscroll.Set({(int)left_width, 0}, window_width, + center_text, + Style::STATUS); + } else { + hscroll.Clear(); + } +#endif +} + void StatusBar::Update(const struct mpd_status *status, const struct mpd_song *song, @@ -171,20 +191,7 @@ StatusBar::Update(const struct mpd_status *status, center_text.clear(); /* scroll if the song name is to long */ -#ifndef NCMPC_MINI - if (options.scroll) { - const unsigned window_width = window.GetWidth(); - const unsigned center_width = - StringWidthMB(center_text); - if (window_width > 3 && center_width > window_width) { - hscroll.Set({(int)left_width, 0}, window_width, - center_text, - Style::STATUS); - } else { - hscroll.Clear(); - } - } -#endif + UpdateScrollLayout(); } else { right_width = 0; center_text.clear(); diff --git a/src/StatusBar.hxx b/src/StatusBar.hxx index 955868fe..b4f7792d 100644 --- a/src/StatusBar.hxx +++ b/src/StatusBar.hxx @@ -55,6 +55,11 @@ public: void Paint() const noexcept; private: + /** + * Updates #hscroll after a content or size change. + */ + void UpdateScrollLayout() noexcept; + void OnMessageTimer() noexcept { ClearMessage(); }