Commit 9f24ff1 1 parent 5a88c58 commit 9f24ff1 Copy full SHA for 9f24ff1
File tree 2 files changed +9
-11
lines changed
include/elements/element/gallery
2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ namespace cycfi { namespace elements
23
23
24
24
private:
25
25
26
- float _xpos = full_extent ;
26
+ float _val = 0 . 0f ;
27
27
};
28
28
29
29
inline auto slide_switch ()
Original file line number Diff line number Diff line change @@ -48,25 +48,23 @@ namespace cycfi { namespace elements
48
48
color = color.opacity (color.alpha * theme_.disabled_opacity );
49
49
50
50
// Animate sliding
51
- auto target = value? bounds. right -radius : bounds. left +radius ;
52
- if (enabled && _xpos > bounds. left && _xpos < bounds. right )
51
+ auto diff = value - _val ;
52
+ if (std::abs (diff) > 0.1 )
53
53
{
54
- auto diff = target - _xpos;
55
54
constexpr auto alpha = 0.3 ;
56
- _xpos += alpha * diff;
57
- if (std::abs (diff) > 1 .0f )
58
- ctx.view .refresh (ctx);
59
- else
60
- _xpos = target;
55
+ _val += alpha * diff;
56
+ ctx.view .refresh (ctx);
61
57
}
62
58
else
63
59
{
64
- _xpos = target ;
60
+ _val = value ;
65
61
}
62
+ auto span = (bounds.right -bounds.left )-height; // height == diameter of thumb
63
+ auto xpos = bounds.left + radius + (span * _val);
66
64
67
65
// Draw the thumb
68
66
canvas_.begin_path ();
69
- canvas_.add_circle (_xpos , bounds.top +radius, radius-1.5 );
67
+ canvas_.add_circle (xpos , bounds.top +radius, radius-1.5 );
70
68
canvas_.fill_style (color);
71
69
canvas_.fill ();
72
70
}
You can’t perform that action at this time.
0 commit comments