From 3b70a5697fc065fb8f535b21a1f0a3602f9a6340 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 15 Apr 2019 02:26:50 -0400 Subject: [PATCH] Add string::ellipsizePrefix. Use kHz instead of Hz for sample rate displays. --- include/string.hpp | 1 + src/app/AudioWidget.cpp | 4 ++-- src/app/ModuleWidget.cpp | 6 +++++- src/app/Toolbar.cpp | 7 ++++--- src/string.cpp | 7 +++++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/string.hpp b/include/string.hpp index eafe63fc..97215b41 100644 --- a/include/string.hpp +++ b/include/string.hpp @@ -24,6 +24,7 @@ std::string uppercase(const std::string &s); std::string trim(const std::string &s); /** Truncates and adds "..." to a string, not exceeding `len` characters */ std::string ellipsize(const std::string &s, size_t len); +std::string ellipsizePrefix(const std::string &s, size_t len); bool startsWith(const std::string &str, const std::string &prefix); bool endsWith(const std::string &str, const std::string &suffix); /** Extracts portions of a path */ diff --git a/src/app/AudioWidget.cpp b/src/app/AudioWidget.cpp index 79a1cbec..8052267e 100644 --- a/src/app/AudioWidget.cpp +++ b/src/app/AudioWidget.cpp @@ -124,14 +124,14 @@ struct AudioSampleRateChoice : LedDisplayChoice { AudioSampleRateItem *item = new AudioSampleRateItem; item->port = port; item->sampleRate = sampleRate; - item->text = string::f("%d Hz", sampleRate); + item->text = string::f("%g kHz", sampleRate / 1000.0); item->rightText = CHECKMARK(item->sampleRate == port->sampleRate); menu->addChild(item); } } void step() override { if (port) - text = string::f("%g kHz", port->sampleRate / 1000.f); + text = string::f("%g kHz", port->sampleRate / 1000.0); else text = "44.1 kHz"; } diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index dd891a81..8829ec66 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -44,6 +44,10 @@ struct ModulePluginItem : ui::MenuItem { ui::Menu *createChildMenu() override { ui::Menu *menu = new ui::Menu; + ui::MenuLabel *pluginLabel = new ui::MenuLabel; + pluginLabel->text = plugin->name; + menu->addChild(pluginLabel); + ui::MenuLabel *versionLabel = new ui::MenuLabel; versionLabel->text = "v" + plugin->version; menu->addChild(versionLabel); @@ -774,7 +778,7 @@ void ModuleWidget::createContextMenu() { menu->addChild(modelLabel); ModulePluginItem *pluginItem = new ModulePluginItem; - pluginItem->text = model->plugin->name; + pluginItem->text = "Plugin"; pluginItem->rightText = RIGHT_ARROW; pluginItem->plugin = model->plugin; menu->addChild(pluginItem); diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index d7fa37d0..2896ad44 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -300,10 +300,11 @@ struct SampleRateItem : ui::MenuItem { SampleRateValueItem *item = new SampleRateValueItem; item->sampleRate = sampleRate; - item->text = string::f("%.0f Hz", sampleRate); + item->text = string::f("%g kHz", sampleRate / 1000.0); if (oversample > 1) - item->text += string::f(" (%dx)", oversample); - item->rightText = CHECKMARK(APP->engine->getSampleRate() == sampleRate); + item->rightText += string::f("(%dx)", oversample); + item->rightText += " "; + item->rightText += CHECKMARK(APP->engine->getSampleRate() == sampleRate); menu->addChild(item); } } diff --git a/src/string.cpp b/src/string.cpp index a7781d5a..c5863be4 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -67,6 +67,13 @@ std::string ellipsize(const std::string &s, size_t len) { return s.substr(0, len - 3) + "..."; } +std::string ellipsizePrefix(const std::string &s, size_t len) { + if (s.size() <= len) + return s; + else + return "..." + s.substr(s.size() - (len - 3)); +} + bool startsWith(const std::string &str, const std::string &prefix) { return str.substr(0, prefix.size()) == prefix; }