center cursor directly in Menu class
centering in Screen::Scroll is hacky and works only for scrolling, not e.g. selecting.
This commit is contained in:
@@ -60,6 +60,7 @@ void Browser::Init()
|
||||
w = new Menu<MPD::Item>(0, MainStartY, COLS, MainHeight, Config.columns_in_browser ? Display::Columns() : "", Config.main_color, brNone);
|
||||
w->HighlightColor(Config.main_highlight_color);
|
||||
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w->CenteredCursor(Config.centered_cursor);
|
||||
w->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
w->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
w->SetItemDisplayer(Display::Items);
|
||||
|
||||
@@ -54,6 +54,7 @@ void MediaLibrary::Init()
|
||||
Artists = new Menu<std::string>(0, MainStartY, itsLeftColWidth, MainHeight, IntoStr(Config.media_lib_primary_tag) + "s", Config.main_color, brNone);
|
||||
Artists->HighlightColor(Config.active_column_color);
|
||||
Artists->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Artists->CenteredCursor(Config.centered_cursor);
|
||||
Artists->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
Artists->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
Artists->SetItemDisplayer(Display::Generic);
|
||||
@@ -61,6 +62,7 @@ void MediaLibrary::Init()
|
||||
Albums = new Menu<SearchConstraints>(itsMiddleColStartX, MainStartY, itsMiddleColWidth, MainHeight, "Albums", Config.main_color, brNone);
|
||||
Albums->HighlightColor(Config.main_highlight_color);
|
||||
Albums->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Albums->CenteredCursor(Config.centered_cursor);
|
||||
Albums->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
Albums->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
Albums->SetItemDisplayer(DisplayAlbums);
|
||||
@@ -70,6 +72,7 @@ void MediaLibrary::Init()
|
||||
Songs = new Menu<MPD::Song>(itsRightColStartX, MainStartY, itsRightColWidth, MainHeight, "Songs", Config.main_color, brNone);
|
||||
Songs->HighlightColor(Config.main_highlight_color);
|
||||
Songs->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Songs->CenteredCursor(Config.centered_cursor);
|
||||
Songs->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
Songs->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
Songs->SetItemDisplayer(Display::Songs);
|
||||
|
||||
12
src/menu.h
12
src/menu.h
@@ -441,6 +441,11 @@ namespace NCurses
|
||||
///
|
||||
void CyclicScrolling(bool state) { useCyclicScrolling = state; }
|
||||
|
||||
/// Turns on/off centered cursor
|
||||
/// @param state state of centered cursor
|
||||
///
|
||||
void CenteredCursor(bool state) { useCenteredCursor = state; }
|
||||
|
||||
/// Checks if list is empty
|
||||
/// @return true if list is empty, false otherwise
|
||||
///
|
||||
@@ -528,6 +533,8 @@ namespace NCurses
|
||||
bool highlightEnabled;
|
||||
bool useCyclicScrolling;
|
||||
|
||||
bool useCenteredCursor;
|
||||
|
||||
size_t itsCurrentlyDrawedPosition;
|
||||
|
||||
Buffer *itsSelectedPrefix;
|
||||
@@ -558,6 +565,7 @@ template <typename T> NCurses::Menu<T>::Menu(size_t startx,
|
||||
itsHighlightColor(itsBaseColor),
|
||||
highlightEnabled(1),
|
||||
useCyclicScrolling(0),
|
||||
useCenteredCursor(0),
|
||||
itsSelectedPrefix(0),
|
||||
itsSelectedSuffix(0)
|
||||
{
|
||||
@@ -573,6 +581,8 @@ template <typename T> NCurses::Menu<T>::Menu(const Menu &m) : Window(m),
|
||||
itsHighlight(m.itsHighlight),
|
||||
itsHighlightColor(m.itsHighlightColor),
|
||||
highlightEnabled(m.highlightEnabled),
|
||||
useCyclicScrolling(m.useCyclicScrolling),
|
||||
useCenteredCursor(m.useCenteredCursor),
|
||||
itsSelectedPrefix(m.itsSelectedPrefix),
|
||||
itsSelectedSuffix(m.itsSelectedSuffix)
|
||||
{
|
||||
@@ -871,6 +881,8 @@ template <typename T> void NCurses::Menu<T>::Scroll(Where where)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (useCenteredCursor)
|
||||
Highlight(itsHighlight);
|
||||
}
|
||||
|
||||
template <typename T> void NCurses::Menu<T>::Reset()
|
||||
|
||||
@@ -35,6 +35,7 @@ void Outputs::Init()
|
||||
{
|
||||
w = new Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone);
|
||||
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w->CenteredCursor(Config.centered_cursor);
|
||||
w->HighlightColor(Config.main_highlight_color);
|
||||
w->SetItemDisplayer(Display::Pairs);
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ void Playlist::Init()
|
||||
{
|
||||
Items = new Menu<MPD::Song>(0, MainStartY, COLS, MainHeight, Config.columns_in_playlist ? Display::Columns() : "", Config.main_color, brNone);
|
||||
Items->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Items->CenteredCursor(Config.centered_cursor);
|
||||
Items->HighlightColor(Config.main_highlight_color);
|
||||
Items->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
Items->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
@@ -63,6 +64,7 @@ void Playlist::Init()
|
||||
|
||||
SortDialog = new Menu< std::pair<std::string, MPD::Song::GetFunction> >((COLS-SortDialogWidth)/2, (MainHeight-SortDialogHeight)/2+MainStartY, SortDialogWidth, SortDialogHeight, "Sort songs by...", Config.main_color, Config.window_border);
|
||||
SortDialog->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
SortDialog->CenteredCursor(Config.centered_cursor);
|
||||
SortDialog->SetItemDisplayer(Display::Pairs);
|
||||
|
||||
SortDialog->AddOption(std::make_pair("Artist", &MPD::Song::GetArtist));
|
||||
|
||||
@@ -48,11 +48,13 @@ void PlaylistEditor::Init()
|
||||
Playlists = new Menu<std::string>(0, MainStartY, LeftColumnWidth, MainHeight, "Playlists", Config.main_color, brNone);
|
||||
Playlists->HighlightColor(Config.active_column_color);
|
||||
Playlists->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Playlists->CenteredCursor(Config.centered_cursor);
|
||||
Playlists->SetItemDisplayer(Display::Generic);
|
||||
|
||||
Content = new Menu<MPD::Song>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, "Playlist's content", Config.main_color, brNone);
|
||||
Content->HighlightColor(Config.main_highlight_color);
|
||||
Content->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Content->CenteredCursor(Config.centered_cursor);
|
||||
Content->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
Content->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
Content->SetItemDisplayer(Display::Songs);
|
||||
|
||||
15
src/screen.h
15
src/screen.h
@@ -225,7 +225,6 @@ template <typename WindowType> void Screen<WindowType>::ReadKey(int &key)
|
||||
|
||||
template <typename WindowType> void Screen<WindowType>::Scroll(Where where, const int key[2])
|
||||
{
|
||||
List *list = Config.centered_cursor ? dynamic_cast<List *>(w) : 0;
|
||||
if (!Config.fancy_scrolling && key)
|
||||
{
|
||||
int in = key[0];
|
||||
@@ -234,37 +233,23 @@ template <typename WindowType> void Screen<WindowType>::Scroll(Where where, cons
|
||||
{
|
||||
TraceMpdStatus();
|
||||
w->Scroll(where);
|
||||
if (list)
|
||||
list->Highlight(list->Choice());
|
||||
w->Refresh();
|
||||
w->ReadKey(in);
|
||||
}
|
||||
w->SetTimeout(ncmpcpp_window_timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
w->Scroll(where);
|
||||
if (list)
|
||||
list->Highlight(list->Choice());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename WindowType> void Screen<WindowType>::MouseButtonPressed(MEVENT me)
|
||||
{
|
||||
List *list = Config.mouse_list_scroll_whole_page ? 0 : dynamic_cast<List *>(w);
|
||||
|
||||
if (me.bstate & BUTTON2_PRESSED)
|
||||
{
|
||||
if (list)
|
||||
list->Highlight(list->Choice()+Config.lines_scrolled);
|
||||
else
|
||||
Scroll(wPageDown);
|
||||
}
|
||||
else if (me.bstate & BUTTON4_PRESSED)
|
||||
{
|
||||
if (list)
|
||||
list->Highlight(list->Choice() > Config.lines_scrolled ? list->Choice()-Config.lines_scrolled : 0);
|
||||
else
|
||||
Scroll(wPageUp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ void SearchEngine::Init()
|
||||
w = new Menu< std::pair<Buffer *, MPD::Song *> >(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone);
|
||||
w->HighlightColor(Config.main_highlight_color);
|
||||
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w->CenteredCursor(Config.centered_cursor);
|
||||
w->SetItemDisplayer(Display::SearchEngine);
|
||||
w->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
w->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
|
||||
@@ -39,11 +39,13 @@ void SelectedItemsAdder::Init()
|
||||
SetDimensions();
|
||||
itsPlaylistSelector = new Menu<std::string>((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY, itsWidth, itsHeight, "Add selected item(s) to...", Config.main_color, Config.window_border);
|
||||
itsPlaylistSelector->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
itsPlaylistSelector->CenteredCursor(Config.centered_cursor);
|
||||
itsPlaylistSelector->HighlightColor(Config.main_highlight_color);
|
||||
itsPlaylistSelector->SetItemDisplayer(Display::Generic);
|
||||
|
||||
itsPositionSelector = new Menu<std::string>((COLS-itsPSWidth)/2, (MainHeight-itsPSHeight)/2+MainStartY, itsPSWidth, itsPSHeight, "Where?", Config.main_color, Config.window_border);
|
||||
itsPositionSelector->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
itsPositionSelector->CenteredCursor(Config.centered_cursor);
|
||||
itsPositionSelector->HighlightColor(Config.main_highlight_color);
|
||||
itsPositionSelector->SetItemDisplayer(Display::Generic);
|
||||
itsPositionSelector->AddOption("At the end of playlist");
|
||||
|
||||
@@ -67,12 +67,14 @@ void TagEditor::Init()
|
||||
Albums = new Menu<string_pair>(0, MainStartY, LeftColumnWidth, MainHeight, "Albums", Config.main_color, brNone);
|
||||
Albums->HighlightColor(Config.active_column_color);
|
||||
Albums->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Albums->CenteredCursor(Config.centered_cursor);
|
||||
Albums->SetItemDisplayer(Display::Pairs);
|
||||
Albums->SetGetStringFunction(StringPairToString);
|
||||
|
||||
Dirs = new Menu<string_pair>(0, MainStartY, LeftColumnWidth, MainHeight, "Directories", Config.main_color, brNone);
|
||||
Dirs->HighlightColor(Config.active_column_color);
|
||||
Dirs->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Dirs->CenteredCursor(Config.centered_cursor);
|
||||
Dirs->SetItemDisplayer(Display::Pairs);
|
||||
Dirs->SetGetStringFunction(StringPairToString);
|
||||
|
||||
@@ -81,6 +83,7 @@ void TagEditor::Init()
|
||||
TagTypes = new Menu<std::string>(MiddleColumnStartX, MainStartY, MiddleColumnWidth, MainHeight, "Tag types", Config.main_color, brNone);
|
||||
TagTypes->HighlightColor(Config.main_highlight_color);
|
||||
TagTypes->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
TagTypes->CenteredCursor(Config.centered_cursor);
|
||||
TagTypes->SetItemDisplayer(Display::Generic);
|
||||
|
||||
for (const Info::Metadata *m = Info::Tags; m->Name; ++m)
|
||||
@@ -99,6 +102,7 @@ void TagEditor::Init()
|
||||
Tags = new Menu<MPD::Song>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, "Tags", Config.main_color, brNone);
|
||||
Tags->HighlightColor(Config.main_highlight_color);
|
||||
Tags->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Tags->CenteredCursor(Config.centered_cursor);
|
||||
Tags->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
Tags->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
Tags->SetItemDisplayer(Display::Tags);
|
||||
@@ -108,6 +112,7 @@ void TagEditor::Init()
|
||||
|
||||
FParserDialog = new Menu<std::string>((COLS-FParserDialogWidth)/2, (MainHeight-FParserDialogHeight)/2+MainStartY, FParserDialogWidth, FParserDialogHeight, "", Config.main_color, Config.window_border);
|
||||
FParserDialog->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
FParserDialog->CenteredCursor(Config.centered_cursor);
|
||||
FParserDialog->SetItemDisplayer(Display::Generic);
|
||||
FParserDialog->AddOption("Get tags from filename");
|
||||
FParserDialog->AddOption("Rename files");
|
||||
@@ -116,6 +121,7 @@ void TagEditor::Init()
|
||||
|
||||
FParser = new Menu<std::string>((COLS-FParserWidth)/2, (MainHeight-FParserHeight)/2+MainStartY, FParserWidthOne, FParserHeight, "_", Config.main_color, Config.active_window_border);
|
||||
FParser->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
FParser->CenteredCursor(Config.centered_cursor);
|
||||
FParser->SetItemDisplayer(Display::Generic);
|
||||
|
||||
FParserLegend = new Scrollpad((COLS-FParserWidth)/2+FParserWidthOne, (MainHeight-FParserHeight)/2+MainStartY, FParserWidthTwo, FParserHeight, "Legend", Config.main_color, Config.window_border);
|
||||
|
||||
@@ -47,6 +47,7 @@ void TinyTagEditor::Init()
|
||||
w = new Menu<Buffer>(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone);
|
||||
w->HighlightColor(Config.main_highlight_color);
|
||||
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w->CenteredCursor(Config.centered_cursor);
|
||||
w->SetItemDisplayer(Display::Generic);
|
||||
isInitialized = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user