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