Widgets/TextAreaWidget: Add a way to limit text length

This commit is contained in:
SirLynix
2024-01-26 16:15:53 +01:00
parent f10671ac2a
commit c931e9a509
7 changed files with 92 additions and 9 deletions

View File

@@ -42,6 +42,7 @@ namespace Nz
inline EchoMode GetEchoMode() const;
inline std::size_t GetGlyphIndex() const;
inline std::size_t GetGlyphIndex(const Vector2ui& cursorPosition) const;
inline std::size_t GetMaximumTextLength() const;
Vector2ui GetHoveredGlyph(float x, float y) const;
@@ -61,6 +62,7 @@ namespace Nz
inline void SetCursorPosition(std::size_t glyphIndex);
inline void SetCursorPosition(Vector2ui cursorPosition);
inline void SetEchoMode(EchoMode echoMode);
virtual void SetMaximumTextLength(std::size_t maximumLength) = 0;
inline void SetReadOnly(bool readOnly = true);
inline void SetSelection(Vector2ui fromPosition, Vector2ui toPosition);
@@ -131,6 +133,7 @@ namespace Nz
};
std::shared_ptr<TextSprite> m_textSprite;
std::size_t m_maximumTextLength;
std::vector<Cursor> m_cursors;
CharacterFilter m_characterFilter;
EchoMode m_echoMode;

View File

@@ -87,6 +87,11 @@ namespace Nz
return glyphIndex;
}
inline std::size_t AbstractTextAreaWidget::GetMaximumTextLength() const
{
return m_maximumTextLength;
}
inline bool AbstractTextAreaWidget::HasSelection() const
{
return m_cursorPositionBegin != m_cursorPositionEnd;
@@ -257,3 +262,4 @@ namespace Nz
}
#include <Nazara/Widgets/DebugOff.hpp>
#include "AbstractTextAreaWidget.hpp"

View File

@@ -38,6 +38,7 @@ namespace Nz
inline void SetCharacterSize(unsigned int characterSize);
inline void SetCharacterSpacingOffset(float offset);
inline void SetLineSpacingOffset(float offset);
void SetMaximumTextLength(std::size_t maximumLength) override;
inline void SetTextColor(const Color& color);
inline void SetTextFont(std::shared_ptr<Font> font);
inline void SetTextOutlineColor(const Color& color);

View File

@@ -41,6 +41,7 @@ namespace Nz
inline void SetCharacterSize(unsigned int characterSize);
inline void SetCharacterSpacingOffset(float offset);
inline void SetLineSpacingOffset(float offset);
void SetMaximumTextLength(std::size_t maximumLength) override;
inline void SetText(std::string text);
inline void SetTextColor(const Color& text);
inline void SetTextFont(std::shared_ptr<Font> font);