33 using namespace ystdex;
45 bool need_h(d.Width < s.Width), need_v(d.Height < s.Height);
49 if(d.Height < min_height)
51 d.Height -= min_height;
55 if(d.Width < min_width)
61 if(!need_h && d.Width < s.Width)
64 if(d.Height < min_height)
66 d.Height -= min_height;
68 if(!need_v && d.Height < s.Height)
71 if(d.Width < min_width)
76 return pair<bool, bool>(need_h, need_v);
85 ATrack::ATrack(
const Rect& r,
SDst uMinThumbLength)
96 GetThumbDrag() += [
this](UIEventArgs&&){
97 LocateThumb(0, ScrollCategory::ThumbTrack);
100 FetchEvent<TouchDown>(*this) += [
this](TouchEventArgs&& e){
101 if(e.Strategy == RoutedEventArgs::Direct && &e.GetSender() ==
this
106 switch(CheckArea(e.GetRef(IsHorizontal())))
109 t = ScrollCategory::LargeDecrement;
112 t = ScrollCategory::LargeIncrement;
117 t = ScrollCategory::EndScroll;
131 const bool is_h(IsHorizontal());
141 ATrack::SetThumbPosition(
SPos pos)
146 const bool is_h(IsHorizontal());
148 if(pos != pt.
GetRef(is_h))
169 SetThumbPosition(
SPos(round(val * GetScrollableLength() / max_value)));
175 SetThumbLength(
SDst(round(val * GetTrackLength() / (val + max_value))));
179 ATrack::CheckArea(
SPos q)
const
185 SPos(GetThumbPosition() + GetThumbLength())};
199 if(t == ScrollCategory::ThumbTrack)
200 value = GetThumbPosition() == GetScrollableLength() ? max_value
201 : max_value * GetThumbPosition()
202 / (GetTrackLength() - GetThumbLength());
205 if(t == ScrollCategory::LargeDecrement
206 || t == ScrollCategory::LargeIncrement)
207 val = GetLargeDelta();
210 case ScrollCategory::SmallDecrement:
211 case ScrollCategory::LargeDecrement:
214 SetValue(value - val);
217 case ScrollCategory::First:
221 case ScrollCategory::SmallIncrement:
222 case ScrollCategory::LargeIncrement:
223 if(value + val < max_value)
225 SetValue(value + val);
228 case ScrollCategory::Last:
230 SetThumbPosition(GetScrollableLength());
242 const auto& g(e.Target);
243 const auto& pt(e.Location);
249 #define YSL_UI_ATRACK_PARTIAL_INVALIDATION
252 #ifdef YSL_UI_ATRACK_PARTIAL_INVALIDATION
255 SPos xr(x + trk.GetWidth());
256 SPos yr(y + trk.GetHeight());
258 const SPos xr(pt.X + trk.GetWidth());
259 const SPos yr(pt.Y + trk.GetHeight());
262 if(trk.IsHorizontal())
264 #ifdef YSL_UI_ATRACK_PARTIAL_INVALIDATION
273 #ifdef YSL_UI_ATRACK_PARTIAL_INVALIDATION
280 #ifndef YSL_UI_ATRACK_PARTIAL_INVALIDATION
286 HorizontalTrack::HorizontalTrack(
const Rect& r,
SDst uMinThumbLength)
287 : ATrack(r, uMinThumbLength)
289 YAssert(GetWidth() > GetHeight(),
"Width is not greater than height.");
291 FetchEvent<TouchMove>(
tmbScroll) +=[
this](TouchEventArgs&& e){
292 if(e.Strategy == RoutedEventArgs::Direct)
295 SPos x(st.LastControlLocation.X + st.DraggingOffset.X);
300 GetThumbDrag()(UIEventArgs(*
this));
306 VerticalTrack::VerticalTrack(
const Rect& r,
SDst uMinThumbLength)
307 : ATrack(r, uMinThumbLength)
309 YAssert(GetHeight() > GetWidth(),
"height is not greater than width.");
311 FetchEvent<TouchMove>(
tmbScroll) += [
this](TouchEventArgs&& e){
312 if(e.Strategy == RoutedEventArgs::Direct)
315 SPos y(st.LastControlLocation.Y + st.DraggingOffset.Y);
320 GetThumbDrag()(UIEventArgs(*
this));
326 AScrollBar::AScrollBar(
const Rect& r,
SDst uMinThumbSize,
Orientation o)
329 ? static_cast<ATrack*>(new HorizontalTrack(
330 Rect(r.Height, 0, r.
Width - r.Height * 2, r.Height), uMinThumbSize))
331 : static_cast<ATrack*>(new VerticalTrack(
339 FetchEvent<Resize>(*
this) += [
this](UIEventArgs&&){
340 auto& track(GetTrack());
341 const bool is_h(track.IsHorizontal());
346 "No enough space for track.");
350 yunseq(track.GetView().GetSizeRef().GetRef(is_h) = tl,
btnNext
351 .GetView().GetLocationRef().GetRef(is_h) = tl + prev_metric);
356 FetchEvent<TouchDown>(
btnPrev) += [
this](TouchEventArgs&&){
357 LocateThumb(small_delta, ScrollCategory::SmallDecrement);
360 FetchEvent<TouchDown>(
btnNext) += [
this](TouchEventArgs&&){
361 LocateThumb(small_delta, ScrollCategory::SmallIncrement);
369 const SDst l(s.GetRef(!bHorizontal));
371 s.GetRef(bHorizontal) = l;
379 HorizontalScrollBar::HorizontalScrollBar(
const Rect& r,
SDst uMinThumbLength)
383 using namespace placeholders;
389 RDeg0, ref(ForeColor))
394 HorizontalScrollBar::GetBoundControlPtr(
const KeyInput& k)
407 VerticalScrollBar::VerticalScrollBar(
const Rect& r,
SDst uMinThumbLength)
411 using namespace placeholders;