Kiwano Engine v1.2.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
29KGE_DECLARE_SMART_PTR(TextLayout);
30
38class KGE_API TextLayout : public NativeObject
39{
40public:
41 TextLayout();
42
47 TextLayout(const String& content, const TextStyle& style);
48
51 bool IsDirty() const;
52
55 void Clear();
56
61 void Reset(const String& content, const TextStyle& style);
62
65 Size GetSize() const;
66
69 uint32_t GetLineCount() const;
70
73 uint32_t GetContentLength() const;
74
78 void SetFont(FontPtr font);
79
83 void SetUnderline(bool enable);
84
88 void SetStrikethrough(bool enable);
89
93 void SetAlignment(TextAlign align);
94
97 void SetWrapWidth(float wrap_width);
98
101 void SetLineSpacing(float line_spacing);
102
105 enum class DirtyFlag : uint8_t
106 {
107 Clean = 0,
108 Dirty = 1 << 0
109 };
110
113 DirtyFlag GetDirtyFlag() const;
114
117 void SetDirtyFlag(DirtyFlag flag);
118
122 bool UpdateIfDirty();
123
124private:
125 DirtyFlag dirty_flag_;
126 uint32_t line_count_;
127 uint32_t content_length_;
128 Size size_;
129};
130
133inline bool TextLayout::IsDirty() const
134{
135 return dirty_flag_ != DirtyFlag::Clean;
136}
137
138inline uint32_t TextLayout::GetContentLength() const
139{
140 return content_length_;
141}
142
144{
145 return dirty_flag_;
146}
147
149{
150 dirty_flag_ = flag;
151}
152
153} // namespace kiwano
含有本地指针的对象
Definition: NativeObject.hpp:34
文本布局
Definition: TextLayout.h:39
void SetDirtyFlag(DirtyFlag flag)
设置脏布局标志
Definition: TextLayout.h:148
DirtyFlag
脏布局标志
Definition: TextLayout.h:106
uint32_t GetContentLength() const
获取文本长度
Definition: TextLayout.h:138
bool IsDirty() const
文本布局是否陈旧
Definition: TextLayout.h:133
DirtyFlag GetDirtyFlag() const
获取脏布局标志
Definition: TextLayout.h:143
文本样式
Definition: TextStyle.h:51
TextAlign
文本对齐方式
Definition: TextStyle.h:39