YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
label.h
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2011 - 2013.
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 "ywidget.h"
32 //#include "../Core/yres.h"
33 #include "../Core/ystring.h"
34 #include "../Service/TextBase.h"
35 
37 
39 
40 //文本对齐样式。
41 enum class TextAlignment
42 {
43  Left = 0,
44  Up = 0,
45  Center = 1,
46  Right = 2,
47  Down = 2
48 };
49 
50 
55 class YF_API MLabel : private noncopyable
56 {
57 public:
60 
65  TextAlignment HorizontalAlignment, VerticalAlignment;
71 // bool AutoSize; //!< 启用根据字号自动调整大小。
72 // bool AutoEllipsis; //!< 启用对超出标签宽度的文本调整大小。
73  String Text;
74 
75 protected:
80  explicit
82  inline DefDeMoveCtor(MLabel)
83 
84 
88  void
89  DrawText(const Size&, Color, const PaintContext&);
90 };
91 
92 
94 class YF_API Label : public Widget, protected MLabel
95 {
96 public:
97  using MLabel::Font;
98  using MLabel::Margin;
99  using MLabel::HorizontalAlignment;
100  using MLabel::VerticalAlignment;
102  using MLabel::AutoWrapLine;
103  using MLabel::Text;
104 /*
105  YImage BackgroundImage; //!< 背景图像。
106  YImage Image; //!< 前景图像。
107 */
108 
113  explicit
114  Label(const Rect& r = {}, const Drawing::Font& fnt = {})
115  : Widget(r), MLabel(fnt)
116  {}
117  inline DefDeMoveCtor(Label)
118 
119 
123  void
124  Refresh(PaintEventArgs&&) override;
125 };
126 
127 
132 class YF_API MTextList : public MLabel
133 {
134 public:
135  typedef String ItemType;
136  typedef vector<ItemType> ListType;
137  typedef typename ListType::size_type IndexType;
138 
139 protected:
140  mutable shared_ptr<ListType> hList;
141 
146 
147 protected:
153  explicit
154  MTextList(const shared_ptr<ListType>& = {}, const Drawing::Font& = {});
155  inline DefDeMoveCtor(MTextList)
156 
157  //void
158  //PaintTextList(Widget&, const Point&);
159 
160 public:
165  DefGetter(const ynothrow, const ListType&, List, *hList)
170  DefGetter(ynothrow, ListType&, ListRef, *hList)
175  ItemType*
176  GetItemPtr(const IndexType&);
181  const ItemType*
182  GetItemPtr(const IndexType&) const;
187  DefGetter(const ynothrow, SDst, ItemHeight,
189 
194  SDst
195  GetMaxTextWidth() const;
196 
202  void
203  SetList(const shared_ptr<ListType>& h)
204  {
205  if(YB_LIKELY(h))
206  hList = h;
207  }
208 
214  IndexType
215  Find(const ItemType&) const;
216 
220  void
221  RefreshTextState();
222 };
223 
225 
226 YSL_END
227 
228 #endif
229