Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/frontend/StarSongbookInterface.cpp
diff options
context:
space:
mode:
authorJamesTheMaker <jamesthemaker2005@gmail.com>2024-03-08 11:39:39 -0500
committerJamesTheMaker <jamesthemaker2005@gmail.com>2024-03-08 12:19:15 -0500
commit81ab5b638b5da3aba2625e3ed814493c4278854b (patch)
treee62580c3361fd7e9c2888f348671b2c2b786c6fc /source/frontend/StarSongbookInterface.cpp
parent89fe1bf15bc458df6c63f1aaeac42a4883efbfd5 (diff)
Added searchbar to songbook
Diffstat (limited to 'source/frontend/StarSongbookInterface.cpp')
-rw-r--r--source/frontend/StarSongbookInterface.cpp49
1 files changed, 40 insertions, 9 deletions
diff --git a/source/frontend/StarSongbookInterface.cpp b/source/frontend/StarSongbookInterface.cpp
index 8ccb437..cc6a17d 100644
--- a/source/frontend/StarSongbookInterface.cpp
+++ b/source/frontend/StarSongbookInterface.cpp
@@ -23,21 +23,52 @@ SongbookInterface::SongbookInterface(PlayerPtr player) {
dismiss();
});
reader.registerCallback("group", [=](Widget*) {});
+ reader.registerCallback("search", [=](Widget*) {});
reader.construct(assets->json("/interface/windowconfig/songbook.config:paneLayout"), this);
auto songList = fetchChild<ListWidget>("songs.list");
+ auto search = fetchChild<TextBoxWidget>("search")->getText();
- StringList files = assets->scan(".abc");
- sort(files, [](String const& a, String const& b) -> bool { return b.compare(a, String::CaseInsensitive) > 0; });
- for (auto s : files) {
+ if (m_searchValue != search)
+ m_searchValue = search;
+
+ m_files = assets->scan(".abc");
+ sort(m_files, [](String const& a, String const& b) -> bool { return b.compare(a, String::CaseInsensitive) > 0; });
+ for (auto s : m_files) {
auto song = s.substr(7, s.length() - (7 + 4));
- auto widget = songList->addItem();
- widget->setData(s);
- auto songName = widget->fetchChild<LabelWidget>("songName");
- songName->setText(song);
+ if (song.contains(m_searchValue, String::CaseInsensitive)) {
+ auto widget = songList->addItem();
+ widget->setData(s);
+ auto songName = widget->fetchChild<LabelWidget>("songName");
+ songName->setText(song);
- widget->show();
+ widget->show();
+ }
+ }
+}
+
+void SongbookInterface::update(float dt) {
+ Pane::update(dt);
+
+ auto search = fetchChild<TextBoxWidget>("search")->getText();
+ if (m_searchValue != search) {
+ m_searchValue = search;
+
+ auto songList = fetchChild<ListWidget>("songs.list");
+ songList->clear();
+
+ for (auto s : m_files) {
+ auto song = s.substr(7, s.length() - (7 + 4));
+ if (song.contains(m_searchValue, String::CaseInsensitive)) {
+ auto widget = songList->addItem();
+ widget->setData(s);
+ auto songName = widget->fetchChild<LabelWidget>("songName");
+ songName->setText(song);
+
+ widget->show();
+ }
+ }
}
}
@@ -58,4 +89,4 @@ bool SongbookInterface::play() {
return true;
}
-}
+} \ No newline at end of file