From e40ced8daff622c6b58fa97c9b4c8a35d653d459 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Fri, 5 Feb 2010 15:30:20 +0100 Subject: [PATCH] display selected item/now playing suffix in column view --- src/display.cpp | 38 ++++++++++++++++++++++++++++++++------ src/settings.cpp | 2 ++ src/settings.h | 1 + 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 4b10dd00..bf147a23 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -125,13 +125,14 @@ void Display::SongsInColumns(const MPD::Song &s, void *, Menu *menu) if (Config.columns.empty()) return; - std::vector::const_iterator next2last, it; + std::vector::const_iterator next2last, last, it; size_t where = 0; int width; bool last_fixed = Config.columns.back().fixed; if (Config.columns.size() > 1) next2last = Config.columns.end()-2; + last = Config.columns.end()-1; bool discard_colors = Config.discard_colors_if_item_is_selected && menu->isSelected(menu->CurrentlyDrawedPosition()); @@ -211,9 +212,19 @@ void Display::SongsInColumns(const MPD::Song &s, void *, Menu *menu) *menu << it->color; whline(menu->Raw(), 32, menu->GetWidth()-where); std::string tag = get ? s.GetTags(get) : ""; + + // last column might need to be shrinked to make space for np/sel suffixes + if (it == last) + { + if (menu->isSelected(menu->CurrentlyDrawedPosition())) + width -= Config.selected_item_suffix_length; + if (is_now_playing) + width -= Config.now_playing_suffix_length; + } + if (it->right_alignment) { - if (!tag.empty() || it->display_empty_tag) + if (width > 0 && (!tag.empty() || it->display_empty_tag)) { int x, y; menu->GetXY(x, y); @@ -223,10 +234,25 @@ void Display::SongsInColumns(const MPD::Song &s, void *, Menu *menu) } else { - if (!tag.empty()) - *menu << tag; - else if (it->display_empty_tag) - *menu << Config.empty_tag; + if (it == last) + { + if (width > 0) + { + std::basic_string str; + if (!tag.empty()) + str = TO_WSTRING(tag).substr(0, width-1); + else if (it->display_empty_tag) + str = TO_WSTRING(Config.empty_tag).substr(0, width-1); + *menu << str; + } + } + else + { + if (!tag.empty()) + *menu << tag; + else if (it->display_empty_tag) + *menu << Config.empty_tag; + } } where += width; } diff --git a/src/settings.cpp b/src/settings.cpp index e2605f41..d1d5008b 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -387,6 +387,7 @@ void DefaultConfiguration(ncmpcpp_config &conf) conf.lines_scrolled = 2; conf.search_engine_default_search_mode = 0; conf.selected_item_suffix_length = 0; + conf.now_playing_suffix_length = 0; # ifdef HAVE_LANGINFO_H conf.system_encoding = nl_langinfo(CODESET); if (conf.system_encoding == "UTF-8") // mpd uses utf-8 by default so no need to convert @@ -765,6 +766,7 @@ void ReadConfiguration(ncmpcpp_config &conf) { conf.now_playing_suffix.Clear(); String2Buffer(TO_WSTRING(v), conf.now_playing_suffix); + conf.now_playing_suffix_length = Window::Length(conf.now_playing_suffix.Str()); } } else if (cl.find("color1") != std::string::npos) diff --git a/src/settings.h b/src/settings.h index cc3b77ab..8a3964b7 100644 --- a/src/settings.h +++ b/src/settings.h @@ -236,6 +236,7 @@ struct ncmpcpp_config unsigned search_engine_default_search_mode; size_t selected_item_suffix_length; + size_t now_playing_suffix_length; std::list screens_seq; };