summaryrefslogtreecommitdiff
path: root/Runtime/IMGUI/TextFormatting.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/IMGUI/TextFormatting.h
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/IMGUI/TextFormatting.h')
-rw-r--r--Runtime/IMGUI/TextFormatting.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/Runtime/IMGUI/TextFormatting.h b/Runtime/IMGUI/TextFormatting.h
new file mode 100644
index 0000000..3646692
--- /dev/null
+++ b/Runtime/IMGUI/TextFormatting.h
@@ -0,0 +1,85 @@
+#ifndef TEXTFORMATTING_H
+#define TEXTFORMATTING_H
+
+#include "TextUtil.h"
+#include "Runtime/Math/Rect.h"
+
+enum {
+ kStyleDefault = 0,
+ kStyleFlagBold = 1 << 0,
+ kStyleFlagItalic = 1 << 1,
+};
+
+struct TextFormat
+{
+ int style;
+ ColorRGBA32 color;
+ int size;
+ int material;
+ Rectf imageRect;
+
+ TextFormat () :
+ style(0),
+ color(0xff,0xff,0xff,0xff),
+ size(0),
+ material(0),
+ imageRect(0,0,1,1)
+ {
+ }
+};
+
+enum FormatFlags {
+ kFormatBold = 1 << 0,
+ kFormatItalic = 1 << 1,
+ kFormatColor = 1 << 2,
+ kFormatSize = 1 << 3,
+ kFormatMaterial = 1 << 4,
+ kFormatImage = 1 << 5,
+ kFormatPop = 1 << 15,
+};
+
+struct TextFormatChange
+{
+ int startPosition;
+ int skipCharacters;
+ TextFormat format;
+ int flags;
+};
+
+class FormatStack : std::vector<TextFormat>
+{
+public:
+ FormatStack (ColorRGBA32 _color, int _size, int _style)
+ {
+ push_back (TextFormat());
+ back().color = _color;
+ back().size = _size;
+ back().style = _style;
+ }
+
+ void PushFormat (TextFormatChange &change)
+ {
+ if (change.flags & kFormatPop)
+ pop_back();
+ else
+ {
+ push_back(back());
+ if (change.flags & kFormatBold)
+ back().style |= kStyleFlagBold;
+ if (change.flags & kFormatItalic)
+ back().style |= kStyleFlagItalic;
+ if (change.flags & kFormatColor)
+ back().color = change.format.color;
+ if (change.flags & kFormatSize)
+ back().size = change.format.size;
+ if (change.flags & kFormatMaterial)
+ back().material = change.format.material;
+ }
+ }
+
+ TextFormat& Current() { return back(); }
+};
+
+void GetFormatString (UTF16String& input, std::vector<TextFormatChange> &format);
+
+#endif \ No newline at end of file