YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
label.h
浏览该文件的文档.
1 /*
2  © 2011-2014 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 
37 namespace YSLib
38 {
39 
40 namespace UI
41 {
42 
43 //文本对齐样式。
44 enum class TextAlignment
45 {
46  Left = 0,
47  Up = 0,
48  Center = 1,
49  Right = 2,
50  Down = 2
51 };
52 
53 
58 class YF_API MLabel : private noncopyable
59 {
60 public:
63 
68  TextAlignment HorizontalAlignment, VerticalAlignment;
74 // bool AutoSize; //!< 启用根据字号自动调整大小。
75 // bool AutoEllipsis; //!< 启用对超出标签宽度的文本调整大小。
77 
79 
80  explicit
84  virtual DefDeDtor(MLabel)
85 
90  void
91  DrawText(const Size&, Color, const PaintContext&);
92 
97  virtual void
98  DrawClippedText(const Graphics&, const Rect&, Drawing::TextState&);
100 };
101 
102 
104 class YF_API Label : public Widget, protected MLabel
105 {
106 public:
107  using MLabel::Font;
108  using MLabel::Margin;
112  using MLabel::AutoWrapLine;
113  using MLabel::Text;
114 /*
115  YImage BackgroundImage; //!< 背景图像。
116  YImage Image; //!< 前景图像。
117 */
118 
123  explicit
124  Label(const Rect& r = {}, const Drawing::Font& fnt = {},
125  HBrush b = MakeBlankBrush(), Color c = Drawing::ColorSpace::Black)
126  : Widget(r, b, c), MLabel(fnt)
127  {}
128  DefDeMoveCtor(Label)
129 
130 
134  void
135  Refresh(PaintEventArgs&&) override;
136 };
137 
138 
144 class YF_API MTextList : public MLabel
145 {
146 public:
147  using ItemType = String;
148  using ListType = vector<ItemType>;
149  using IndexType = typename ListType::size_type;
150 
151 protected:
152  mutable shared_ptr<ListType> hList;
153 
158 
159 protected:
165  explicit
166  MTextList(const shared_ptr<ListType>& = {}, const Drawing::Font& = {});
168 
169  //void
170  //PaintTextList(Widget&, const Point&);
171 
172 public:
177  DefGetter(const ynothrow, const ListType&, List, *hList)
182  DefGetter(ynothrow, ListType&, ListRef, *hList)
187  ItemType*
188  GetItemPtr(const IndexType&);
193  const ItemType*
194  GetItemPtr(const IndexType&) const;
199  DefGetter(const ynothrow, SDst, ItemHeight,
200  GetTextLineHeightExOf(tsList))
201 
206  SDst
207  GetMaxTextWidth() const;
208 
214  void
215  SetList(const shared_ptr<ListType>& h)
216  {
217  if(YB_LIKELY(h))
218  hList = h;
219  }
220 
226  IndexType
227  Find(const ItemType&) const;
228 
232  void
233  RefreshTextState();
234 };
235 
236 
244 {
245 public:
250 
251  MHilightText(const Color& bc, const Color& fc)
252  : HilightBackColor(bc), HilightTextColor(fc)
253  {}
254  template<class _type>
255  MHilightText(const _type& pr)
256  : MHilightText(get<0>(pr), get<1>(pr))
257  {}
258 };
259 
260 } // namespace UI;
261 
262 } // namespace YSLib;
263 
264 #endif
265 
typename ListType::size_type IndexType
索引类型。
Definition: label.h:149
void Refresh(PaintEventArgs &&) override
刷新:按指定参数绘制界面并更新状态。
文本列表模块。
Definition: label.h:144
#define DefDeDtor(_t)
定义默认析构函数。
Definition: YBaseMacro.h:146
Drawing::Font Font
字体。
Definition: label.h:61
YF_API void DrawClippedText(const Graphics &g, const Rect &mask, TextState &ts, const String &str, bool line_wrap)
绘制剪切区域的文本。
Color HilightTextColor
高亮文本色。
Definition: label.h:249
#define YF_API
Definition: Platform.h:64
GIHEvent< UIEventArgs && > ItemType
Definition: ywgtevt.h:424
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
Color HilightBackColor
高亮背景色。
Definition: label.h:247
String Text
标签文本。
Definition: label.h:76
不可复制对象:禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: utility.hpp:75
YSLib 标准字符串(使用 UCS-2 作为内部编码)。
Definition: ystring.h:47
void SetList(const shared_ptr< ListType > &)
设置文本列表。
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
文本状态。
Definition: TextBase.h:87
YF_API void DrawText(const Graphics &g, TextState &ts, const String &str, bool line_wrap)
绘制文本。
MHilightText(const Color &bc, const Color &fc)
Definition: label.h:251
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
vector< ItemType > ListType
列表类型。
Definition: label.h:148
标签。
Definition: label.h:104
TextAlignment HorizontalAlignment
文本水平和竖直对齐属性。
Definition: label.h:68
std::function< void(PaintEventArgs &&)> HBrush
画刷回调函数。
Definition: YComponent.h:104
bool AutoWrapLine
启用自动换行。
Definition: label.h:73
shared_ptr< ListType > hList
文本列表句柄。
Definition: label.h:152
二维图形接口上下文。
Definition: ygdibase.h:721
Drawing::TextState tsList
列表文本状态。
Definition: label.h:157
Drawing::Padding Margin
文本和容器的间距。
Definition: label.h:62
TextAlignment
Definition: label.h:44
高亮文本模块。
Definition: label.h:243
空白样式。
Definition: ygdi.h:46
Selected const shared_ptr< ListType > const pair< Color, Color > & DefDeMoveCtor(TextList) DefPredMem(const ynothrow
bounds & r
Definition: ydraw.h:220
标签模块。
Definition: label.h:58
#define YB_LIKELY(expr)
Definition: ydef.h:297
字体:字模,包含字型、样式和大小。
Definition: Font.h:546
Label(const Rect &r={}, const Drawing::Font &fnt={}, HBrush b=MakeBlankBrush(), Color c=Drawing::ColorSpace::Black)
构造:使用指定边界、字体、背景画刷和文字颜色。
Definition: label.h:124
颜色。
Definition: Video.h:339
屏幕区域大小。
Definition: ygdibase.h:249
部件。
Definition: ywidget.h:356
TextAlignment VerticalAlignment
Definition: label.h:68
MHilightText(const _type &pr)
Definition: label.h:255