Skip to content

Commit

Permalink
StatusBar: do not overwrite time/bitrate with song text
Browse files Browse the repository at this point in the history
We shouldn't be using the full window width for the scroll
calculation; instead, subtract left_width and right_width.

Closes #153
  • Loading branch information
MaxKellermann committed Jan 1, 2025
1 parent 2e65b9f commit 3dda9ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/StatusBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3dda9ce

Please sign in to comment.