29 #include YFM_YSLib_UI_TextBox
30 #include YFM_YSLib_UI_Border
31 #include YFM_YSLib_UI_YGUI
32 #include YFM_YSLib_Service_TextLayout
33 #include YFM_YSLib_UI_YUIContainer // for LocateForWidget;
46 : CaretBrush(caret_brush), CursorInvalidator(inv)
50 if(
Check(e.GetSender()))
58 FetchEvent<LostFocus>(
wgt) += [
this]{
91 const pair<Color, Color>& hilight_pair)
93 Selection(), CursorCaret(*this, std::bind(&
TextBox::PaintDefaultCaret, this,
94 std::placeholders::_1), InvalidateDefaultCaret), h_offset()
100 using namespace KeyCategory;
101 using namespace KeyCodes;
102 const auto& k(e.GetKeys());
103 const char c(FetchGUIState().UpdateChar(e.Keys));
104 auto& sender(e.GetSender());
109 const ucs2_t buf[]{ucs2_t(c), u
'\0'};
111 CallEvent<TextInput>(sender,
112 TextInputEventArgs(sender, String(buf), k));
113 Invalidate(e.GetSender());
119 if(ek == KeyBitsetWidth)
121 if(ek != KeyBitsetWidth)
123 const bool shifted(k[Shift]);
134 if(range.second.X == 0)
140 if(range.second.X >=
Text.length())
153 if(range.second.X == 0)
161 if(range.second.X >=
Text.length())
169 range.second.X = (ek ==
Left) == (range.first.X
170 < range.second.X) ? range.first.X : range.second.X;
183 Selection.Range.second = GetCaretPosition(e.Position);
184 Selection.Collapse();
189 const auto& sender(e.GetSender());
191 Selection.Range.second = GetCaretPosition(&sender ==
this
197 FetchEvent<TextInput>(*this) += [
this](TextInputEventArgs&& e){
198 ReplaceSelection(e.Text);
201 FetchEvent<GotFocus>(*this) += [
this]{
204 FetchEvent<LostFocus>(*this) += [
this]{
205 Selection.Collapse();
212 TextBox::GetCaretPosition(
const Point& pt)
220 return {pr.first, 0};
237 const auto q1(p + x1), q2(p + x2);
264 auto& tb(ystdex::polymorphic_downcast<TextBox&>(wgt));
266 const auto lh(tb.Font.GetHeight());
267 const auto& cur_pos(tb.Selection.Range.second);
270 const auto y(cur_pos.Y * lh + inner_bounds.
X);
282 if(
r.second.X <
r.first.X)
285 +
Text.substr(min(
Text.length(),
r.second.X));
286 r.second.X =
r.first.X + text.length(),
295 const auto mask(
FetchMargin(inner_bounds, e.Target.GetSize()));
300 cur_pos.Y * lh + lh + mask.Top,
ForeColor);
void DrawVLineSeg(const Graphics &g, const Rect &bounds, SPos x, SPos y1, SPos y2, Color c)
描画竖直线段。
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化:使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
SDst FetchStringWidth(const Font &fnt, _tIter s)
取迭代器指定的单行字符串在字体指定、无边界限制时的显示宽度。
YF_API void OnKeyHeld(KeyEventArgs &&)
处理键接触保持事件。
void Refresh(PaintEventArgs &&) override
刷新:按指定参数绘制界面并更新状态。
GBinaryGroup< size_t > Position
位置:横坐标和纵坐标。
pair< size_t, SDst > FetchStringOffsets(size_t max_width, const Font &fnt, _tIter s)
取迭代器指定的单行字符串在指定字体和宽度时的最多能显示的字符数和宽。
YF_API Padding FetchMargin(const Rect &, const Size &)
取内边界相对于外边界的边距。
YF_API GUIState & FetchGUIState()
取默认图形用户界面公共状态。
SDst GetVerticalOf(const Padding &m)
取竖直边距和。
YF_API void FillRect(const Graphics &g, const Rect &, Color c)
填充标准矩形。
YF_API void Invalidate(IWidget &, const Rect &)
无效化:使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Color HilightTextColor
高亮文本色。
Timers::Timer CaretTimer
决定是否显示插入符的计时器。
TextSelection Selection
选择区域:结束位置指示插入符光标逻辑位置。
HBrush CaretBrush
插入符画刷。 484
表示编辑键(如回车、空格、退格、插入、删除和制表符)
Duration RefreshRemainder()
刷新:对于非零时间间隔判断有效性并都更新时间基点。
std::uint16_t SDst
屏幕坐标距离。
InvalidationUpdater::Invalidator CursorInvalidator
供闪烁动画使用的指定无效化区域的光标位置刷新器。
_fCallable void Restart(_tAnimation &ani, IWidget &wgt, _fCallable f)
Color HilightBackColor
高亮背景色。
Duration Interval
重复刷新有效的最小时间间隔。
定制文本渲染器:使用自定义的渲染函数替代的 TextRenderer 。
YF_API bool IsFocusedCascade(const IWidget &, const IWidget *={})
判断部件相对于指针指定的部件是否具有级联焦点。
void PaintDefaultCaret(PaintEventArgs &&)
绘制默认插入符。
void swap(any &x, any &y)
交换对象。
const PaintContext &virtual void DrawClippedText(const Graphics &, const Rect &, Drawing::TextState &)
绘制剪切文本:使用指定的图形接口上下文、相对于部件的边界和文本状态。
YF_API SDst FetchCharWidth(const Font &, ucs4_t)
取指定的字符使用指定字体的显示宽度。
YSLib 标准字符串(使用 UCS-2 作为内部编码)。
YF_API void InvalidateVisible(IWidget &, const Rect &)
无效化:使相对于可见的部件的指定区域在直接和间接的窗口缓冲区中无效。
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
#define yunseq
无序列依赖表达式组求值。
YF_API void DrawText(const Graphics &g, TextState &ts, const String &str, bool line_wrap)
绘制文本。
TextBox(const Rect &={}, const Drawing::Font &={}, const pair< Drawing::Color, Drawing::Color > &=FetchGUIState().Colors.GetPair(Styles::Highlight, Styles::HighlightText))
构造:使用指定边界、字体和高亮背景色/文本色对。
Caret(IWidget &, HBrush, InvalidationUpdater::Invalidator)
构造:注册插入符光标动画的事件处理器和画刷。
std::function< void(PaintEventArgs &&)> HBrush
画刷回调函数。
YF_API Point LocateForWidget(const IWidget &, const IWidget &)
取第二参数指定的部件相对于第一参数指定的部件的偏移坐标。
static void Stop()
停止插入符光标动画。
bool Check(IWidget &)
检查是否需要对指定部件进行绘制。
static bool InvalidateDefaultCaret(IWidget &)
无效化默认插入符。
bool IsEnabled(const IWidget &wgt)
判断部件是否为可用的控件。
Drawing::Padding Margin
文本和容器的间距。
SDst h_offset
文字区域水平基准负偏移:文本内容在光标回退方向超出的未显示部分大小。
void ReplaceSelection(const String &)
替换选中文本。
DefDeMoveCtor(TextBox) TextSelection void DrawClippedText(const Graphics &, const Rect &, TextState &) override
取指定点所在的插入符光标逻辑位置。
std::function< bool(IWidget &)> Invalidator
YF_API KeyIndex FindFirstKeyInCategroy(const KeyInput &, KeyIndex) ynothrow
找到第一个在指定类别的按键编码。
char32_t ucs4_t
UCS-4 字符类型。
void PutText(bool multi, _tParams &&...args)
打印文本。
表示导航键(如方向键和 PgUp )、菜单键和 Esc 。
FontSize GetHeight() const ynothrow
取字体对应的字符高度。
bool IsInInterval(_type i, _type b) ynothrow
判断 i 是否在左闭右开区间 [FetchZero<_type>(), b) 中。
static GAnimationSession< InvalidationUpdater > caret_animation
插入符闪烁动画。
#define YAssert(_expr, _msg)
yconstexpr EventPriority BackgroundPriority(0xC0)
用户界面绘制优先级。