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(RefPtr<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 SetLineSpacing(float line_spacing);
100
103 enum class DirtyFlag : uint8_t
104 {
105 Clean = 0,
106 Dirty = 1 << 0
107 };
108
111 DirtyFlag GetDirtyFlag() const;
112
115 void SetDirtyFlag(DirtyFlag flag);
116
120 bool UpdateIfDirty();
121
122private:
123 DirtyFlag dirty_flag_;
124 uint32_t line_count_;
125 uint32_t content_length_;
126 Size size_;
127};
128
131inline bool TextLayout::IsDirty() const
132{
133 return dirty_flag_ != DirtyFlag::Clean;
134}
135
136inline uint32_t TextLayout::GetContentLength() const
137{
138 return content_length_;
139}
140
142{
143 return dirty_flag_;
144}
145
147{
148 dirty_flag_ = flag;
149}
150
151} // namespace kiwano
含有本地指针的对象
Definition: NativeObject.hpp:32
引用计数智能指针
Definition: RefBasePtr.hpp:35
文本布局
Definition: TextLayout.h:37
void SetDirtyFlag(DirtyFlag flag)
设置脏布局标志
Definition: TextLayout.h:146
DirtyFlag
脏布局标志
Definition: TextLayout.h:104
uint32_t GetContentLength() const
获取文本长度
Definition: TextLayout.h:136
bool IsDirty() const
文本布局是否陈旧
Definition: TextLayout.h:131
DirtyFlag GetDirtyFlag() const
获取脏布局标志
Definition: TextLayout.h:141
文本样式
Definition: TextStyle.h:51
TextAlign
文本对齐方式
Definition: TextStyle.h:39