From af9ba02402e70550aad9bec97c3608e08aac9240 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 25 Feb 2018 16:37:58 -0500 Subject: [PATCH] Scissor text fields --- src/app/AudioWidget.cpp | 2 +- src/app/LedDisplay.cpp | 38 ++++++++++++++++++++------------------ src/ui/TextField.cpp | 4 ++++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/app/AudioWidget.cpp b/src/app/AudioWidget.cpp index 2bb4f165..6050fa6f 100644 --- a/src/app/AudioWidget.cpp +++ b/src/app/AudioWidget.cpp @@ -45,7 +45,7 @@ struct AudioDeviceItem : MenuItem { struct AudioDeviceChoice : LedDisplayChoice { AudioWidget *audioWidget; /** Prevents devices with a ridiculous number of channels from being displayed */ - int maxTotalChannels = 64; + int maxTotalChannels = 128; void onAction(EventAction &e) override { Menu *menu = gScene->createMenu(); diff --git a/src/app/LedDisplay.cpp b/src/app/LedDisplay.cpp index 7003e1b3..f3688389 100644 --- a/src/app/LedDisplay.cpp +++ b/src/app/LedDisplay.cpp @@ -40,15 +40,14 @@ LedDisplayChoice::LedDisplayChoice() { void LedDisplayChoice::draw(NVGcontext *vg) { nvgScissor(vg, 0, 0, box.size.x, box.size.y); - if (font->handle < 0) - return; + if (font->handle >= 0) { + nvgFillColor(vg, color); + nvgFontFaceId(vg, font->handle); + nvgTextLetterSpacing(vg, 0.0); - nvgFillColor(vg, color); - nvgFontFaceId(vg, font->handle); - nvgTextLetterSpacing(vg, 0.0); - - nvgFontSize(vg, 12); - nvgText(vg, textOffset.x, textOffset.y, text.c_str(), NULL); + nvgFontSize(vg, 12); + nvgText(vg, textOffset.x, textOffset.y, text.c_str(), NULL); + } nvgResetScissor(vg); } @@ -71,6 +70,8 @@ LedDisplayTextField::LedDisplayTextField() { void LedDisplayTextField::draw(NVGcontext *vg) { + nvgScissor(vg, 0, 0, box.size.x, box.size.y); + // Background nvgBeginPath(vg); nvgRoundedRect(vg, 0, 0, box.size.x, box.size.y, 5.0); @@ -78,19 +79,20 @@ void LedDisplayTextField::draw(NVGcontext *vg) { nvgFill(vg); // Text - if (font->handle < 0) - return; + if (font->handle >= 0) { + bndSetFont(font->handle); - bndSetFont(font->handle); + NVGcolor highlightColor = color; + highlightColor.a = 0.5; + int cend = (this == gFocusedWidget) ? end : -1; + bndIconLabelCaret(vg, textOffset.x, textOffset.y, + box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, + -1, color, 12, text.c_str(), highlightColor, begin, cend); - NVGcolor highlightColor = color; - highlightColor.a = 0.5; - int cend = (this == gFocusedWidget) ? end : -1; - bndIconLabelCaret(vg, textOffset.x, textOffset.y, - box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, - -1, color, 12, text.c_str(), highlightColor, begin, cend); + bndSetFont(gGuiFont->handle); + } - bndSetFont(gGuiFont->handle); + nvgResetScissor(vg); } int LedDisplayTextField::getTextPosition(Vec mousePos) { diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index 09c27024..be9d314b 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -9,6 +9,8 @@ namespace rack { void TextField::draw(NVGcontext *vg) { + nvgScissor(vg, 0, 0, box.size.x, box.size.y); + BNDwidgetState state; if (this == gFocusedWidget) state = BND_ACTIVE; @@ -22,6 +24,8 @@ void TextField::draw(NVGcontext *vg) { if (text.empty() && state != BND_ACTIVE) { bndIconLabelCaret(vg, 0.0, 0.0, box.size.x, box.size.y, -1, bndGetTheme()->textFieldTheme.itemColor, 13, placeholder.c_str(), bndGetTheme()->textFieldTheme.itemColor, 0, -1); } + + nvgResetScissor(vg); } void TextField::onMouseDown(EventMouseDown &e) {