Skip to content

Commit

Permalink
StatusBar: move code to UpdateScrollLayout()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jan 1, 2025
1 parent 29f7645 commit ca14e7f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/StatusBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ FormatStatusRightText(std::span<char> 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,
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/StatusBar.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit ca14e7f

Please sign in to comment.