YSTest: Label.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

Label.h
浏览该文件的文档.
1 /*
2 © 2011-2015, 2020 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YSL_INC_UI_Label_h_
29 #define YSL_INC_UI_Label_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_UI_YWidget
33 //#include YFM_YSLib_Service_YResource
34 #include YFM_YSLib_Core_YString
35 #include YFM_YSLib_Service_TextBase
36 #include YFM_YSLib_Service_YBrush
37
38 namespace YSLib
39 {
40
41 namespace UI
42 {
43
44 //文本对齐样式。
45 enum class TextAlignment
46 {
47 Left = 0,
48 Up = 0,
49 Center = 1,
50 Right = 2,
51 Down = 2
52 };
53
54
61 class YF_API MLabel
62 {
63 public:
70 Drawing::GBrushUpdater<Drawing::TextState&, const String&, bool>
71 UpdateClippedText{DefaultUpdateClippedText};
72
77 Color ForeColor{Drawing::ColorSpace::Black};
78 Drawing::Font Font;
79 Drawing::Padding Margin{Drawing::DefaultMargin};
80
85 TextAlignment HorizontalAlignment,
86 VerticalAlignment = TextAlignment::Center;
91 bool AutoWrapLine = {};
92 // bool AutoSize; //!< 启用根据字号自动调整大小。
93 // bool AutoEllipsis; //!< 启用对超出标签宽度的文本调整大小。
94 String Text{};
95
100 explicit
101 MLabel(const Drawing::Font& = {}, Color = Drawing::ColorSpace::Black,
102 TextAlignment = TextAlignment::Left);
103
108 void
109 operator()(PaintEventArgs&&) const;
110
115 YB_ATTR_nodiscard YB_PURE Point
116 GetAlignedPenOffset(const Size&) const;
118 DefGetter(const ynothrow, SDst, ItemHeight,
119 Font.GetHeight() + GetVerticalOf(Margin))
120
121
127 void
128 DrawText(const Size&, const PaintContext&) const;
129
134 static void
135 DefaultUpdateClippedText(const PaintContext&, Drawing::TextState&,
136 const String&, bool);
138 };
139
140
142 class YF_API Label : public Widget, protected MLabel
143 {
144 public:
146 using MLabel::ForeColor;
147 using MLabel::Font;
148 using MLabel::Margin;
149 using MLabel::HorizontalAlignment;
150 using MLabel::VerticalAlignment;
152 using MLabel::AutoWrapLine;
153 using MLabel::Text;
154
159 explicit
160 Label(const Rect& r = {}, const Drawing::Font& fnt = {},
161 HBrush b = MakeBlankBrush(), Color c = Drawing::ColorSpace::Black)
162 : Widget(r, b), MLabel(fnt, c)
163 {}
164
166 using MLabel::GetAlignedPenOffset;
168 using MLabel::GetItemHeight;
169
175 static Rect
176 CalculateBounds(const String&, Rect, const Drawing::Font&,
177 const Drawing::Padding& = {});
178
183 void
184 Refresh(PaintEventArgs&&) override;
185 };
186
193 YF_API unique_ptr<Label>
195 MakeLabel(const String&, const Rect& = Rect::Invalid, const Drawing::Font& = {},
196 const Drawing::Padding& = Drawing::DefaultMargin * 2);
197
199 YF_API void
200 SetupContentsOf(Label&, const String&, const Rect& = Rect::Invalid, const
201 Drawing::Font& = {}, const Drawing::Padding& = Drawing::DefaultMargin * 2);
203
204
211 class YF_API MHilightText
212 {
213 public:
215 Color HilightBackColor;
217 Color HilightTextColor;
218
219 MHilightText(const Color& bc, const Color& fc)
220 : HilightBackColor(bc), HilightTextColor(fc)
221 {}
222 template<class _type>
223 MHilightText(const _type& pr)
224 : MHilightText(get<0>(pr), get<1>(pr))
225 {}
226 };
227
228 } // namespace UI;
229
230 } // namespace YSLib;
231
232 #endif
233
YSLib::UI::TextAlignment::Down
@ Down
YSLib::UI::MHilightText::MHilightText
MHilightText(const _type &pr)
Definition: Label.h:223
YSLib::Drawing::TextState
文本状态。
Definition: TextBase.h:87
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
YSLib::UI::MLabel::HorizontalAlignment
TextAlignment HorizontalAlignment
文本水平和竖直对齐属性。
Definition: Label.h:85
YSLib::UI::MHilightText::HilightTextColor
Color HilightTextColor
高亮文本色。
Definition: Label.h:217
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:536
YSLib::Drawing::Rect::Invalid
static const Rect Invalid
无效对象。
Definition: YGDIBase.h:794
CHRLib::c
c
Definition: CharacterProcessing.h:84
YSLib::UI::MHilightText::HilightBackColor
Color HilightBackColor
高亮背景色。
Definition: Label.h:215
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
ystdex::function_base
函数包装类模板。
Definition: function.hpp:578
YSLib::UI::Widget
部件。
Definition: YWidget.h:374
YSLib::UI::MLabel::VerticalAlignment
TextAlignment VerticalAlignment
Definition: Label.h:86
YSLib::UI::fc
fc
Definition: Console.h:93
YSLib::UI::Label::Label
Label(const Rect &r={}, const Drawing::Font &fnt={}, HBrush b=MakeBlankBrush(), Color c=Drawing::ColorSpace::Black)
构造：使用指定边界、字体、背景画刷和文字颜色。
Definition: Label.h:160
YSLib::UI::Label
标签。
Definition: Label.h:143
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::UI::TextAlignment::Up
@ Up
YSLib::UI::MLabel::AutoWrapLine
bool AutoWrapLine
启用自动换行。
Definition: Label.h:91
YSLib::UI::MHilightText::MHilightText
MHilightText(const Color &bc, const Color &fc)
Definition: Label.h:219
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: YString.h:47
YSLib::UI::MLabel::Font
Drawing::Font Font
字体。
Definition: Label.h:78
YSLib::UI::TextAlignment::Center
@ Center
YSLib::Drawing::Padding
空白样式。
Definition: YGDI.h:47
YSLib::GHEvent
标准事件处理器模板。
Definition: YEvent.hpp:59
YSLib::UI::MakeLabel
unique_ptr< Label > MakeLabel(const String &text, const Rect &r, const Font &fnt, const Padding &m)
Definition: Label.cpp:143
YSLib::Drawing::GBinaryGroup< SPos >
YSLib::Drawing::ColorSpace::Black
@ Black
Definition: YGDIBase.h:262
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::UI::MLabel::ForeColor
Color ForeColor
默认前景色。
Definition: Label.h:77
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
Color
Pixel Color
Definition: CharRenderer.cpp:59
YSLib::UI::MLabel
标签模块。
Definition: Label.h:62
YModules.h
YSLib 用户界面模块配置文件。
YSLib::UI::MLabel::Margin
Drawing::Padding Margin
文本和容器的间距。
Definition: Label.h:79
YSLib::UI::SetupContentsOf
YF_API void SetupContentsOf(Label &, const String &, const Rect &=Rect::Invalid, const Drawing::Font &={}, const Drawing::Padding &=Drawing::DefaultMargin *2)
设置指定字符串、初始边界、字体和边距的单行文本需要的标签。
Definition: Label.cpp:153
YSLib::Drawing::DrawText
YF_API void DrawText(const Graphics &g, TextState &ts, const String &str, bool line_wrap)
绘制文本。
Definition: TextRenderer.cpp:246
YSLib::UI::TextAlignment::Left
@ Left
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:330
YSLib::UI::MHilightText
高亮文本模块。
Definition: Label.h:212
YSLib::UI::TextAlignment::Right
@ Right
YSLib::UI::MLabel::Text
String Text
标签文本。
Definition: Label.h:94
YSLib::Drawing::GetVerticalOf
YB_ATTR_nodiscard YB_PURE const Padding &m ynothrowv GetVerticalOf
Definition: YGDI.h:151
YSLib::Drawing::Font
字体：字模，包含字型、样式和大小。
Definition: Font.h:589
YSLib::Drawing::DefaultMargin
yconstexpr const Padding DefaultMargin(2, 2, 2, 2)
默认边距。
YSLib::Drawing::Font::GetHeight
YB_ATTR_nodiscard YB_PURE FontSize GetHeight() const ynothrow
取字体对应的字符高度。
Definition: Font.cpp:541
YSLib::UI::TextAlignment
TextAlignment
Definition: Label.h:46
YSLib::UI::MLabel::DefGetter
DefGetter(const ynothrow, SDst, ItemHeight, Font.GetHeight()+GetVerticalOf(Margin)) void DrawText(const Size &
绘制文本。
NPL::get
PDefH(void, LiftTermRef, TermNode &term, const TermNode &tm) ImplExpr(NPL ref get()
Definition: NPLA.h:1737
YSLib::UI::MLabel::GetAlignedPenOffset
YB_ATTR_nodiscard YB_PURE Point GetAlignedPenOffset(const Size &) const
按参数指定的边界大小和当前状态计算笔的偏移位置。
Definition: Label.cpp:52