diff options
author | crupest <crupest@outlook.com> | 2018-09-19 01:15:01 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-19 01:15:01 +0800 |
commit | 85bb4d466efeb2540363065d7c0987a9d60f70e9 (patch) | |
tree | ea5e5aa738afb37a2d3bc4e74f9be64c15f3d188 /CruUI/ui/controls/toggle_button.cpp | |
parent | 4710715102df3806479985679bd8048631ccaab5 (diff) | |
download | cru-85bb4d466efeb2540363065d7c0987a9d60f70e9.tar.gz cru-85bb4d466efeb2540363065d7c0987a9d60f70e9.tar.bz2 cru-85bb4d466efeb2540363065d7c0987a9d60f70e9.zip |
finish animation!!!
Diffstat (limited to 'CruUI/ui/controls/toggle_button.cpp')
-rw-r--r-- | CruUI/ui/controls/toggle_button.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/CruUI/ui/controls/toggle_button.cpp b/CruUI/ui/controls/toggle_button.cpp index a22cfda8..033fa9fc 100644 --- a/CruUI/ui/controls/toggle_button.cpp +++ b/CruUI/ui/controls/toggle_button.cpp @@ -8,7 +8,7 @@ namespace cru::ui::controls { using graph::CreateSolidBrush; - using animations::Animation; + using animations::AnimationBuilder; // ui length parameters of toggle button. constexpr float half_height = 15; @@ -56,15 +56,16 @@ namespace cru::ui::controls const auto previous_position = current_circle_position_; const auto delta = destination_x - current_circle_position_; - constexpr double total_time = 0.5; + constexpr auto total_time = FloatSecond(0.2); - const auto time = total_time * std::abs(delta) / (inner_circle_x * 2); + const auto time = total_time * (std::abs(delta) / (inner_circle_x * 2)); - Animation::Builder(fmt::format(L"ToggleButton {}", reinterpret_cast<size_t>(this)), time).AddStepHandler([=](Animation*, const float percentage) + AnimationBuilder(fmt::format(L"ToggleButton {}", reinterpret_cast<size_t>(this)), time) + .AddStepHandler(CreatePtr<animations::AnimationStepHandlerPtr>([=](animations::AnimationDelegatePtr, const double percentage) { - current_circle_position_ = previous_position + delta * percentage; + current_circle_position_ = static_cast<float>(previous_position + delta * percentage); Repaint(); - }).Create(); + })).Start(); OnToggleInternal(state); Repaint(); |