aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/viewer
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-11-08 13:11:36 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-08 18:33:07 +0000
commitf479e42981f6572ec17b178aa95608eb5196eefa (patch)
tree23f3a8d8d35267d8653aaae5cc57b2f243250c12 /tools/viewer
parentdf429f3beac1c191289ba1e3bd918bf84df57bf5 (diff)
Use ListBox for slide picker in Viewer
Interaction is much nicer (the bulleted list of text had dead space between entries, so mouse clicks could go unnoticed). This version also keeps the currently active slide highlighted in the list, which is nice. Bug: skia: Change-Id: I609d90f3b1ff99765f0a7f1ca43e02a0a534dc4d Reviewed-on: https://skia-review.googlesource.com/68780 Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'tools/viewer')
-rw-r--r--tools/viewer/Viewer.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 03b774804f..220a482805 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -1180,21 +1180,29 @@ void Viewer::drawImGui(SkCanvas* canvas) {
if (ImGui::CollapsingHeader("Slide")) {
static ImGuiTextFilter filter;
+ static ImVector<const char*> filteredSlideNames;
+ static ImVector<int> filteredSlideIndices;
+
filter.Draw();
- int previousSlide = fCurrentSlide;
- fCurrentSlide = 0;
- for (auto slide : fSlides) {
- if (filter.PassFilter(slide->getName().c_str())) {
- ImGui::BulletText("%s", slide->getName().c_str());
- if (ImGui::IsItemClicked()) {
- setupCurrentSlide(previousSlide);
- break;
+ filteredSlideNames.clear();
+ filteredSlideIndices.clear();
+ int filteredIndex = 0;
+ for (int i = 0; i < fSlides.count(); ++i) {
+ const char* slideName = fSlides[i]->getName().c_str();
+ if (filter.PassFilter(slideName) || i == fCurrentSlide) {
+ if (i == fCurrentSlide) {
+ filteredIndex = filteredSlideIndices.size();
}
+ filteredSlideNames.push_back(slideName);
+ filteredSlideIndices.push_back(i);
}
- ++fCurrentSlide;
}
- if (fCurrentSlide >= fSlides.count()) {
- fCurrentSlide = previousSlide;
+
+ int previousSlide = fCurrentSlide;
+ if (ImGui::ListBox("", &filteredIndex, filteredSlideNames.begin(),
+ filteredSlideNames.size(), 20)) {
+ fCurrentSlide = filteredSlideIndices[filteredIndex];
+ setupCurrentSlide(previousSlide);
}
}