SDK/TextAreaWidget: Add cursor shifting by left and right arrows

This commit is contained in:
Lynix 2016-12-03 00:40:31 +01:00
parent d28dab2e36
commit 6c03803c5e
2 changed files with 29 additions and 0 deletions

View File

@ -40,6 +40,8 @@ namespace Ndk
private:
void RefreshCursor();
void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override;
void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key) override;
void OnMouseEnter() override;
void OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button button) override;
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;

View File

@ -111,6 +111,33 @@ namespace Ndk
m_cursorEntity->GetComponent<Ndk::NodeComponent>().SetPosition(position, lineInfo.bounds.y);
}
void TextAreaWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key)
{
switch (key.code)
{
case Nz::Keyboard::Left:
if (m_cursorPosition > 0)
m_cursorPosition--;
RefreshCursor();
break;
case Nz::Keyboard::Right:
{
std::size_t glyphCount = m_drawer.GetGlyphCount();
if (m_cursorPosition < glyphCount)
m_cursorPosition++;
RefreshCursor();
break;
}
}
}
void TextAreaWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& key)
{
}
void TextAreaWidget::OnMouseEnter()
{
m_cursorEntity->Enable(true);