Kiwano Engine v1.3.x
TextLayout.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/math/Math.h>
23#include <kiwano/platform/NativeObject.hpp>
24#include <kiwano/render/TextStyle.h>
25
26namespace kiwano
27{
28
36class KGE_API TextLayout : public NativeObject
37{
38public:
39 TextLayout();
40
45 TextLayout(StringView content, const TextStyle& style);
46
49 bool IsDirty() const;
50
53 void Clear();
54
59 void Reset(StringView content, const TextStyle& style);
60
63 Size GetSize() const;
64
67 uint32_t GetLineCount() const;
68
71 uint32_t GetContentLength() const;
72
76 void SetFont(const Font& font);
77
81 void SetUnderline(bool enable);
82
86 void SetStrikethrough(bool enable);
87
91 void SetAlignment(TextAlign align);
92
95 void SetWrapWidth(float wrap_width);
96
99 void SetWordWrapping(TextWordWrapping word_wrapping);
100
103 void SetLineSpacing(float line_spacing);
104
107 enum class DirtyFlag : uint8_t
108 {
109 Clean = 0,
110 Dirty = 1 << 0
111 };
112
115 DirtyFlag GetDirtyFlag() const;
116
119 void SetDirtyFlag(DirtyFlag flag);
120
124 bool UpdateIfDirty();
125
126private:
127 DirtyFlag dirty_flag_;
128 uint32_t line_count_;
129 uint32_t content_length_;
130 Size size_;
131};
132
135inline bool TextLayout::IsDirty() const
136{
137 return dirty_flag_ != DirtyFlag::Clean;
138}
139
140inline uint32_t TextLayout::GetContentLength() const
141{
142 return content_length_;
143}
144
146{
147 return dirty_flag_;
148}
149
151{
152 dirty_flag_ = flag;
153}
154
155} // namespace kiwano
字体
Definition: Font.h:112
含有本地指针的对象
Definition: NativeObject.hpp:32
文本布局
Definition: TextLayout.h:37
void SetDirtyFlag(DirtyFlag flag)
设置脏布局标志
Definition: TextLayout.h:150
DirtyFlag
脏布局标志
Definition: TextLayout.h:108
uint32_t GetContentLength() const
获取文本长度
Definition: TextLayout.h:140
bool IsDirty() const
文本布局是否陈旧
Definition: TextLayout.h:135
DirtyFlag GetDirtyFlag() const
获取脏布局标志
Definition: TextLayout.h:145
文本样式
Definition: TextStyle.h:64
TextWordWrapping
换行方式
Definition: TextStyle.h:51
TextAlign
文本对齐方式
Definition: TextStyle.h:39