Subclass CTextEdit using Enter key as Return
This commit is contained in:
parent
1bfcfd4b8c
commit
2752c8c1c8
3 changed files with 49 additions and 2 deletions
|
|
@ -134,7 +134,7 @@ struct Editor::Impl : EditorController::Receiver,
|
||||||
SValueMenu *scalaRootOctaveSlider_ = nullptr;
|
SValueMenu *scalaRootOctaveSlider_ = nullptr;
|
||||||
CTextLabel* scalaRootKeyLabel_ = nullptr;
|
CTextLabel* scalaRootKeyLabel_ = nullptr;
|
||||||
SValueMenu* tuningFrequencyDropdown_ = nullptr;
|
SValueMenu* tuningFrequencyDropdown_ = nullptr;
|
||||||
CTextEdit* tuningFrequencyEdit_ = nullptr;
|
STextEdit* tuningFrequencyEdit_ = nullptr;
|
||||||
CTextLabel* tuningFrequencyLabel_ = nullptr;
|
CTextLabel* tuningFrequencyLabel_ = nullptr;
|
||||||
CControl *stretchedTuningSlider_ = nullptr;
|
CControl *stretchedTuningSlider_ = nullptr;
|
||||||
CTextLabel* stretchedTuningLabel_ = nullptr;
|
CTextLabel* stretchedTuningLabel_ = nullptr;
|
||||||
|
|
@ -1114,7 +1114,7 @@ void Editor::Impl::createFrameContents()
|
||||||
};
|
};
|
||||||
|
|
||||||
auto createTextEdit = [this, &palette] (const CRect& bounds, int tag, const char* label, CHoriTxtAlign align, int fontsize) {
|
auto createTextEdit = [this, &palette] (const CRect& bounds, int tag, const char* label, CHoriTxtAlign align, int fontsize) {
|
||||||
auto* edit = new CTextEdit(bounds, this, tag, label, nullptr);
|
auto* edit = new STextEdit(bounds, this, tag, label, nullptr);
|
||||||
auto font = makeOwned<CFontDesc>("Roboto", fontsize);
|
auto font = makeOwned<CFontDesc>("Roboto", fontsize);
|
||||||
edit->setFont(font);
|
edit->setFont(font);
|
||||||
edit->setHoriAlign(align);
|
edit->setHoriAlign(align);
|
||||||
|
|
|
||||||
|
|
@ -1348,3 +1348,36 @@ void SPlaceHolder::draw(CDrawContext* dc)
|
||||||
dc->drawLine(bounds.getTopLeft(), bounds.getBottomRight());
|
dc->drawLine(bounds.getTopLeft(), bounds.getBottomRight());
|
||||||
dc->drawLine(bounds.getTopRight(), bounds.getBottomLeft());
|
dc->drawLine(bounds.getTopRight(), bounds.getBottomLeft());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STextEdit::STextEdit(
|
||||||
|
const CRect& size,
|
||||||
|
IControlListener* listener,
|
||||||
|
int32_t tag,
|
||||||
|
UTF8StringPtr txt,
|
||||||
|
CBitmap* background,
|
||||||
|
const int32_t style)
|
||||||
|
: CTextEdit(size, listener, tag, txt, background, style)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void STextEdit::onKeyboardEvent(KeyboardEvent &event)
|
||||||
|
{
|
||||||
|
if (!platformControl || event.type != EventType::KeyDown)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (event.virt == VirtualKey::Escape)
|
||||||
|
{
|
||||||
|
bWasReturnPressed = false;
|
||||||
|
platformControl->setText (text);
|
||||||
|
getFrame ()->setFocusView (nullptr);
|
||||||
|
looseFocus ();
|
||||||
|
event.consumed = true;
|
||||||
|
}
|
||||||
|
else if (event.virt == VirtualKey::Return || event.virt == VirtualKey::Enter)
|
||||||
|
{
|
||||||
|
bWasReturnPressed = true;
|
||||||
|
getFrame ()->setFocusView (nullptr);
|
||||||
|
looseFocus ();
|
||||||
|
event.consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -236,6 +236,20 @@ private:
|
||||||
bool inactive_ { false };
|
bool inactive_ { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// CTextEdit control that can use Enter key as Return
|
||||||
|
class STextEdit: public CTextEdit {
|
||||||
|
public:
|
||||||
|
STextEdit(
|
||||||
|
const CRect& size,
|
||||||
|
IControlListener* listener,
|
||||||
|
int32_t tag,
|
||||||
|
UTF8StringPtr txt = nullptr,
|
||||||
|
CBitmap* background = nullptr,
|
||||||
|
const int32_t style = 0
|
||||||
|
);
|
||||||
|
void onKeyboardEvent(KeyboardEvent& event) override;
|
||||||
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
class SStyledKnob : public CKnobBase {
|
class SStyledKnob : public CKnobBase {
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue