Browse Source

Add TextField::password property, make PasswordField simply set that property.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
aff9aa6fa6
5 changed files with 18 additions and 36 deletions
  1. +0
    -1
      include/rack.hpp
  2. +0
    -17
      include/ui/PasswordField.hpp
  3. +9
    -0
      include/ui/TextField.hpp
  4. +0
    -17
      src/ui/PasswordField.cpp
  5. +9
    -1
      src/ui/TextField.cpp

+ 0
- 1
include/rack.hpp View File

@@ -64,7 +64,6 @@ Directly including Rack headers other than rack.hpp in your plugin is unsupporte
#include <ui/RadioButton.hpp> #include <ui/RadioButton.hpp>
#include <ui/Menu.hpp> #include <ui/Menu.hpp>
#include <ui/ScrollWidget.hpp> #include <ui/ScrollWidget.hpp>
#include <ui/PasswordField.hpp>


#include <app/SliderKnob.hpp> #include <app/SliderKnob.hpp>
#include <app/MultiLightWidget.hpp> #include <app/MultiLightWidget.hpp>


+ 0
- 17
include/ui/PasswordField.hpp View File

@@ -1,17 +0,0 @@
#pragma once
#include <ui/common.hpp>
#include <ui/TextField.hpp>


namespace rack {
namespace ui {


/** A TextField that hides/replaces all characters with "*" */
struct PasswordField : TextField {
void draw(const DrawArgs& args) override;
};


} // namespace ui
} // namespace rack

+ 9
- 0
include/ui/TextField.hpp View File

@@ -11,6 +11,8 @@ namespace ui {
struct TextField : widget::OpaqueWidget { struct TextField : widget::OpaqueWidget {
std::string text; std::string text;
std::string placeholder; std::string placeholder;
/** Masks text with "*". */
bool password = false;
bool multiline = false; bool multiline = false;
/** The index of the text cursor */ /** The index of the text cursor */
int cursor = 0; int cursor = 0;
@@ -48,5 +50,12 @@ struct TextField : widget::OpaqueWidget {
}; };




struct PasswordField : TextField {
PasswordField() {
password = true;
}
};


} // namespace ui } // namespace ui
} // namespace rack } // namespace rack

+ 0
- 17
src/ui/PasswordField.cpp View File

@@ -1,17 +0,0 @@
#include <ui/PasswordField.hpp>


namespace rack {
namespace ui {


void PasswordField::draw(const DrawArgs& args) {
std::string textTmp = text;
text = std::string(textTmp.size(), '*');
TextField::draw(args);
text = textTmp;
}


} // namespace ui
} // namespace rack

+ 9
- 1
src/ui/TextField.cpp View File

@@ -69,7 +69,15 @@ void TextField::draw(const DrawArgs& args) {
int begin = std::min(cursor, selection); int begin = std::min(cursor, selection);
int end = std::max(cursor, selection); int end = std::max(cursor, selection);


bndTextField(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str(), begin, end);
std::string drawText;
if (password) {
drawText = std::string(text.size(), '*');
}
else {
drawText = text;
}

bndTextField(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, drawText.c_str(), begin, end);


// Draw placeholder text // Draw placeholder text
if (text.empty()) { if (text.empty()) {


Loading…
Cancel
Save