aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-03 01:52:27 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-03 01:52:30 +0200
commit117eb25e36ac3b1e1ba18cc9f1e177016c076f34 (patch)
tree04bd7fe4662af4c8b5d352098430c489082e71aa /src/main.cpp
parent65cf7681a04f2511db8c7829e9828b53a6676c88 (diff)
Add search suggestions for youtube & manganelo
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 4689bc5..c3c91b7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -81,12 +81,18 @@ namespace QuickMedia {
};
}
-static void search(sf::String text, QuickMedia::Body *body, QuickMedia::Plugin *plugin) {
+static void search(const sf::String &text, QuickMedia::Body *body, QuickMedia::Plugin *plugin) {
body->clear_items();
QuickMedia::SearchResult search_result = plugin->search(text, body->items);
fprintf(stderr, "Search result: %d\n", search_result);
}
+static void update_search_suggestions(const sf::String &text, QuickMedia::Body *body, QuickMedia::Plugin *plugin) {
+ body->clear_items();
+ QuickMedia::SuggestionResult suggestion_result = plugin->update_search_suggestions(text, body->items);
+ fprintf(stderr, "Suggestion result: %d\n", suggestion_result);
+}
+
int main() {
const float padding_horizontal = 10.0f;
const float padding_vertical = 10.0f;
@@ -120,10 +126,14 @@ int main() {
QuickMedia::Body body(font);
QuickMedia::Manganelo manganelo_plugin;
QuickMedia::Youtube youtube_plugin;
- QuickMedia::Plugin *plugin = &youtube_plugin;
+ QuickMedia::Plugin *plugin = &manganelo_plugin;
+
+ sf::Clock time_since_search_update;
+ bool updated_search = false;
while (window.isOpen()) {
sf::Event event;
+
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
@@ -150,6 +160,8 @@ int main() {
search_text.setString("Search...");
search_text.setFillColor(text_placeholder_color);
}
+ updated_search = true;
+ time_since_search_update.restart();
}
} else if(event.text.unicode == 13 && !show_placeholder) { // Return
body.reset_selected();
@@ -166,10 +178,20 @@ int main() {
sf::String str = search_text.getString();
str += event.text.unicode;
search_text.setString(str);
+ updated_search = true;
+ time_since_search_update.restart();
}
}
}
+ if(updated_search && time_since_search_update.getElapsedTime().asMilliseconds() >= 90) {
+ updated_search = false;
+ sf::String str = search_text.getString();
+ if(show_placeholder)
+ str.clear();
+ update_search_suggestions(str, &body, plugin);
+ }
+
if(resized) {
resized = false;