YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
label.cpp
浏览该文件的文档.
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 #include "YSLib/UI/YModules.h"
29 #include YFM_YSLib_UI_Label
30 #include YFM_YSLib_Service_TextLayout
31 #include YFM_YSLib_UI_YWidgetEvent
32 
33 namespace YSLib
34 {
35 
36 namespace UI
37 {
38 
40  : Font(fnt), Margin(Drawing::DefaultMargin),
41  HorizontalAlignment(a), VerticalAlignment(TextAlignment::Center),
42  AutoWrapLine(false), /*AutoSize(false), AutoEllipsis(false),*/ Text()
43 {}
44 
45 void
46 MLabel::DrawText(const Size& s, Color c, const PaintContext& e)
47 {
49  const Rect bounds(e.Location, s);
50 
51  yunseq(ts.Font = Font, ts.Color = c,
52  ts.Margin = FetchMargin(bounds + Margin, e.Target.GetSize())),
53  ts.ResetPen(e.Location, Margin);
54 
55  if(!AutoWrapLine)
56  {
57  switch(HorizontalAlignment)
58  {
61  {
62  SPos horizontal_offset(bounds.Width - GetHorizontalOf(Margin)
63  - FetchStringWidth(ts.Font, Text));
64 
65  if(horizontal_offset > 0)
66  {
68  horizontal_offset /= 2;
69  ts.Pen.X += horizontal_offset;
70  }
71  }
73  default:
74  break;
75  }
76  switch(VerticalAlignment)
77  {
80  {
81  SPos vertical_offset(bounds.Height - GetVerticalOf(Margin)
82  - GetTextLineHeightOf(ts));
83 
84  if(vertical_offset > 0)
85  {
87  vertical_offset /= 2;
88  ts.Pen.Y += vertical_offset;
89  }
90  }
91  case TextAlignment::Up:
92  default:
93  break;
94  }
95  }
96  DrawClippedText(e.Target, e.ClipArea & (bounds + Margin), ts);
97 }
98 
99 void
101  Drawing::TextState& ts)
102 {
104 }
105 
106 
107 void
109 {
110  DrawText(GetSizeOf(*this), ForeColor, e);
111 }
112 
113 
114 MTextList::MTextList(const shared_ptr<ListType>& h, const Drawing::Font& fnt)
115  : MLabel(fnt),
116  hList(h), tsList(Font)
117 {
118  if(!hList)
119  hList = make_shared<ListType>();
120 }
121 
124 {
125  auto& lst(GetListRef());
126 
127  return IsInInterval<IndexType>(idx, lst.size()) ? &lst[idx] : nullptr;
128 }
129 const MTextList::ItemType*
130 MTextList::GetItemPtr(const IndexType& idx) const
131 {
132  const auto& lst(GetList());
133 
134  return IsInInterval<IndexType>(idx, lst.size()) ? &lst[idx] : nullptr;
135 }
136 
137 SDst
138 MTextList::GetMaxTextWidth() const
139 {
140  return FetchMaxTextWidth(Font, GetList().cbegin(), GetList().cend());
141 }
142 
144 MTextList::Find(const ItemType& text) const
145 {
146  const auto& lst(GetList());
147  const auto i(std::find(lst.begin(), lst.end(), text));
148 
149  return i != lst.end() ? i - lst.begin() : IndexType(-1);
150 }
151 
152 void
154 {
156 }
157 
158 } // namespace UI;
159 
160 } // namespace YSLib;
161 
Point Pen
笔坐标。
Definition: TextBase.h:99
typename ListType::size_type IndexType
索引类型。
Definition: label.h:149
yconstexpr Padding DefaultMargin(2, 2, 2, 2)
默认边距。
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化:使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
SDst FetchStringWidth(const Font &fnt, _tIter s)
取迭代器指定的单行字符串在字体指定、无边界限制时的显示宽度。
Definition: TextLayout.h:192
u8 LineGap
行距。
Definition: TextBase.h:100
YF_API Padding FetchMargin(const Rect &, const Size &)
取内边界相对于外边界的边距。
Definition: ygdi.cpp:51
SDst GetVerticalOf(const Padding &m)
取竖直边距和。
Definition: ygdi.h:116
SDst FetchMaxTextWidth(const Font &font, _tIter first, _tIter last)
取指定字体显示的迭代器范围中的文本的最大宽度。
Definition: TextLayout.h:318
IndexType Find(const ItemType &) const
查找项。
Definition: label.cpp:144
YF_API void DrawClippedText(const Graphics &g, const Rect &mask, TextState &ts, const String &str, bool line_wrap)
绘制剪切区域的文本。
部件绘制参数。
Definition: ywgtevt.h:276
DefDeMoveCtor(MTextList) public const ItemType * GetItemPtr(const IndexType &) const
取文本列表。
Definition: label.cpp:123
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
Padding Margin
边距:文本区域到显示区域的距离。
Definition: TextBase.h:94
String Text
标签文本。
Definition: label.h:76
const PaintContext &virtual void DrawClippedText(const Graphics &, const Rect &, Drawing::TextState &)
绘制剪切文本:使用指定的图形接口上下文、相对于部件的边界和文本状态。
Definition: label.cpp:100
YSLib 标准字符串(使用 UCS-2 作为内部编码)。
Definition: ystring.h:47
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
文本状态。
Definition: TextBase.h:87
YF_API void DrawText(const Graphics &g, TextState &ts, const String &str, bool line_wrap)
绘制文本。
MTextList(const shared_ptr< ListType > &={}, const Drawing::Font &={})
构造:使用文本列表句柄和字体指针。
Definition: label.cpp:114
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
Drawing::Font Font
字体。
Definition: TextBase.h:57
const IWidget &wgt SPos
Definition: ywidget.h:104
Drawing::Color Color
笔颜色。
Definition: TextBase.h:58
TextAlignment HorizontalAlignment
文本水平和竖直对齐属性。
Definition: label.h:68
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:58
c yconstfn g
Definition: ystyle.h:104
字体:字模,包含字型、样式和大小。
Definition: Font.h:546
Color ForeColor
默认前景色。
Definition: ywidget.h:375
virtual void Refresh(PaintEventArgs &&)
刷新:按指定参数绘制界面并更新状态。
Definition: ywidget.cpp:264
颜色。
Definition: Video.h:339
MLabel(const Drawing::Font &={}, TextAlignment=TextAlignment::Left)
构造:使用指定字体。
Definition: label.cpp:39
屏幕区域大小。
Definition: ygdibase.h:249
void RefreshTextState()
刷新文本状态。
Definition: label.cpp:153
TextAlignment VerticalAlignment
Definition: label.h:68
PDefHOp(TextState &,=, const PenStyle &ps) ImplRet(PenStyle void ResetPen()
赋值:笔样式。
Definition: TextBase.h:145