YSTest: Hover.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

Hover.h
浏览该文件的文档.
1 /*
2 © 2013-2016 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_Hover_h_
29 #define YSL_INC_UI_Hover_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_UI_YControl
33 #include YFM_YSLib_UI_YGUI
34
35 namespace YSLib
36 {
37
38 namespace UI
39 {
40
48 class YF_API HoverUpdater
49 {
50 private:
51 bool entered = {};
52
53 public:
55 lref<IWidget> Widget;
56
57 HoverUpdater(IWidget&);
58
59 DefPred(const ynothrow, Entered, entered)
60 };
61
62
67 template<typename _func, typename... _tParams>
68 void
69 ActOnHover(IWidget& wgt, _func f, _tParams&&... args)
70 {
71 if(FetchGUIState().GetIndependentFocusPtr().get() != &wgt)
72 f(yforward(args)...);
73 }
74
80 template<typename _func>
81 inline void
82 SetRendererOnHover(IWidget& wgt, Widget& target, _func f)
83 {
84 UI::ActOnHover(wgt, std::bind(&Widget::SetRenderer, std::ref(target),
85 std::bind(f)));
86 }
87 inline PDefH(void, SetRendererOnHover, IWidget& wgt, Widget& target)
88 ImplExpr(UI::SetRendererOnHover(wgt, target, make_unique<Renderer>))
90
91
92
96 class YF_API TimedHoverState
97 {
98 public:
103 enum HoverCursorState : yimpl(size_t)
104 {
105 Outside = 0,
106 Over,
107 Left
108 };
114 using Locator = std::function<Point(const CursorEventArgs&)>;
115
116 static yconstexpr const Timers::Duration
117 DefaultDuration{Timers::TimeSpan(400U)};
118 Locator Locate{DefaultLocate};
119
120 private:
121 Timers::Timer tmr;
122 HoverCursorState state = Outside;
123
124 public:
125 Point Position{Point::Invalid};
126
127 TimedHoverState(Locator loc = DefaultLocate,
128 Timers::Duration d = DefaultDuration)
129 : Locate(loc), tmr(d, {})
130 {}
131
132 DefGetter(const ynothrow, HoverCursorState, State, state)
133
134 bool
135 Check() ynothrow;
136
141 static Point
142 DefaultLocate(const CursorEventArgs&) ynothrow;
143
144 PDefH(bool, CheckShow, CursorEventArgs& e) ynothrow
145 ImplRet(e.Strategy == RoutedEventArgs::Direct && Check())
146
147 PDefH(bool, CheckHide, CursorEventArgs& e) ynothrow
148 ImplRet(e.Strategy == RoutedEventArgs::Direct && Update(e.Position))
149
150 void
151 Leave() ynothrow;
152
157 static Point
158 LocateForOffset(const CursorEventArgs&, const Point&);
159
160 PDefH(void, Reset, ) ynothrow
161 ImplExpr(state = Outside)
162
163 bool
164 Update(const Point& pt) ynothrow;
165 };
166
167 } // namespace UI;
168
169 } // namespace YSLib;
170
171 #endif
172
YSLib::UI::ImplExpr
IWidget bool b ImplExpr(wgt.GetController().SetEnabled(b)) YF_API bool Enable(IWidget &
设置部件可用性，且当可用性改变时无效化部件区域。
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
YSLib::UI::FetchGUIState
GUIState & FetchGUIState() ynothrow
Definition: YGUI.cpp:508
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
YSLib::UI::args
yconstfn const string _tParams && args
Definition: Loader.h:131
YSLib::UI::HoverUpdater::Widget
lref< IWidget > Widget
Definition: Hover.h:55
CHRLib::d
_tDst * d
Definition: CharacterProcessing.h:139
YSLib::Timers::Duration
HighResolutionClock::duration Duration
高精度时间间隔。
Definition: YClock.h:68
YSLib::UI::CursorState::Over
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:240
ystdex::lref
左值引用包装。
Definition: ref.hpp:74
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
platform_ex::Reset
unsigned long Reset(COMPtr< _iCOM > &ptr) ynothrow
Definition: COM.h:408
YSLib::Timers::TimeSpan
std::chrono::duration< Duration::rep, std::milli > TimeSpan
低精度时间间隔。
Definition: YClock.h:81
YSLib::UI::Leave
控件离开。
Definition: YWidgetEvent.h:424
YSLib::UI::wgt
IWidget & wgt
Definition: YControl.h:112
UI
YSLib::UI::CursorState::Outside
YSLib::Drawing::GBinaryGroup< SPos >::Invalid
static const GBinaryGroup Invalid
无效（不在屏幕坐标系中）对象。
Definition: YGDIBase.h:58
YSLib::UI::SetRendererOnHover
void SetRendererOnHover(IWidget &wgt, Widget &target, _func f)
设置悬停操作渲染器。
Definition: Hover.h:82
YSLib::UI::e
void e
Definition: YWidget.h:352
YModules.h
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: YGDIBase.h:278
YSLib::UI::Widget
部件。
Definition: YWidget.h:369
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:969
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::UI::bool
IWidget bool b bool
Definition: YControl.h:121
YSLib::IO::f
const string &path const String &path _func f
Definition: YSLib/Service/FileSystem.h:430
DefPred
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:231
YSLib::UI::ActOnHover
void ActOnHover(IWidget &wgt, _func f, _tParams &&...args)
设置悬停动作。
Definition: Hover.h:69
YSLib::UI::PDefH
PDefH(void, DisplayFor, IWidget &wgt, Timers::TimeSpan delay) ImplExpr(Show(wgt)
在一定时间内显示部件。
ystdex::ref
lref< _type > ref(_type &t)
构造引用包装。
Definition: ref.hpp:120
YSLib::UI::HoverUpdater
悬停更新器。
Definition: Hover.h:48