Sdk/TextAreaWidget: Add signals (allowing for controlling the cursor/keys)
This commit is contained in:
parent
5d39d60f94
commit
ec795269ad
|
|
@ -56,6 +56,14 @@ namespace Ndk
|
|||
TextAreaWidget& operator=(const TextAreaWidget&) = delete;
|
||||
TextAreaWidget& operator=(TextAreaWidget&&) = default;
|
||||
|
||||
NazaraSignal(OnTextAreaCursorMove, const TextAreaWidget* /*textArea*/, std::size_t* /*newCursorPosition*/);
|
||||
NazaraSignal(OnTextAreaKeyBackspace, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyDown, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyLeft, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyReturn, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyRight, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
NazaraSignal(OnTextAreaKeyUp, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
|
||||
|
||||
private:
|
||||
void Layout() override;
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ namespace Ndk
|
|||
|
||||
inline void TextAreaWidget::SetCursorPosition(std::size_t cursorPosition)
|
||||
{
|
||||
OnTextAreaCursorMove(this, &cursorPosition);
|
||||
|
||||
m_cursorPosition = std::min(cursorPosition, m_drawer.GetGlyphCount());
|
||||
|
||||
RefreshCursor();
|
||||
|
|
@ -83,6 +85,8 @@ namespace Ndk
|
|||
m_drawer.SetText(text);
|
||||
|
||||
m_textSprite->Update(m_drawer);
|
||||
|
||||
SetCursorPosition(m_cursorPosition); //< Refresh cursor position (prevent it from being outside of the text)
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextColor(const Nz::Color& text)
|
||||
|
|
|
|||
|
|
@ -123,13 +123,53 @@ namespace Ndk
|
|||
break;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::Down:
|
||||
{
|
||||
bool ignoreDefaultAction = false;
|
||||
OnTextAreaKeyDown(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction)
|
||||
break;
|
||||
|
||||
//TODO
|
||||
break;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::Left:
|
||||
{
|
||||
bool ignoreDefaultAction = false;
|
||||
OnTextAreaKeyLeft(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction)
|
||||
break;
|
||||
|
||||
MoveCursor(-1);
|
||||
break;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::Right:
|
||||
{
|
||||
bool ignoreDefaultAction = false;
|
||||
OnTextAreaKeyRight(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction)
|
||||
break;
|
||||
|
||||
MoveCursor(1);
|
||||
break;
|
||||
}
|
||||
|
||||
case Nz::Keyboard::Up:
|
||||
{
|
||||
bool ignoreDefaultAction = false;
|
||||
OnTextAreaKeyUp(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction)
|
||||
break;
|
||||
|
||||
//TODO
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -170,6 +210,12 @@ namespace Ndk
|
|||
{
|
||||
case '\b':
|
||||
{
|
||||
bool ignoreDefaultAction = false;
|
||||
OnTextAreaKeyBackspace(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction)
|
||||
break;
|
||||
|
||||
const Nz::String& text = m_drawer.GetText();
|
||||
|
||||
Nz::String newText;
|
||||
|
|
@ -179,18 +225,23 @@ namespace Ndk
|
|||
if (m_cursorPosition < m_drawer.GetGlyphCount())
|
||||
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorPosition)));
|
||||
|
||||
SetText(newText);
|
||||
MoveCursor(-1);
|
||||
SetText(newText);
|
||||
break;
|
||||
}
|
||||
|
||||
case '\r':
|
||||
case '\n':
|
||||
if (!m_multiLineEnabled)
|
||||
{
|
||||
bool ignoreDefaultAction = false;
|
||||
OnTextAreaKeyReturn(this, &ignoreDefaultAction);
|
||||
|
||||
if (ignoreDefaultAction || !m_multiLineEnabled)
|
||||
break;
|
||||
|
||||
Write(Nz::String('\n'));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue