SimpleWindow
载入中...
搜索中...
未找到
UIElement.h
1#pragma once
2
3#include "Alignment.h"
4#include "Binding.h"
5#include "Color.h"
6#include "Cursor.h"
7#include "EnumBit.h"
8#include "EventHandlerWrapper.h"
9#include "ILayout.h"
10#include "RoutedEvent.h"
11#include "RoutedEventArgs.h"
12#include "Thickness.h"
13#include "WndBase.h"
14#include <cstdint>
15#include <unordered_map>
16#include <vector>
17
18namespace sw
19{
20 // 前向声明
21 class UIElement;
22 class ContextMenu;
23 class DataBinding;
24
30 SizeChanged = 1 << 0,
31
33 PositionChanged = 1 << 1,
34
36 ChildAdded = 1 << 2,
37
39 ChildRemoved = 1 << 3,
40
42 TextChanged = 1 << 4,
43
45 FontChanged = 1 << 5,
46
49 MeasureInvalidated = 1 << 29,
50
54 Supressed = 1 << 30,
55 };
56
60 _SW_ENUM_ENABLE_BIT_OPERATIONS(LayoutUpdateCondition);
61
65 class UIElement : public WndBase,
66 public ILayout
67 {
68 private:
72 sw::LayoutUpdateCondition _layoutUpdateCondition =
76
80 bool _collapseWhenHide = true;
81
85 Size _desireSize{};
86
90 Size _origionalSize{};
91
95 Size _minSize{-1, -1};
96
100 Size _maxSize{-1, -1};
101
105 Thickness _margin{};
106
111
115 VerticalAlignment _verticalAlignment = VerticalAlignment::Center;
116
120 UIElement *_parent = nullptr;
121
125 std::vector<UIElement *> _children{};
126
130 std::vector<UIElement *> _layoutVisibleChildren{};
131
135 std::unordered_map<RoutedEventType, RoutedEventHandler> _eventMap{};
136
140 uint64_t _layoutTag = 0;
141
145 sw::ContextMenu *_contextMenu = nullptr;
146
150 double _arrangeOffsetX = 0;
151
155 double _arrangeOffsetY = 0;
156
160 double _childRightmost = 0;
161
165 double _childBottommost = 0;
166
170 bool _float = false;
171
175 bool _tabStop = false;
176
180 Color _backColor{KnownColors::White};
181
185 Color _textColor{KnownColors::Black};
186
190 bool _transparent = false;
191
195 bool _inheritTextColor = false;
196
200 bool _useDefaultCursor = true;
201
205 HCURSOR _hCursor = NULL;
206
210 Size _lastMeasureAvailableSize{};
211
215 HDWP _hdwpChildren = NULL;
216
220 HBRUSH _hCtlColorBrush = NULL;
221
225 COLORREF _lastTextColor = 0;
226
230 COLORREF _lastBackColor = 0;
231
235 bool _isHitTestVisible = true;
236
240 bool _focusedViaTab = false;
241
245 std::unordered_map<FieldId, std::unique_ptr<BindingBase>> _bindings{};
246
247 public:
252
257
262
267
272
277
282
287
292
297
302
308
313
319
324
329
334
339
344
350
355
360
361 public:
366
370 virtual ~UIElement() = 0;
371
378 [[deprecated("Use AddHandler instead to avoid overwriting existing event handlers.")]]
380
387
395
401
407
414
421
428
435
441 bool RemoveChildAt(int index);
442
448
454
459
466
473
482 const Point &point,
485
489 void MoveToTop();
490
495
499 bool IsRootElement() const;
500
505
510
515
520
525
531
537
543
549
554
561
566 void Resize(const Size &size);
567
572
577
584
590
596
602
609
614
620
627
632
638
644
645 protected:
651
657
663
669
676
683
688
693
699
705
712
719
727
733
740
747
754
760
769
775
780
785
792
798
804
810
816 virtual bool OnMove(const Point &newClientPosition) override;
817
823 virtual bool OnSize(const Size &newClientSize) override;
824
829
835
840
847
854
861 virtual bool OnChar(wchar_t ch, const KeyFlags &flags) override;
862
870
878
885 virtual bool OnMouseMove(const Point &mousePosition, MouseKey keyState) override;
886
892
900 virtual bool OnMouseWheel(int wheelDelta, const Point &mousePosition, MouseKey keyState) override;
901
909
916 virtual bool OnMouseLeftButtonUp(const Point &mousePosition, MouseKey keyState) override;
917
925
932 virtual bool OnMouseRightButtonUp(const Point &mousePosition, MouseKey keyState) override;
933
941
949
956 virtual bool OnContextMenu(bool isKeyboardMsg, const Point &mousePosition) override;
957
963
971
981
988
995
996 private:
1002 bool _SetHorzAlignment(sw::HorizontalAlignment value);
1003
1009 bool _SetVertAlignment(sw::VerticalAlignment value);
1010
1014 void _SetMeasureInvalidated();
1015
1019 void _UpdateLayoutVisibleChildren();
1020
1025 bool _AddToLayoutVisibleChildren(UIElement *element);
1026
1030 void _RemoveFromLayoutVisibleChildren(UIElement *element);
1031
1035 static UIElement *_GetNextElement(UIElement *element);
1036
1040 static UIElement *_GetDeepestLastElement(UIElement *element);
1041
1045 static UIElement *_GetPreviousElement(UIElement *element);
1046
1047 private:
1051 template <typename T, typename = void>
1052 struct _CanAddChild : std::false_type {
1053 };
1054
1055 // 已移动到类外,防止clang报错不完整的类型
1056 // /**
1057 // * @brief _CanAddChild模板偏特化,当AddChild有对应类型的重载时该偏特化生效
1058 // */
1059 // template <typename T>
1060 // struct _CanAddChild<
1061 // T, decltype(void(std::declval<UIElement>().AddChild(std::declval<T>())))> : std::true_type {
1062 // };
1063
1067 template <typename First, typename... Rest>
1068 struct _CanAddChildren
1069 : std::integral_constant<bool, _CanAddChild<First>::value && _CanAddChildren<Rest...>::value> {
1070 };
1071
1075 template <typename T>
1076 struct _CanAddChildren<T> : _CanAddChild<T> {
1077 };
1078
1083 template <typename T>
1084 int _AddChildrenImpl(T &&child)
1085 {
1086 return this->AddChild(std::forward<T>(child)) ? 1 : 0;
1087 }
1088
1093 template <typename First, typename... Rest>
1094 int _AddChildrenImpl(First &&first, Rest &&...rest)
1095 {
1096 int count = 0;
1097 if (this->AddChild(std::forward<First>(first)))
1098 count = 1 + this->_AddChildrenImpl(std::forward<Rest>(rest)...);
1099 return count;
1100 }
1101
1102 public:
1109 template <typename First, typename... Rest>
1111 -> typename std::enable_if<_CanAddChildren<First, Rest...>::value, int>::type
1112 {
1113 this->_layoutUpdateCondition |= sw::LayoutUpdateCondition::Supressed;
1114 int count = this->_AddChildrenImpl(std::forward<First>(first), std::forward<Rest>(rest)...);
1115 this->_layoutUpdateCondition &= ~sw::LayoutUpdateCondition::Supressed;
1116
1118 this->InvalidateMeasure();
1119 return count;
1120 }
1121
1130 template <typename T>
1131 [[deprecated("Use AddHandler instead to avoid overwriting existing event handlers.")]]
1133 {
1134 if (handler == nullptr) {
1135 this->UnregisterRoutedEvent(eventType);
1136 } else {
1137 this->RegisterRoutedEvent(eventType, RoutedEventHandler(obj, handler));
1138 }
1139 }
1140
1147 template <typename TEventArgs>
1148 [[deprecated("Use AddHandler instead to avoid overwriting existing event handlers.")]]
1150 -> typename std::enable_if<std::is_base_of<RoutedEventArgs, TEventArgs>::value && sw::_IsTypedRoutedEventArgs<TEventArgs>::value>::type
1151 {
1152 if (!handler) {
1153 this->UnregisterRoutedEvent(TEventArgs::EventType);
1154 } else {
1156 }
1157 }
1158
1167 template <typename TEventArgs, typename THandleObj>
1168 [[deprecated("Use AddHandler instead to avoid overwriting existing event handlers.")]]
1171 {
1172 if (handler == nullptr) {
1173 this->UnregisterRoutedEvent(TEventArgs::EventType);
1174 } else {
1176 }
1177 }
1178
1186 template <typename T>
1187 void AddHandler(RoutedEventType eventType, T &obj, void (T::*handler)(UIElement &, RoutedEventArgs &))
1188 {
1189 if (handler) this->_eventMap[eventType].Add(obj, handler);
1190 }
1191
1197 template <typename TEventArgs>
1199 -> typename std::enable_if<std::is_base_of<RoutedEventArgs, TEventArgs>::value && sw::_IsTypedRoutedEventArgs<TEventArgs>::value>::type
1200 {
1201 if (handler) this->AddHandler(TEventArgs::EventType, RoutedEventHandlerWrapper<TEventArgs>(handler));
1202 }
1203
1211 template <typename TEventArgs, typename THandleObj>
1217
1224 template <typename TEventArgs>
1226 -> typename std::enable_if<
1227 std::is_base_of<RoutedEventArgs, TEventArgs>::value &&
1228 !std::is_same<TEventArgs, RoutedEventArgs>::value &&
1230 {
1232 }
1233
1242 template <typename TEventArgs, typename THandleObj>
1244 -> typename std::enable_if<
1245 std::is_base_of<RoutedEventArgs, TEventArgs>::value &&
1246 !std::is_same<TEventArgs, RoutedEventArgs>::value &&
1247 !sw::_IsTypedRoutedEventArgs<TEventArgs>::value>::type
1248 {
1250 }
1251
1260 template <typename T>
1261 bool RemoveHandler(RoutedEventType eventType, T &obj, void (T::*handler)(UIElement &, RoutedEventArgs &))
1262 {
1263 return handler == nullptr ? false : this->_eventMap[eventType].Remove(obj, handler);
1264 }
1265
1272 template <typename TEventArgs>
1274 -> typename std::enable_if<std::is_base_of<RoutedEventArgs, TEventArgs>::value && sw::_IsTypedRoutedEventArgs<TEventArgs>::value, bool>::type
1275 {
1276 if (handler == nullptr) {
1277 return false;
1278 } else {
1279 return this->RemoveHandler(TEventArgs::EventType, RoutedEventHandlerWrapper<TEventArgs>(handler));
1280 }
1281 }
1282
1291 template <typename TEventArgs, typename THandleObj>
1294 {
1295 if (handler == nullptr) {
1296 return false;
1297 } else {
1299 }
1300 }
1301
1309 template <typename TEventArgs>
1311 -> typename std::enable_if<
1312 std::is_base_of<RoutedEventArgs, TEventArgs>::value &&
1313 !std::is_same<TEventArgs, RoutedEventArgs>::value &&
1315 bool>::type
1316 {
1317 if (handler == nullptr) {
1318 return false;
1319 } else {
1321 }
1322 }
1323
1333 template <typename TEventArgs, typename THandleObj>
1335 -> typename std::enable_if<
1336 std::is_base_of<RoutedEventArgs, TEventArgs>::value &&
1337 !std::is_same<TEventArgs, RoutedEventArgs>::value &&
1339 bool>::type
1340 {
1341 if (handler == nullptr) {
1342 return false;
1343 } else {
1345 }
1346 }
1347 };
1348
1352 template <typename T>
1353 struct UIElement::_CanAddChild<
1354 T, decltype(void(std::declval<UIElement>().AddChild(std::declval<T>())))> : std::true_type {
1355 };
1356}
上下文菜单
Definition ContextMenu.h:11
布局接口
Definition ILayout.h:13
值转换器接口
Definition IValueConverter.h:14
表示界面中的元素
Definition UIElement.h:67
Color GetRealTextColor() const
获取当前要显示的文本颜色
virtual UIElement * GetParent() const override final
获取逻辑树中的父元素
const Property< HorizontalAlignment > HorizontalAlignment
水平对齐方式
Definition UIElement.h:256
void RaiseRoutedEvent(RoutedEventType eventType)
触发路由事件
UIElement * GetNextElement()
获取当前元素在界面树上的下一个节点,若已是最后一个节点则返回根节点
void RegisterRoutedEvent(RoutedEventType eventType, T &obj, void(T::*handler)(UIElement &, RoutedEventArgs &))
注册成员函数作为路由事件处理函数,当事件已注册时会覆盖已注册的函数
Definition UIElement.h:1132
void UnregisterRoutedEvent(RoutedEventType eventType)
取消对应类型路由事件的注册,该函数会移除对应事件所有的处理函数
void SetCursor(HCURSOR hCursor)
设置鼠标样式
virtual UIElement * ToUIElement() override final
尝试将对象转换成UIElement
virtual void OnTabStop()
通过tab键将焦点移动到当前元素时调用该函数
bool AddChild(UIElement &element)
添加子元素
virtual bool OnMove(const Point &newClientPosition) override
接收到WM_MOVE时调用该函数
UIElement * GetPreviousElement()
获取当前元素在界面树上的上一个节点,若元素为第一个节点则返回最后一个节点
void UpdateSiblingsZOrder(bool invalidateMeasure=true)
更新兄弟元素的Z轴位置
virtual bool OnClose() override
接收到WM_CLOSE时调用该函数
double GetChildRightmost(bool update)
获取所有子元素在当前元素中最右边的位置(只考虑参与布局的子窗口且忽略悬浮的元素)
const ReadOnlyProperty< bool > IsFocusedViaTab
当前元素是否是通过按下Tab键获得的焦点
Definition UIElement.h:359
const Property< bool > TabStop
表示用户是否可以通过按下Tab键将焦点移动到当前元素
Definition UIElement.h:291
void RegisterRoutedEvent(RoutedEventType eventType, const RoutedEventHandler &handler)
注册路由事件处理函数,当事件已注册时会覆盖已注册的函数
double & GetInternalArrangeOffsetY()
获取布局时子元素的垂直偏移量
virtual void ArrangeOverride(const Size &finalSize)
安排子元素的位置,可重写该函数以实现自定义布局
bool AddChild(UIElement *element)
添加子元素
const Property< double > MinHeight
最小高度,当值为负数或0时表示不限制
Definition UIElement.h:333
bool AddChild(UIElement &element, uint64_t layoutTag)
添加子元素并设置布局标记
virtual UIElement & GetChildAt(int index) const override final
获取逻辑树中指定索引处的子元素
void ResetCursor()
将鼠标样式设置为默认样式
virtual bool OnKeyUp(VirtualKey key, const KeyFlags &flags) override
接收到WM_KEYUP时调用该函数
int IndexOf(UIElement *element)
获取指定元素的索引
virtual void OnRoutedEvent(RoutedEventArgs &eventArgs, const RoutedEventHandler &handler)
路由事件经过当前元素时调用该函数
virtual Size GetDesireSize() const override
获取当前元素所需尺寸
virtual bool OnMouseLeftButtonDown(const Point &mousePosition, MouseKey keyState) override
接收到WM_LBUTTONDOWN时调用该函数
auto RegisterRoutedEvent(THandleObj &obj, void(THandleObj::*handler)(UIElement &, TEventArgs &)) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
根据事件参数类型注册成员函数作为路由事件,当事件已注册时会覆盖已注册的函数
Definition UIElement.h:1169
UIElement * GetRootElement()
获取当前元素所在界面树的根节点
const ReadOnlyProperty< int > ChildCount
子元素数量
Definition UIElement.h:266
virtual bool OnColor(HDC hdc, HBRUSH &hRetBrush) override
父窗口接收到WM_CTLCOLORxxx时调用对应控件的该函数
void ClampDesireSize(sw::Size &size) const
限定指定尺寸在最小和最大尺寸之间
const ReadOnlyProperty< sw::Rect > LogicalRect
元素的逻辑位置和尺寸,即去除布局偏移以及拉伸影响的位置和尺寸
Definition UIElement.h:349
virtual bool OnSetCursor(HWND hwnd, HitTestResult hitTest, int message, bool &result) override
接收到WM_SETCURSOR消息时调用该函数
virtual bool OnKeyDown(VirtualKey key, const KeyFlags &flags) override
接收到WM_KEYDOWN时调用该函数
bool RemoveChildAt(int index)
移除指定索引处的子元素
virtual int GetChildLayoutCount() const override final
获取参与布局的子元素数量
UIElement * GetNextTabStopElement()
获取下一个TabStop属性为true的元素
virtual bool OnDropFiles(HDROP hDrop) override
接收到WM_DROPFILES时调用该函数
virtual bool OnKillFocus(HWND hNextFocus) override
接收到WM_KILLFOCUS时调用该函数
bool RemoveHandler(RoutedEventType eventType, T &obj, void(T::*handler)(UIElement &, RoutedEventArgs &))
移除已添加的类型为成员函数的路由事件处理函数
Definition UIElement.h:1261
auto AddChildren(First &&first, Rest &&...rest) -> typename std::enable_if< _CanAddChildren< First, Rest... >::value, int >::type
添加多个子元素
Definition UIElement.h:1110
bool ShowContextMenu(const Point &point, sw::HorizontalAlignment horz=sw::HorizontalAlignment::Left, sw::VerticalAlignment vert=sw::VerticalAlignment::Top)
弹出当前元素的上下文菜单
virtual bool OnSize(const Size &newClientSize) override
接收到WM_SIZE时调用该函数
virtual bool OnMouseMiddleButtonUp(const Point &mousePosition, MouseKey keyState) override
接收到WM_MBUTTONUP时调用该函数
const Property< uint64_t > LayoutTag
布局标记,对于不同的布局有不同含义
Definition UIElement.h:276
virtual void OnTabMove(bool forward)
通过tab键将焦点从当前元素移出时调用该函数
const ReadOnlyProperty< bool > IsMeasureValid
当前元素的布局状态是否有效
Definition UIElement.h:323
virtual bool OnMouseRightButtonDown(const Point &mousePosition, MouseKey keyState) override
接收到WM_RBUTTONDOWN时调用该函数
void MoveToBottom()
移动到界面底部
virtual bool OnMouseMiddleButtonDown(const Point &mousePosition, MouseKey keyState) override
接收到WM_MBUTTONDOWN时调用该函数
void SetAlignment(sw::HorizontalAlignment horz, sw::VerticalAlignment vert)
设置对齐方式
virtual void OnNcHitTest(const Point &testPoint, HitTestResult &result) override
接收到WM_NCHITTEST后调用该函数
double GetChildBottommost(bool update)
获取所有子元素在当前元素中最底边的位置(只考虑参与布局的子窗口且忽略悬浮的元素)
void AddHandler(RoutedEventType eventType, const RoutedEventHandler &handler)
添加路由事件处理函数
const Property< bool > InheritTextColor
是否继承父元素的文本颜色
Definition UIElement.h:312
virtual void OnTextChanged() override
Text属性更改时调用此函数
void SetCursor(StandardCursor cursor)
设置鼠标样式
virtual uint64_t GetLayoutTag() const override
获取布局标记
const Property< bool > IsHitTestVisible
当前元素是否响应鼠标事件
Definition UIElement.h:354
virtual void ParentChanged(WndBase *newParent) override
父窗口改变时调用此函数
bool QueryAllChildren(const Predicate< UIElement * > &queryFunc)
查询所有子元素,直到queryFunc返回false或所有子元素均被查询
Color GetRealBackColor() const
获取当前要显示的背景颜色
bool IsRootElement() const
判断当前元素是否为根节点
virtual Size MeasureOverride(const Size &availableSize)
测量元素所需尺寸,无需考虑边框和边距
auto AddHandler(const Action< UIElement &, TEventArgs & > &handler) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
根据事件参数类型添加路由事件处理函数
Definition UIElement.h:1198
auto RemoveHandler(RoutedEventType eventType, THandleObj &obj, void(THandleObj::*handler)(UIElement &, TEventArgs &)) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&!std::is_same< TEventArgs, RoutedEventArgs >::value &&!sw::_IsTypedRoutedEventArgs< TEventArgs >::value, bool >::type
移除已添加的类型为成员函数的路由事件处理函数
Definition UIElement.h:1334
const Property< Thickness > Margin
边距
Definition UIElement.h:251
int IndexOf(UIElement &element)
获取指定元素的索引
bool RemoveHandler(RoutedEventType eventType, const RoutedEventHandler &handler)
移除已添加的路由事件处理函数
bool RemoveChild(UIElement *element)
移除子元素
virtual ILayout & GetChildLayoutAt(int index) const override final
获取对应索引处的子元素,只索引参与布局的子元素
virtual bool OnMouseWheel(int wheelDelta, const Point &mousePosition, MouseKey keyState) override
接收到WM_MOUSEWHEEL时调用该函数
virtual bool OnChar(wchar_t ch, const KeyFlags &flags) override
接收到WM_CHAR时调用该函数
auto RemoveHandler(const Action< UIElement &, TEventArgs & > &handler) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value, bool >::type
移除已添加的路由事件处理函数
Definition UIElement.h:1273
const Property< bool > CollapseWhenHide
是否在不可见时不参与布局
Definition UIElement.h:271
void ClearChildren()
移除所有子元素
virtual bool OnSetFocus(HWND hPrevFocus) override
接收到WM_SETFOCUS时调用该函数
auto AddHandler(THandleObj &obj, void(THandleObj::*handler)(UIElement &, TEventArgs &)) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
根据事件参数类型添加成员函数作为路由事件处理函数
Definition UIElement.h:1212
virtual void VisibleChanged(bool newVisible) override
Visible属性改变时调用此函数
const Property< double > MinWidth
最小宽度,当值为负数或0时表示不限制
Definition UIElement.h:328
bool IsLayoutUpdateConditionSet(sw::LayoutUpdateCondition condition)
判断指定的布局更新条件是否已设置
bool RemoveChild(UIElement &element)
移除子元素
virtual bool OnMouseLeftButtonUp(const Point &mousePosition, MouseKey keyState) override
接收到WM_LBUTTONUP时调用该函数
void UpdateChildrenZOrder(bool invalidateMeasure=true)
更新子元素的Z轴位置
auto AddHandler(RoutedEventType eventType, THandleObj &obj, void(THandleObj::*handler)(UIElement &, TEventArgs &)) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&!std::is_same< TEventArgs, RoutedEventArgs >::value &&!sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
添加成员函数作为路由事件处理函数
Definition UIElement.h:1243
void Resize(const Size &size)
调整当前元素的尺寸
void AddHandler(RoutedEventType eventType, T &obj, void(T::*handler)(UIElement &, RoutedEventArgs &))
添加成员函数作为路由事件处理函数
Definition UIElement.h:1187
const Property< double > MaxHeight
最大高度,当值为负数或0时表示不限制
Definition UIElement.h:343
const Property< bool > Transparent
是否使用透明背景
Definition UIElement.h:307
virtual void OnRemovedChild(UIElement &element)
移除子元素后调用该函数
const Property< Color > BackColor
背景颜色,修改该属性会同时将Transparent属性设为false,对于部分控件该属性可能不生效
Definition UIElement.h:296
UIElement * GetPreviousTabStopElement()
获取上一个TabStop属性为true的元素
const Property< sw::LayoutUpdateCondition > LayoutUpdateCondition
触发布局更新的条件
Definition UIElement.h:318
virtual void SetTextColor(Color color, bool redraw)
设置文本颜色
auto AddHandler(RoutedEventType eventType, const Action< UIElement &, TEventArgs & > &handler) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&!std::is_same< TEventArgs, RoutedEventArgs >::value &&!sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
添加路由事件处理函数
Definition UIElement.h:1225
void MoveToTop()
移动到界面顶部
bool QueryAllElements(const Predicate< UIElement * > &queryFunc)
查询自身和所有子元素,直到queryFunc返回false或所有子元素均被查询
auto RegisterRoutedEvent(const Action< UIElement &, TEventArgs & > &handler) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value >::type
根据事件参数类型注册路由事件,当事件已注册时会覆盖已注册的函数
Definition UIElement.h:1149
bool AddChild(UIElement *element, uint64_t layoutTag)
添加子元素并设置布局标记
double & GetInternalArrangeOffsetX()
获取布局时子元素的水平偏移量
const Property< bool > Float
元素是否悬浮,若元素悬浮则该元素不会随滚动条滚动而改变位置
Definition UIElement.h:286
virtual bool RequestBringIntoView(const sw::Rect &screenRect)
尝试将指定的矩形区域移动到可视区域内
virtual bool OnMouseLeave() override
接收到WM_MOUSELEAVE时调用该函数
virtual void Arrange(const sw::Rect &finalPosition) override
安排元素位置
virtual void OnMenuCommand(int id) override
当WM_COMMAND接收到菜单命令时调用该函数
virtual ~UIElement()=0
析构函数,这里用纯虚函数使该类成为抽象类
virtual int GetChildCount() const override final
获取逻辑树中的子元素数量
auto RemoveHandler(THandleObj &obj, void(THandleObj::*handler)(UIElement &, TEventArgs &)) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&sw::_IsTypedRoutedEventArgs< TEventArgs >::value, bool >::type
移除已添加的类型为成员函数的路由事件处理函数
Definition UIElement.h:1292
const Property< double > MaxWidth
最大宽度,当值为负数或0时表示不限制
Definition UIElement.h:338
virtual bool SetParent(WndBase *parent) override
设置父窗口
const Property< VerticalAlignment > VerticalAlignment
垂直对齐方式
Definition UIElement.h:261
bool BringIntoView()
尝试将当前元素移动到可视区域内
bool IsRoutedEventRegistered(RoutedEventType eventType)
判断路由事件是否已存在事件处理函数
auto RemoveHandler(RoutedEventType eventType, const Action< UIElement &, TEventArgs & > &handler) -> typename std::enable_if< std::is_base_of< RoutedEventArgs, TEventArgs >::value &&!std::is_same< TEventArgs, RoutedEventArgs >::value &&!sw::_IsTypedRoutedEventArgs< TEventArgs >::value, bool >::type
移除已添加的路由事件处理函数
Definition UIElement.h:1310
virtual bool OnMouseMove(const Point &mousePosition, MouseKey keyState) override
接收到WM_MOUSEMOVE时调用该函数
virtual void OnAddedChild(UIElement &element)
添加子元素后调用该函数
const Property< sw::ContextMenu * > ContextMenu
右键按下时弹出的菜单
Definition UIElement.h:281
virtual void OnMinMaxSizeChanged()
当MinWidth、MinHeight、MaxWidth或MaxHeight属性更改时调用此函数
virtual bool OnMouseRightButtonUp(const Point &mousePosition, MouseKey keyState) override
接收到WM_RBUTTONUP时调用该函数
const Property< Color > TextColor
文本颜色,修改该属性会同时将InheritTextColor属性设为false,对于部分控件该属性可能不生效
Definition UIElement.h:301
UIElement()
初始化UIElement
virtual void Measure(const Size &availableSize) override
测量元素所需尺寸
virtual bool OnContextMenu(bool isKeyboardMsg, const Point &mousePosition) override
接收到WM_CONTEXTMENU后调用目标控件的该函数
virtual void SetBackColor(Color color, bool redraw)
设置背景颜色
void InvalidateMeasure()
使元素的布局状态失效,并立即触发布局更新
表示一个Windows窗口,是所有窗口和控件的基类
Definition WndBase.h:29
SimpleWindow框架的顶级命名空间,所有公共类型、控件、枚举和工具函数均定义于此。
Definition Alignment.h:4
LayoutUpdateCondition
通知布局更新的条件
Definition UIElement.h:28
@ ChildAdded
添加子元素时更新布局
@ TextChanged
文本改变时更新布局
@ PositionChanged
位置改变时更新布局
@ FontChanged
字体改变时更新布局
@ ChildRemoved
移除子元素时更新布局
@ SizeChanged
尺寸改变时更新布局
VerticalAlignment
垂直对齐方式
Definition Alignment.h:18
MouseKey
鼠标事件时用于判断按键状态
Definition Keys.h:291
VirtualKey
虚拟按键
Definition Keys.h:65
EventHandler< UIElement, RoutedEventArgs > RoutedEventHandler
路由事件类型
Definition RoutedEvent.h:195
HorizontalAlignment
水平对齐方式
Definition Alignment.h:8
StandardCursor
系统标准鼠标样式
Definition Cursor.h:12
RoutedEventType
路由事件类型枚举
Definition RoutedEvent.h:12
HitTestResult
NcHitTest(WM_NCHITTEST)的返回值
Definition HitTestResult.h:10
颜色
Definition Color.h:16
https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#keystroke-message-flags
Definition Keys.h:12
表示相对于左上角的点坐标
Definition Point.h:15
表示一个矩形区域
Definition Rect.h:17
路由事件的参数
Definition RoutedEvent.h:154
尺寸
Definition Size.h:15
表示矩形区域周围边框的厚度
Definition Thickness.h:15
结构体模板,用于检测类型T是否包含事件类型信息
Definition RoutedEventArgs.h:58