diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-28 20:08:11 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-28 20:08:11 +1000 |
commit | 48ec8895797001298f90e02545811a3e5d8169f8 (patch) | |
tree | 4ee2d6107601d78d46ae251601ea8d6a7bcc1b54 /source/rendering/StarTextPainter.hpp | |
parent | 4b91eb717554aeaab8f366a1608276acb5f88479 (diff) |
TextPainter now uses StringView
Diffstat (limited to 'source/rendering/StarTextPainter.hpp')
-rw-r--r-- | source/rendering/StarTextPainter.hpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/source/rendering/StarTextPainter.hpp b/source/rendering/StarTextPainter.hpp index 7b0db7c..0da4904 100644 --- a/source/rendering/StarTextPainter.hpp +++ b/source/rendering/StarTextPainter.hpp @@ -4,6 +4,7 @@ #include "StarFontTextureGroup.hpp" #include "StarAnchorTypes.hpp" #include "StarRoot.hpp" +#include "StarStringView.hpp" namespace Star { @@ -54,18 +55,24 @@ class TextPainter { public: TextPainter(RendererPtr renderer, TextureGroupPtr textureGroup); - RectF renderText(String const& s, TextPositioning const& position); - RectF renderLine(String const& s, TextPositioning const& position); + RectF renderText(StringView s, TextPositioning const& position); + RectF renderLine(StringView s, TextPositioning const& position); RectF renderGlyph(String::Char c, TextPositioning const& position); - RectF determineTextSize(String const& s, TextPositioning const& position); - RectF determineLineSize(String const& s, TextPositioning const& position); + RectF determineTextSize(StringView s, TextPositioning const& position); + RectF determineLineSize(StringView s, TextPositioning const& position); RectF determineGlyphSize(String::Char c, TextPositioning const& position); int glyphWidth(String::Char c); - int stringWidth(String const& s); + int stringWidth(StringView s); - StringList wrapText(String const& s, Maybe<unsigned> wrapWidth); + + typedef function<bool(StringView text, int line)> WrapTextCallback; + typedef function<bool(StringView command)> WrapCommandsCallback; + void processWrapText(StringView s, Maybe<unsigned> wrapWidth, WrapTextCallback textFunc, WrapCommandsCallback commandFunc = WrapCommandsCallback(), bool includeCommandSides = false); + + List<StringView> wrapTextViews(StringView s, Maybe<unsigned> wrapWidth); + StringList wrapText(StringView s, Maybe<unsigned> wrapWidth); unsigned fontSize() const; void setFontSize(unsigned size); @@ -79,7 +86,7 @@ public: void reloadFonts(); void cleanup(int64_t textureTimeout); - void applyCommands(String const& unsplitCommands); + void applyCommands(StringView unsplitCommands); private: struct RenderSettings { FontMode mode; @@ -88,8 +95,8 @@ private: String directives; }; - RectF doRenderText(String const& s, TextPositioning const& position, bool reallyRender, unsigned* charLimit); - RectF doRenderLine(String const& s, TextPositioning const& position, bool reallyRender, unsigned* charLimit); + RectF doRenderText(StringView s, TextPositioning const& position, bool reallyRender, unsigned* charLimit); + RectF doRenderLine(StringView s, TextPositioning const& position, bool reallyRender, unsigned* charLimit); RectF doRenderGlyph(String::Char c, TextPositioning const& position, bool reallyRender); void renderGlyph(String::Char c, Vec2F const& screenPos, unsigned fontSize, float scale, Vec4B const& color, String const& processingDirectives); |