Browse Source

Scissor text fields

pull/1639/head
Andrew Belt 7 years ago
parent
commit
af9ba02402
3 changed files with 25 additions and 19 deletions
  1. +1
    -1
      src/app/AudioWidget.cpp
  2. +20
    -18
      src/app/LedDisplay.cpp
  3. +4
    -0
      src/ui/TextField.cpp

+ 1
- 1
src/app/AudioWidget.cpp View File

@@ -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();


+ 20
- 18
src/app/LedDisplay.cpp View File

@@ -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) {


+ 4
- 0
src/ui/TextField.cpp View File

@@ -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) {


Loading…
Cancel
Save