5#include "ScrollEnums.h"
11 template <
typename TBase,
typename =
void>
17 template <
typename TBase>
26 static constexpr int _LayerScrollBarLineInterval = 20;
32 bool _autoSize =
true;
42 bool _horizontalScrollDisabled =
true;
47 bool _verticalScrollDisabled =
true;
52 bool _mouseWheelScrollEnabled =
true;
61 return self->_customLayout;
66 self->_customLayout = value;
67 self->InvalidateMeasure();
76 return self->_autoSize;
79 if (
self->_autoSize != value) {
80 self->_autoSize = value;
81 self->InvalidateMeasure();
94 if (
self->HorizontalScrollBar == value) {
99 self->HorizontalScrollPos =
self->HorizontalScrollPos;
101 self->HorizontalScrollPos = 0;
115 if (
self->VerticalScrollBar == value) {
120 self->VerticalScrollPos =
self->VerticalScrollPos;
122 self->VerticalScrollPos = 0;
148 if (
layout !=
nullptr && !
self->_horizontalScrollDisabled &&
self->HorizontalScrollBar) {
149 self->GetInternalArrangeOffsetX() = -
self->HorizontalScrollPos;
150 self->_MeasureAndArrangeWithoutResize(*
layout,
self->ClientRect->GetSize());
176 if (
layout !=
nullptr && !
self->_verticalScrollDisabled &&
self->VerticalScrollBar) {
177 self->GetInternalArrangeOffsetY() = -
self->VerticalScrollPos;
178 self->_MeasureAndArrangeWithoutResize(*
layout,
self->ClientRect->GetSize());
188 if (
self->_horizontalScrollDisabled) {
204 if (
self->_verticalScrollDisabled) {
220 return self->_mouseWheelScrollEnabled;
223 self->_mouseWheelScrollEnabled = value;
235 _MeasureAndArrangeWithoutLayout();
237 _MeasureAndArrangeWithoutResize(*
layout, this->ClientRect->GetSize());
261 this->RaiseRoutedEvent(
args);
271 HorizontalScrollPos = pos;
283 ScrollHorizontal(-GetHorizontalScrollPageSize());
287 ScrollHorizontal(GetHorizontalScrollPageSize());
291 ScrollHorizontal(-_LayerScrollBarLineInterval);
295 ScrollHorizontal(_LayerScrollBarLineInterval);
306 VerticalScrollPos = pos;
318 ScrollVertical(-GetVerticalScrollPageSize());
322 ScrollVertical(GetVerticalScrollPageSize());
326 ScrollVertical(-_LayerScrollBarLineInterval);
330 ScrollVertical(_LayerScrollBarLineInterval);
387 if (
layout ==
nullptr || !_autoSize) {
404 _MeasureAndArrangeWithoutLayout();
405 }
else if (!_autoSize) {
421 bool handled =
false;
428 if (VerticalScrollBar) {
429 double curPos = VerticalScrollPos;
431 VerticalScrollPos =
rect.top;
434 VerticalScrollPos =
rect.top;
442 if (HorizontalScrollBar) {
443 double curPos = HorizontalScrollPos;
445 HorizontalScrollPos =
rect.left;
448 HorizontalScrollPos =
rect.left;
473 double offset = -std::copysign(_LayerScrollBarLineInterval,
wheelArgs.wheelDelta);
475 if (HorizontalScrollBar) {
480 if (VerticalScrollBar) {
604 if (_GetLayout() ==
nullptr) {
607 _horizontalScrollDisabled =
false;
608 _verticalScrollDisabled =
false;
612 if (HorizontalScrollBar) {
616 _horizontalScrollDisabled =
false;
621 double pos = HorizontalScrollPos;
622 if (-this->GetInternalArrangeOffsetX() > pos) {
623 HorizontalScrollPos = pos;
627 HorizontalScrollPos = 0;
629 _horizontalScrollDisabled =
true;
633 if (VerticalScrollBar) {
637 _verticalScrollDisabled =
false;
642 double pos = VerticalScrollPos;
643 if (-this->GetInternalArrangeOffsetY() > pos) {
644 VerticalScrollPos = pos;
648 VerticalScrollPos = 0;
650 _verticalScrollDisabled =
true;
660 VerticalScrollPos = 0;
668 VerticalScrollPos = VerticalScrollLimit;
676 HorizontalScrollPos = 0;
684 HorizontalScrollPos = HorizontalScrollLimit;
693 HorizontalScrollPos +=
offset;
702 VerticalScrollPos +=
offset;
712 auto layout = (_customLayout !=
nullptr) ? _customLayout : GetDefaultLayout();
719 void _MeasureAndArrangeWithoutLayout()
721 this->GetInternalArrangeOffsetX() = 0;
722 this->GetInternalArrangeOffsetY() = 0;
724 int childCount = this->GetChildLayoutCount();
726 for (
int i = 0; i < childCount; ++i) {
728 UIElement &item =
static_cast<UIElement &
>(this->GetChildLayoutAt(i));
729 item.Measure(Size{INFINITY, INFINITY});
731 Size desireSize = item.GetDesireSize();
733 Thickness itemMargin = item.Margin;
734 item.Arrange(
sw::Rect{itemRect.
left - itemMargin.left, itemRect.
top - itemMargin.top, desireSize.width, desireSize.height});
741 void _MeasureAndArrangeWithoutResize(LayoutHost &layout,
const Size &clientSize)
743 if (layout.IsAssociated(
this)) {
744 layout.MeasureOverride(clientSize);
745 layout.ArrangeOverride(clientSize);
752 extern template class Layer<UIElement>;
static int DipToPxY(double dip) noexcept
dip转像素(垂直方向)
static int DipToPxX(double dip) noexcept
dip转像素(水平方向)
static double PxToDipX(int px) noexcept
像素转dip(水平方向)
static double PxToDipY(int px) noexcept
像素转dip(垂直方向)
值转换器接口
Definition IValueConverter.h:14
virtual Size MeasureOverride(const Size &availableSize) override
测量元素所需尺寸,无需考虑边框和边距
Definition Layer.h:381
virtual void Arrange(const sw::Rect &finalPosition) override
安排元素位置
Definition Layer.h:370
void UpdateLayout()
更新布局
Definition Layer.h:230
virtual LayoutHost * GetDefaultLayout()
获取默认布局对象
Definition Layer.h:247
void SetVerticalScrollRange(double min, double max)
设置纵向滚动条的范围
Definition Layer.h:539
void ScrollToRight()
将水平滚动条移动到最右
Definition Layer.h:682
void UpdateScrollRange()
根据子元素更新滚动条范围,未设定布局方式时该函数无效
Definition Layer.h:602
virtual void ArrangeOverride(const Size &finalSize) override
安排子元素的位置,可重写该函数以实现自定义布局
Definition Layer.h:398
void SetHorizontalScrollPageSize(double pageSize)
设置水平滚动条滚动页面大小
Definition Layer.h:578
void ScrollHorizontal(double offset)
水平滚动
Definition Layer.h:691
void ScrollToLeft()
将水平滚动条移动到最左
Definition Layer.h:674
void SetHorizontalScrollRange(double min, double max)
设置横向滚动条的范围
Definition Layer.h:522
void ScrollToBottom()
将垂直滚动条移动到底部
Definition Layer.h:666
void GetVerticalScrollRange(double &refMin, double &refMax)
获取纵向滚动条的范围
Definition Layer.h:508
void ScrollVertical(double offset)
垂直滚动
Definition Layer.h:700
virtual bool OnVerticalScroll(int event, int pos) override
接收到WM_VSCROLL时调用目标控件的该函数
Definition Layer.h:346
void SetVerticalScrollPageSize(double pageSize)
设置垂直滚动条滚动页面大小
Definition Layer.h:590
virtual void OnRoutedEvent(RoutedEventArgs &eventArgs, const RoutedEventHandler &handler) override
路由事件经过当前元素时调用该函数
Definition Layer.h:464
virtual void OnScroll(ScrollOrientation scrollbar, ScrollEvent event, double pos)
触发滚动条相关事件时调用该函数
Definition Layer.h:258
virtual bool RequestBringIntoView(const sw::Rect &screenRect) override
尝试将指定的矩形区域移动到可视区域内
Definition Layer.h:419
void ScrollToTop()
将垂直滚动条移动到顶部
Definition Layer.h:658
void GetHorizontalScrollRange(double &refMin, double &refMax)
获取横向滚动条的范围
Definition Layer.h:494
double GetVerticalScrollPageSize()
获取垂直滚动条滚动页面大小
Definition Layer.h:566
double GetHorizontalScrollPageSize()
获取水平滚动条滚动页面大小
Definition Layer.h:554
virtual bool OnHorizontalScroll(int event, int pos) override
接收到WM_HSCROLL时调用目标控件的该函数
Definition Layer.h:359
用于托管元素的布局方式的对象类型,是所有布局方式类型的基类
Definition LayoutHost.h:11
void Associate(ILayout *obj)
设置关联的对象,每个LayoutHost只能关联一个对象
static StaticPropertyInitializer< T > Init()
获取静态属性初始化器
Definition Property.h:1523
SimpleWindow框架的顶级命名空间,所有公共类型、控件、枚举和工具函数均定义于此。
Definition Alignment.h:4
ScrollOrientation
滚动条方向
Definition ScrollEnums.h:10
@ AutoSize
调整BmpBox大小,使其等于所包含位图的大小
ScrollEvent
滚动条事件
Definition ScrollEnums.h:18
@ Bottom
Scrolls to the lower right.
@ ThubmTrack
The user is dragging the scroll box. This message is sent repeatedly until the user releases the mous...
@ LineLeft
Scrolls left by one unit.
@ LineRight
Scrolls right by one unit.
@ LineDown
Scrolls one line down.
@ Right
Scrolls to the lower right.
@ Left
Scrolls to the upper left.
@ PageUp
Scrolls one page up.
@ LineUp
Scrolls one line up.
@ Top
Scrolls to the upper left.
@ PageRight
Scrolls right by the width of the window.
@ PageLeft
Scrolls left by the width of the window.
@ PageDown
Scrolls one page down.
@ UIElement_MouseWheel
鼠标滚轮滚动,参数类型为sw::MouseWheelEventArgs
Definition RoutedEvent.h:53
鼠标滚轮滚动事件参数类型
Definition RoutedEventArgs.h:134
表示相对于左上角的点坐标
Definition Point.h:15
double y
纵坐标
Definition Point.h:24
double x
横坐标
Definition Point.h:19
表示一个矩形区域
Definition Rect.h:17
double top
顶边
Definition Rect.h:26
double left
左边
Definition Rect.h:21
路由事件的参数
Definition RoutedEvent.h:154