SDK/(Rich)TextAreaWidget: Add character and line spacing offsets
This commit is contained in:
parent
8c7301f649
commit
1d86d90ca0
|
|
@ -321,6 +321,7 @@ Nazara Development Kit:
|
||||||
- Fixed crash when pressing up/down key with no history in the console
|
- Fixed crash when pressing up/down key with no history in the console
|
||||||
- (Rich)TextAreaWidget text style is now alterable
|
- (Rich)TextAreaWidget text style is now alterable
|
||||||
- Added CameraComponent::SetProjectionScale
|
- Added CameraComponent::SetProjectionScale
|
||||||
|
- Added (Rich)TextAreaWidget character and line spacing offset properties
|
||||||
|
|
||||||
# 0.4:
|
# 0.4:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ namespace Ndk
|
||||||
void Erase(std::size_t firstGlyph, std::size_t lastGlyph) override;
|
void Erase(std::size_t firstGlyph, std::size_t lastGlyph) override;
|
||||||
|
|
||||||
inline unsigned int GetCharacterSize() const;
|
inline unsigned int GetCharacterSize() const;
|
||||||
|
inline float GetCharacterSpacingOffset() const;
|
||||||
|
inline float GetLineSpacingOffset() const;
|
||||||
inline const Nz::Color& GetTextColor() const;
|
inline const Nz::Color& GetTextColor() const;
|
||||||
inline Nz::Font* GetTextFont() const;
|
inline Nz::Font* GetTextFont() const;
|
||||||
inline const Nz::Color& GetTextOutlineColor() const;
|
inline const Nz::Color& GetTextOutlineColor() const;
|
||||||
|
|
@ -34,6 +36,8 @@ namespace Ndk
|
||||||
inline Nz::TextStyleFlags GetTextStyle() const;
|
inline Nz::TextStyleFlags GetTextStyle() const;
|
||||||
|
|
||||||
inline void SetCharacterSize(unsigned int characterSize);
|
inline void SetCharacterSize(unsigned int characterSize);
|
||||||
|
inline void SetCharacterSpacingOffset(float offset);
|
||||||
|
inline void SetLineSpacingOffset(float offset);
|
||||||
inline void SetTextColor(const Nz::Color& color);
|
inline void SetTextColor(const Nz::Color& color);
|
||||||
inline void SetTextFont(Nz::FontRef font);
|
inline void SetTextFont(Nz::FontRef font);
|
||||||
inline void SetTextOutlineColor(const Nz::Color& color);
|
inline void SetTextOutlineColor(const Nz::Color& color);
|
||||||
|
|
@ -53,7 +57,7 @@ namespace Ndk
|
||||||
void HandleSelectionIndentation(bool add) override;
|
void HandleSelectionIndentation(bool add) override;
|
||||||
void HandleWordCursorMove(bool left) override;
|
void HandleWordCursorMove(bool left) override;
|
||||||
|
|
||||||
void UpdateDisplayText();
|
void UpdateDisplayText() override;
|
||||||
|
|
||||||
Nz::RichTextDrawer m_drawer;
|
Nz::RichTextDrawer m_drawer;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,16 @@ namespace Ndk
|
||||||
return m_drawer.GetDefaultCharacterSize();
|
return m_drawer.GetDefaultCharacterSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float RichTextAreaWidget::GetCharacterSpacingOffset() const
|
||||||
|
{
|
||||||
|
return m_drawer.GetDefaultCharacterSpacingOffset();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float RichTextAreaWidget::GetLineSpacingOffset() const
|
||||||
|
{
|
||||||
|
return m_drawer.GetDefaultLineSpacingOffset();
|
||||||
|
}
|
||||||
|
|
||||||
inline const Nz::Color& RichTextAreaWidget::GetTextColor() const
|
inline const Nz::Color& RichTextAreaWidget::GetTextColor() const
|
||||||
{
|
{
|
||||||
return m_drawer.GetDefaultColor();
|
return m_drawer.GetDefaultColor();
|
||||||
|
|
@ -41,6 +51,16 @@ namespace Ndk
|
||||||
m_drawer.SetDefaultCharacterSize(characterSize);
|
m_drawer.SetDefaultCharacterSize(characterSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void RichTextAreaWidget::SetCharacterSpacingOffset(float offset)
|
||||||
|
{
|
||||||
|
m_drawer.SetDefaultCharacterSpacingOffset(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void RichTextAreaWidget::SetLineSpacingOffset(float offset)
|
||||||
|
{
|
||||||
|
m_drawer.SetDefaultLineSpacingOffset(offset);
|
||||||
|
}
|
||||||
|
|
||||||
inline void RichTextAreaWidget::SetTextColor(const Nz::Color& color)
|
inline void RichTextAreaWidget::SetTextColor(const Nz::Color& color)
|
||||||
{
|
{
|
||||||
m_drawer.SetDefaultColor(color);
|
m_drawer.SetDefaultColor(color);
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ namespace Ndk
|
||||||
|
|
||||||
inline unsigned int GetCharacterSize() const;
|
inline unsigned int GetCharacterSize() const;
|
||||||
inline const Nz::String& GetDisplayText() const;
|
inline const Nz::String& GetDisplayText() const;
|
||||||
|
inline float GetCharacterSpacingOffset() const;
|
||||||
|
inline float GetLineSpacingOffset() const;
|
||||||
inline const Nz::String& GetText() const;
|
inline const Nz::String& GetText() const;
|
||||||
inline const Nz::Color& GetTextColor() const;
|
inline const Nz::Color& GetTextColor() const;
|
||||||
inline Nz::Font* GetTextFont() const;
|
inline Nz::Font* GetTextFont() const;
|
||||||
|
|
@ -36,7 +38,9 @@ namespace Ndk
|
||||||
inline float GetTextOulineThickness() const;
|
inline float GetTextOulineThickness() const;
|
||||||
inline Nz::TextStyleFlags GetTextStyle() const;
|
inline Nz::TextStyleFlags GetTextStyle() const;
|
||||||
|
|
||||||
void SetCharacterSize(unsigned int characterSize);
|
inline void SetCharacterSize(unsigned int characterSize);
|
||||||
|
inline void SetCharacterSpacingOffset(float offset);
|
||||||
|
inline void SetLineSpacingOffset(float offset);
|
||||||
inline void SetText(const Nz::String& text);
|
inline void SetText(const Nz::String& text);
|
||||||
inline void SetTextColor(const Nz::Color& text);
|
inline void SetTextColor(const Nz::Color& text);
|
||||||
inline void SetTextFont(Nz::FontRef font);
|
inline void SetTextFont(Nz::FontRef font);
|
||||||
|
|
@ -61,6 +65,7 @@ namespace Ndk
|
||||||
void HandleWordCursorMove(bool left) override;
|
void HandleWordCursorMove(bool left) override;
|
||||||
|
|
||||||
void UpdateDisplayText() override;
|
void UpdateDisplayText() override;
|
||||||
|
void UpdateMinimumSize();
|
||||||
|
|
||||||
Nz::SimpleTextDrawer m_drawer;
|
Nz::SimpleTextDrawer m_drawer;
|
||||||
Nz::String m_text;
|
Nz::String m_text;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,16 @@ namespace Ndk
|
||||||
return m_drawer.GetText();
|
return m_drawer.GetText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float TextAreaWidget::GetCharacterSpacingOffset() const
|
||||||
|
{
|
||||||
|
return m_drawer.GetCharacterSpacingOffset();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float TextAreaWidget::GetLineSpacingOffset() const
|
||||||
|
{
|
||||||
|
return m_drawer.GetLineSpacingOffset();
|
||||||
|
}
|
||||||
|
|
||||||
inline const Nz::String& TextAreaWidget::GetText() const
|
inline const Nz::String& TextAreaWidget::GetText() const
|
||||||
{
|
{
|
||||||
return m_text;
|
return m_text;
|
||||||
|
|
@ -46,6 +56,29 @@ namespace Ndk
|
||||||
return m_drawer.GetStyle();
|
return m_drawer.GetStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize)
|
||||||
|
{
|
||||||
|
m_drawer.SetCharacterSize(characterSize);
|
||||||
|
|
||||||
|
UpdateMinimumSize();
|
||||||
|
UpdateDisplayText();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void TextAreaWidget::SetCharacterSpacingOffset(float offset)
|
||||||
|
{
|
||||||
|
m_drawer.SetCharacterSpacingOffset(offset);
|
||||||
|
|
||||||
|
UpdateMinimumSize();
|
||||||
|
UpdateDisplayText();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void TextAreaWidget::SetLineSpacingOffset(float offset)
|
||||||
|
{
|
||||||
|
m_drawer.SetLineSpacingOffset(offset);
|
||||||
|
|
||||||
|
UpdateDisplayText();
|
||||||
|
}
|
||||||
|
|
||||||
inline void TextAreaWidget::SetText(const Nz::String& text)
|
inline void TextAreaWidget::SetText(const Nz::String& text)
|
||||||
{
|
{
|
||||||
m_text = text;
|
m_text = text;
|
||||||
|
|
|
||||||
|
|
@ -91,26 +91,6 @@ namespace Ndk
|
||||||
SetText(newText);
|
SetText(newText);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextAreaWidget::SetCharacterSize(unsigned int characterSize)
|
|
||||||
{
|
|
||||||
m_drawer.SetCharacterSize(characterSize);
|
|
||||||
|
|
||||||
std::size_t fontCount = m_drawer.GetFontCount();
|
|
||||||
unsigned int lineHeight = 0;
|
|
||||||
int spaceAdvance = 0;
|
|
||||||
for (std::size_t i = 0; i < fontCount; ++i)
|
|
||||||
{
|
|
||||||
Nz::Font* font = m_drawer.GetFont(i);
|
|
||||||
|
|
||||||
const Nz::Font::SizeInfo& sizeInfo = font->GetSizeInfo(characterSize);
|
|
||||||
lineHeight = std::max(lineHeight, sizeInfo.lineHeight);
|
|
||||||
spaceAdvance = std::max(spaceAdvance, sizeInfo.spaceAdvance);
|
|
||||||
}
|
|
||||||
|
|
||||||
Nz::Vector2f size = { float(spaceAdvance), float(lineHeight) + 5.f };
|
|
||||||
SetMinimumSize(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextAreaWidget::Write(const Nz::String& text, std::size_t glyphPosition)
|
void TextAreaWidget::Write(const Nz::String& text, std::size_t glyphPosition)
|
||||||
{
|
{
|
||||||
if (glyphPosition >= m_drawer.GetGlyphCount())
|
if (glyphPosition >= m_drawer.GetGlyphCount())
|
||||||
|
|
@ -252,4 +232,22 @@ namespace Ndk
|
||||||
|
|
||||||
SetCursorPosition(m_cursorPositionBegin); //< Refresh cursor position (prevent it from being outside of the text)
|
SetCursorPosition(m_cursorPositionBegin); //< Refresh cursor position (prevent it from being outside of the text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::UpdateMinimumSize()
|
||||||
|
{
|
||||||
|
std::size_t fontCount = m_drawer.GetFontCount();
|
||||||
|
float lineHeight = 0;
|
||||||
|
int spaceAdvance = 0;
|
||||||
|
for (std::size_t i = 0; i < fontCount; ++i)
|
||||||
|
{
|
||||||
|
Nz::Font* font = m_drawer.GetFont(i);
|
||||||
|
|
||||||
|
const Nz::Font::SizeInfo& sizeInfo = font->GetSizeInfo(m_drawer.GetCharacterSize());
|
||||||
|
lineHeight = std::max(lineHeight, m_drawer.GetLineHeight());
|
||||||
|
spaceAdvance = std::max(spaceAdvance, sizeInfo.spaceAdvance);
|
||||||
|
}
|
||||||
|
|
||||||
|
Nz::Vector2f size = { float(spaceAdvance), lineHeight + 5.f };
|
||||||
|
SetMinimumSize(size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue