YSTest: Label.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

Label.h
浏览该文件的文档.
1 /*
2 © 2011-2015 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 DefDeMoveCtor(MLabel)
104
105
109 void
110 operator()(PaintEventArgs&&) const;
111
116 Point
117 GetAlignedPenOffset(const Size&) const;
119 DefGetter(const ynothrow, SDst, ItemHeight,
120 Font.GetHeight() + GetVerticalOf(Margin))
121
128 void
129 DrawText(const Size&, const PaintContext&) const;
130
135 static void
136 DefaultUpdateClippedText(const PaintContext&, Drawing::TextState&,
137 const String&, bool);
139 };
140
141
143 class YF_API Label : public Widget, protected MLabel
144 {
145 public:
147 using MLabel::ForeColor;
148 using MLabel::Font;
149 using MLabel::Margin;
150 using MLabel::HorizontalAlignment;
151 using MLabel::VerticalAlignment;
153 using MLabel::AutoWrapLine;
154 using MLabel::Text;
155
160 explicit
161 Label(const Rect& r = {}, const Drawing::Font& fnt = {},
162 HBrush b = MakeBlankBrush(), Color c = Drawing::ColorSpace::Black)
163 : Widget(r, b), MLabel(fnt, c)
164 {}
165 DefDeMoveCtor(Label)
166
167
168 using MLabel::GetAlignedPenOffset;
170 using MLabel::GetItemHeight;
171
177 static Rect
178 CalculateBounds(const String&, Rect, const Drawing::Font&,
179 const Drawing::Padding& = {});
180
185 void
186 Refresh(PaintEventArgs&&) override;
187 };
188
195 YF_API unique_ptr<Label>
197 MakeLabel(const String&, const Rect& = Rect::Invalid, const Drawing::Font& = {},
198 const Drawing::Padding& = Drawing::DefaultMargin * 2);
199
201 YF_API void
202 SetupContentsOf(Label&, const String&, const Rect& = Rect::Invalid, const
203 Drawing::Font& = {}, const Drawing::Padding& = Drawing::DefaultMargin * 2);
205
206
213 class YF_API MHilightText
214 {
215 public:
217 Color HilightBackColor;
219 Color HilightTextColor;
220
221 MHilightText(const Color& bc, const Color& fc)
222 : HilightBackColor(bc), HilightTextColor(fc)
223 {}
224 template<class _type>
225 MHilightText(const _type& pr)
226 : MHilightText(get<0>(pr), get<1>(pr))
227 {}
228 };
229
230 } // namespace UI;
231
232 } // namespace YSLib;
233
234 #endif
235
YSLib::Drawing::Rect::Invalid
static const Rect Invalid
无效对象。
Definition: YGDIBase.h:548
YSLib::UI::MHilightText::MHilightText
MHilightText(const _type &pr)
Definition: Label.h:225
YSLib::UI::TextAlignment::Left
YSLib::Drawing::GetHeight
tr GetHeight())) inline PDefH(void
按字体高度和行距调整文本区域的底边距。
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
YSLib::Drawing::Font
字体：字模，包含字型、样式和大小。
Definition: Font.h:583
YSLib::UI::fc
fc
Definition: Console.h:93
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Drawing::GBrushUpdater
GHEvent< void(const PaintContext &, _types...)> GBrushUpdater
画刷更新器类型。
Definition: YBrush.h:119
YSLib::UI::MHilightText::HilightTextColor
Color HilightTextColor
高亮文本色。
Definition: Label.h:219
UI
YSLib::Drawing::DefaultMargin
yconstexpr const Padding DefaultMargin(2, 2, 2, 2)
默认边距。
YSLib::UI::MHilightText::HilightBackColor
Color HilightBackColor
高亮背景色。
Definition: Label.h:217
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
YSLib::UI::TextAlignment
TextAlignment
Definition: Label.h:45
Text
YSLib::UI::MLabel::ForeColor
Color ForeColor
默认前景色。
Definition: Label.h:77
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:167
YSLib::UI::Label
标签。
Definition: Label.h:143
Color
Pixel Color
Definition: CharRenderer.cpp:58
YSLib::UI::MLabel
标签模块。
Definition: Label.h:61
YSLib::UI::MLabel::AutoWrapLine
bool AutoWrapLine
启用自动换行。
Definition: Label.h:91
YSLib::UI::MLabel::Margin
Drawing::Padding Margin
文本和容器的间距。
Definition: Label.h:79
YSLib::UI::BorderArea::Center
YSLib::UI::Label::Label
Label(const Rect &r={}, const Drawing::Font &fnt={}, HBrush b=MakeBlankBrush(), Color c=Drawing::ColorSpace::Black)
构造：使用指定边界、字体、背景画刷和文字颜色。
Definition: Label.h:161
YSLib::UI::SetupContentsOf
void SetupContentsOf(Label &lbl, const String &text, const Rect &r, const Font &fnt, const Padding &m)
Definition: Label.cpp:153
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::UI::Widget
部件。
Definition: YWidget.h:369
YSLib::Drawing::TextState
文本状态。
Definition: TextBase.h:86
YSLib::UI::MakeLabel
unique_ptr< Label > MakeLabel(const String &text, const Rect &r, const Font &fnt, const Padding &m)
Definition: Label.cpp:143
YSLib::UI::MLabel::HorizontalAlignment
TextAlignment HorizontalAlignment
文本水平和竖直对齐属性。
Definition: Label.h:85
YSLib::UI::MHilightText::MHilightText
MHilightText(const Color &bc, const Color &fc)
Definition: Label.h:221
YSLib::UI::TextAlignment::Up
YF_API
#define YF_API
Definition: Platform.h:56
Drawing
YSLib::UI::HBrush
std::function< void(PaintEventArgs &&)> HBrush
画刷回调函数。
Definition: YComponent.h:81
YSLib::Drawing::DrawText
YF_API void DrawText(const Graphics &g, TextState &ts, const String &str, bool line_wrap)
绘制文本。
Definition: TextRenderer.cpp:247
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:323
platform::Color
颜色。
Definition: Video.h:416
YSLib::UI::TextAlignment::Right
YSLib::Drawing::GBinaryGroup< SPos >
YModules.h
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
YSLib::UI::MLabel::VerticalAlignment
TextAlignment VerticalAlignment
Definition: Label.h:86
YSLib::Drawing::Padding
空白样式。
Definition: YGDI.h:46
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::Consoles::Black
Definition: YConsole.h:53
YSLib::UI::TextAlignment::Down
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
CHRLib::c
c
Definition: CharacterProcessing.h:81
YSLib::UI::MLabel::Text
String Text
标签文本。
Definition: Label.h:94
YSLib::UI::MHilightText
高亮文本模块。
Definition: Label.h:213
YSLib::UI::MLabel::Font
Drawing::Font Font
字体。
Definition: Label.h:78
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: YString.h:46
ystdex::details::get
get())
Definition: cast.hpp:102