69 fcn::Key key = keyEvent.getKey();
70 int32_t keyType = key.getValue();
72 if (keyType == Key::Left && getCaretPosition() > 0)
74 TextField::keyPressed(keyEvent);
76 else if (keyType == Key::Right && getCaretPosition() < getText().size())
78 TextField::keyPressed(keyEvent);
80 else if (keyType == Key::Down && !
m_history.empty())
91 else if (keyType == Key::Up && !
m_history.empty())
101 else if (keyType == Key::Delete && getCaretPosition() < getText().size())
103 TextField::keyPressed(keyEvent);
105 else if (keyType == Key::Backspace && getCaretPosition() > 0)
107 TextField::keyPressed(keyEvent);
109 else if (keyType == Key::Enter)
111 if( getText() !=
"" ) {
120 else if (keyType == Key::Home)
124 else if (keyType == Key::End)
126 setCaretPosition(getText().size());
128 else if (key.isCharacter() ||
static_cast<uint32_t>(key.getValue()) > 255)
130 TextField::keyPressed(keyEvent);
140 graphics->setColor(getForegroundColor());
141 graphics->drawLine(x, getHeight() - 2, x, 1);
142 graphics->drawLine(x+1, getHeight() - 2, x+1, 1);
void stopBlinking()
Stop blinking the caret for a few seconds.
void setCallback(const type_callback &cb)
Set callback on pressing the ENTER key.
size_t m_history_position
void setInterval(int32_t msec)
Set the interval in milliseconds.
void start()
Start the timer.
void keyPressed(fcn::KeyEvent &keyEvent)
void toggleCaretVisible()
Toggle the caret visibility.
void startBlinking()
Start blinking the caret.
void stop()
Stop the timer.
std::function< void(std::string)> type_callback
std::vector< std::string > m_history
~CommandLine()
Destructor.
virtual void drawCaret(fcn::Graphics *graphics, int32_t x)
CommandLine()
Constructor.
void setCallback(const type_callback &callback)
Set the callback that will be called.
Timer m_suppressBlinkTimer