YSTest: Hover.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

Hover.h
浏览该文件的文档.
1 /*
2 © 2013-2020 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 // for ystdex::invoke, function;
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 ystdex::invoke(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 = function<Point(const CursorEventArgs&)>;
115
116 Locator Locate{DefaultLocate};
117
118 private:
119 Timers::Timer tmr;
120 HoverCursorState state = Outside;
121
122 public:
123 Point Position{Point::Invalid};
124
125 TimedHoverState(Locator loc = DefaultLocate,
126 Timers::Duration d = GetDefaultDuration())
127 : Locate(loc), tmr(d, {})
128 {}
129
130 DefGetter(const ynothrow, HoverCursorState, State, state)
131
132 bool
133 Check() ynothrow;
134
136 static yconstfn DefGetter(ynothrow, Timers::Duration, DefaultDuration,
137 Timers::TimeSpan(yimpl(400U)))
138
143 YB_ATTR_nodiscard YB_PURE static Point
144 DefaultLocate(const CursorEventArgs&) ynothrow;
145
146 PDefH(bool, CheckShow, CursorEventArgs& e) ynothrow
147 ImplRet(e.Strategy == RoutedEventArgs::Direct && Check())
148
149 PDefH(bool, CheckHide, CursorEventArgs& e) ynothrow
150 ImplRet(e.Strategy == RoutedEventArgs::Direct && Update(e.Position))
151
152 void
153 Leave() ynothrow;
154
159 static Point
160 LocateForOffset(const CursorEventArgs&, const Point&);
161
162 PDefH(void, Reset, ) ynothrow
163 ImplExpr(state = Outside)
164
165 bool
166 Update(const Point& pt) ynothrow;
167 };
168
169 } // namespace UI;
170
171 } // namespace YSLib;
172
173 #endif
174
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
DefPred
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:232
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
ystdex::lref
左值引用包装。
Definition: ref.hpp:61
ystdex::invoke
invoke_result_t< _fCallable, _tParams... > invoke(_fCallable &&f, _tParams &&... args)
调用可调用对象。
Definition: invoke.hpp:538
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
YSLib::UI::HoverUpdater
悬停更新器。
Definition: Hover.h:49
YSLib::UI::PDefH
PDefH(void, DisplayFor, IWidget &wgt, Timers::TimeSpan delay) ImplExpr(Show(wgt)
在一定时间内显示部件。
YSLib::UI::Widget
部件。
Definition: YWidget.h:374
YSLib::UI::SetRendererOnHover
void SetRendererOnHover(IWidget &wgt, Widget &target, _func f)
设置悬停操作渲染器。
Definition: Hover.h:82
CHRLib::d
_tDst * d
Definition: CharacterProcessing.h:142
YSLib::Drawing::GBinaryGroup< SPos >::Invalid
static const GBinaryGroup Invalid
无效（不在屏幕坐标系中）对象。
Definition: YGDIBase.h:298
YF_API
#define YF_API
Definition: Platform.h:56
CHRLib::f
f(d, s)
YSLib::UI::args
yconstfn const string _tParams && args
Definition: Loader.h:131
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: YGDIBase.h:520
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
YSLib::UI::ActOnHover
void ActOnHover(IWidget &wgt, _func f, _tParams &&... args)
设置悬停动作。
Definition: Hover.h:69
YSLib::UI::e
void e
Definition: YWidget.h:356
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YModules.h
YSLib 用户界面模块配置文件。
YSLib::UI::wgt
IWidget & wgt
Definition: YControl.h:113
YSLib::UI::CursorState::Over
@ Over
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
YSLib::UI::HoverUpdater::Widget
lref< IWidget > Widget
Definition: Hover.h:55
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::UI::ImplExpr
IWidget bool b ImplExpr(wgt.GetController().SetEnabled(b)) YF_API bool Enable(IWidget &
设置部件可用性，且当可用性改变时无效化部件区域。
YSLib::UI::CursorState::Outside
@ Outside
YSLib::UI::Leave
@ Leave
控件离开。
Definition: YWidgetEvent.h:441
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
YSLib::Timers::TimeSpan
std::chrono::duration< Duration::rep, std::milli > TimeSpan
低精度时间间隔。
Definition: YClock.h:81
YSLib::Timers::Duration
HighResolutionClock::duration Duration
高精度时间间隔。
Definition: YClock.h:68
YSLib::UI::FetchGUIState
GUIState & FetchGUIState() ynothrow
Definition: YGUI.cpp:506
NPL::get
PDefH(void, LiftTermRef, TermNode &term, const TermNode &tm) ImplExpr(NPL ref get()
Definition: NPLA.h:1737
ystdex::ref
void ref(const _type &&)=delete
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) YB_ATTR_nodiscard YB_PURE bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
platform_ex::Reset
unsigned long Reset(COMPtr< _iCOM > &ptr) ynothrow
Definition: Win32/include/YCLib/COM.h:406
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073