SDK/TextAreaWidget: Add ReadOnly option
This commit is contained in:
parent
c781f7cb45
commit
7dc600fb34
|
|
@ -36,11 +36,14 @@ namespace Ndk
|
||||||
|
|
||||||
std::size_t GetHoveredGlyph(float x, float y) const;
|
std::size_t GetHoveredGlyph(float x, float y) const;
|
||||||
|
|
||||||
|
inline bool IsReadOnly() const;
|
||||||
|
|
||||||
inline void MoveCursor(int offset);
|
inline void MoveCursor(int offset);
|
||||||
|
|
||||||
void ResizeToContent() override;
|
void ResizeToContent() override;
|
||||||
|
|
||||||
inline void SetCursorPosition(std::size_t cursorPosition);
|
inline void SetCursorPosition(std::size_t cursorPosition);
|
||||||
|
inline void SetReadOnly(bool readOnly = true);
|
||||||
void SetText(const Nz::String& text);
|
void SetText(const Nz::String& text);
|
||||||
|
|
||||||
void Write(const Nz::String& text);
|
void Write(const Nz::String& text);
|
||||||
|
|
@ -65,6 +68,7 @@ namespace Ndk
|
||||||
Nz::SpriteRef m_cursorSprite;
|
Nz::SpriteRef m_cursorSprite;
|
||||||
Nz::TextSpriteRef m_textSprite;
|
Nz::TextSpriteRef m_textSprite;
|
||||||
std::size_t m_cursorPosition;
|
std::size_t m_cursorPosition;
|
||||||
|
bool m_readOnly;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,11 @@ namespace Ndk
|
||||||
return m_drawer.GetText();
|
return m_drawer.GetText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool TextAreaWidget::IsReadOnly() const
|
||||||
|
{
|
||||||
|
return m_readOnly;
|
||||||
|
}
|
||||||
|
|
||||||
inline void TextAreaWidget::MoveCursor(int offset)
|
inline void TextAreaWidget::MoveCursor(int offset)
|
||||||
{
|
{
|
||||||
if (offset >= 0)
|
if (offset >= 0)
|
||||||
|
|
@ -50,4 +55,11 @@ namespace Ndk
|
||||||
|
|
||||||
RefreshCursor();
|
RefreshCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void TextAreaWidget::SetReadOnly(bool readOnly)
|
||||||
|
{
|
||||||
|
m_readOnly = readOnly;
|
||||||
|
|
||||||
|
m_cursorEntity->Enable(!m_readOnly);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,12 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
TextAreaWidget::TextAreaWidget(BaseWidget* parent) :
|
TextAreaWidget::TextAreaWidget(BaseWidget* parent) :
|
||||||
BaseWidget(parent),
|
BaseWidget(parent),
|
||||||
m_cursorPosition(0U)
|
m_cursorPosition(0U),
|
||||||
|
m_readOnly(false)
|
||||||
{
|
{
|
||||||
m_cursorSprite = Nz::Sprite::New();
|
m_cursorSprite = Nz::Sprite::New();
|
||||||
m_cursorSprite->SetColor(Nz::Color(192, 192, 192));
|
m_cursorSprite->SetColor(Nz::Color(192, 192, 192));
|
||||||
m_cursorSprite->SetSize(1.f, m_drawer.GetFont()->GetSizeInfo(m_drawer.GetCharacterSize()).lineHeight);
|
m_cursorSprite->SetSize(1.f, float(m_drawer.GetFont()->GetSizeInfo(m_drawer.GetCharacterSize()).lineHeight));
|
||||||
|
|
||||||
m_cursorEntity = CreateEntity();
|
m_cursorEntity = CreateEntity();
|
||||||
m_cursorEntity->AddComponent<GraphicsComponent>().Attach(m_cursorSprite, 10);
|
m_cursorEntity->AddComponent<GraphicsComponent>().Attach(m_cursorSprite, 10);
|
||||||
|
|
@ -188,6 +189,9 @@ namespace Ndk
|
||||||
|
|
||||||
void TextAreaWidget::OnTextEntered(char32_t character, bool /*repeated*/)
|
void TextAreaWidget::OnTextEntered(char32_t character, bool /*repeated*/)
|
||||||
{
|
{
|
||||||
|
if (m_readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
switch (character)
|
switch (character)
|
||||||
{
|
{
|
||||||
case '\b':
|
case '\b':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue