From 3dda9ce60dbd87960a397b5e30638c92e3fc0701 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 1 Jan 2025 20:45:19 +0100 Subject: [PATCH] StatusBar: do not overwrite time/bitrate with song text We shouldn't be using the full window width for the scroll calculation; instead, subtract left_width and right_width. Closes https://github.com/MusicPlayerDaemon/ncmpc/issues/153 --- NEWS | 1 + src/StatusBar.cxx | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 813fdfbe..0d253558 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ncmpc 0.52 - not yet released * fix searching on Help and Song page * fix scroll bug after resizing window +* do not overwrite time/bitrate with song text in status bar * build: require Meson 1.0 ncmpc 0.51 - (2024-09-23) diff --git a/src/StatusBar.cxx b/src/StatusBar.cxx index e0c125d7..0c394329 100644 --- a/src/StatusBar.cxx +++ b/src/StatusBar.cxx @@ -138,10 +138,16 @@ StatusBar::UpdateScrollLayout() noexcept return; const unsigned window_width = window.GetWidth(); + if (left_width + right_width >= window_width) + /* there's no room for the center_text */ + return; + + const unsigned remaining_width = window_width - (left_width + right_width); + const unsigned center_width = StringWidthMB(center_text); - if (window_width > 3 && center_width > window_width) { - hscroll.Set({(int)left_width, 0}, window_width, + if (window_width > 3 && center_width > remaining_width) { + hscroll.Set({(int)left_width, 0}, remaining_width, center_text, Style::STATUS); } else { @@ -232,7 +238,7 @@ StatusBar::Paint() const noexcept window.String({x, 0}, {right_buffer, right_length}); } - if (!center_text.empty()) { + if (!center_text.empty() && left_width + right_length < window_width) { /* display song name */ SelectStyle(window, Style::STATUS);