18 void updateScrollBar(ScrollBar* _scroll,
int _viewSize,
int _contentSize,
size_t _range,
size_t _page)
20 _scroll->setScrollPage(_page);
21 _scroll->setScrollViewPage(std::max(
static_cast<size_t>(std::max(0, _viewSize)), _page));
22 _scroll->setScrollRange(_range + 1);
23 if (_contentSize != 0)
24 _scroll->setTrackSize(
25 static_cast<int>(
static_cast<double>(_scroll->getLineSize()) * _viewSize / _contentSize));
30 void ScrollViewBase::updateScrollSize()
32 if (mScrollViewClient ==
nullptr)
36 IntSize contentSize = getContentSize();
37 IntSize viewSize = getViewSize();
39 const auto refreshSizes = [&]
41 if (mChangeContentByResize)
44 contentSize = getContentSize();
46 viewSize = getViewSize();
49 const auto setVerticalVisible = [&](
bool _visible)
51 if (mVScroll ==
nullptr || mVScroll->getVisible() == _visible)
54 const int delta = _visible ? -mVScroll->getWidth() : mVScroll->getWidth();
55 mVScroll->setVisible(_visible);
56 mScrollViewClient->setSize(mScrollViewClient->getWidth() + delta, mScrollViewClient->getHeight());
57 if (mHScroll !=
nullptr)
58 mHScroll->setSize(mHScroll->getWidth() + delta, mHScroll->getHeight());
63 const auto setHorizontalVisible = [&](
bool _visible)
65 if (mHScroll ==
nullptr || mHScroll->getVisible() == _visible)
68 const int delta = _visible ? -mHScroll->getHeight() : mHScroll->getHeight();
69 mHScroll->setVisible(_visible);
70 mScrollViewClient->setSize(mScrollViewClient->getWidth(), mScrollViewClient->getHeight() + delta);
71 if (mVScroll !=
nullptr)
72 mVScroll->setSize(mVScroll->getWidth(), mVScroll->getHeight() + delta);
79 const bool showVertical = mVisibleVScroll && contentSize.height > viewSize.height;
80 if (setVerticalVisible(showVertical))
82 const bool showHorizontal = mVisibleHScroll && contentSize.width > viewSize.width;
83 if (showHorizontal == showVertical)
84 setHorizontalVisible(showHorizontal);
87 const bool showHorizontal = mVisibleHScroll && contentSize.width > viewSize.width;
88 if (setHorizontalVisible(showHorizontal))
90 const bool showVerticalAfterResize = mVisibleVScroll && contentSize.height > viewSize.height;
91 if (showVerticalAfterResize == showHorizontal)
92 setVerticalVisible(showVerticalAfterResize);
95 mVRange =
static_cast<size_t>(std::max(0, contentSize.height - viewSize.height));
96 mHRange =
static_cast<size_t>(std::max(0, contentSize.width - viewSize.width));
98 if (mVScroll !=
nullptr)
99 updateScrollBar(mVScroll, viewSize.height, contentSize.height, mVRange, getVScrollPage());
100 if (mHScroll !=
nullptr)
101 updateScrollBar(mHScroll, viewSize.width, contentSize.width, mHRange, getHScrollPage());
104 void ScrollViewBase::updateScrollPosition()
106 const IntSize contentSize = getContentSize();
107 const IntPoint contentPoint = getContentPosition();
110 const IntSize viewSize = getViewSize();
112 const Align align = getContentAlign();
114 if (contentSize.width > viewSize.width)
116 offset.left = std::clamp(offset.left, 0, contentSize.width - viewSize.width);
124 else if (align.isRight())
126 offset.left = contentSize.width - viewSize.width;
130 offset.left = (contentSize.width - viewSize.width) / 2;
134 if (contentSize.height > viewSize.height)
136 offset.top = std::clamp(offset.top, 0, contentSize.height - viewSize.height);
144 else if (align.isBottom())
146 offset.top = contentSize.height - viewSize.height;
150 offset.top = (contentSize.height - viewSize.height) / 2;
154 if (offset != contentPoint)
156 if (mVScroll !=
nullptr)
157 mVScroll->setScrollPosition(offset.top);
158 if (mHScroll !=
nullptr)
159 mHScroll->setScrollPosition(offset.left);
160 setContentPosition(offset);
164 IntSize ScrollViewBase::getContentSize()
const
169 IntPoint ScrollViewBase::getContentPosition()
const
174 void ScrollViewBase::setContentPosition(
const IntPoint& _value)
178 IntSize ScrollViewBase::getViewSize()
const
183 size_t ScrollViewBase::getHScrollPage()
const
188 size_t ScrollViewBase::getVScrollPage()
const
193 Align ScrollViewBase::getContentAlign()
const
195 return Align::Center;
198 void ScrollViewBase::eraseContent()
types::TPoint< int > IntPoint
types::TSize< int > IntSize