From 85bb4d466efeb2540363065d7c0987a9d60f70e9 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 19 Sep 2018 01:15:01 +0800 Subject: finish animation!!! --- CruUI/ui/controls/text_block.cpp | 15 ++++++++++++++- CruUI/ui/controls/text_block.h | 17 +++++------------ CruUI/ui/controls/toggle_button.cpp | 13 +++++++------ 3 files changed, 26 insertions(+), 19 deletions(-) (limited to 'CruUI/ui/controls') diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp index beb799d3..294c456b 100644 --- a/CruUI/ui/controls/text_block.cpp +++ b/CruUI/ui/controls/text_block.cpp @@ -53,6 +53,19 @@ namespace cru Repaint(); } + void TextBlock::AddTextLayoutHandler(TextLayoutHandlerPtr handler) + { + text_layout_handlers_.push_back(std::move(handler)); + } + + void TextBlock::RemoveTextLayoutHandler(const TextLayoutHandlerPtr& handler) + { + const auto find_result = std::find(text_layout_handlers_.cbegin(), text_layout_handlers_.cend(), + handler); + if (find_result != text_layout_handlers_.cend()) + text_layout_handlers_.erase(find_result); + } + void TextBlock::OnSizeChangedCore(events::SizeChangedEventArgs& args) { Control::OnSizeChangedCore(args); @@ -263,7 +276,7 @@ namespace cru &text_layout_ )); - std::for_each(text_layout_handlers_.cbegin(), text_layout_handlers_.cend(), [this](const std::shared_ptr& handler) + std::for_each(text_layout_handlers_.cbegin(), text_layout_handlers_.cend(), [this](const TextLayoutHandlerPtr& handler) { (*handler)(text_layout_); }); diff --git a/CruUI/ui/controls/text_block.h b/CruUI/ui/controls/text_block.h index db22e3c7..3fed2283 100644 --- a/CruUI/ui/controls/text_block.h +++ b/CruUI/ui/controls/text_block.h @@ -39,7 +39,7 @@ namespace cru class TextBlock : public Control { public: - using TextLayoutHandler = Action>; + using TextLayoutHandlerPtr = FunctionPtr)>; static TextBlock* Create( const String& text = L"", @@ -85,16 +85,9 @@ namespace cru void SetTextFormat(const Microsoft::WRL::ComPtr& text_format); - void AddTextLayoutHandler(std::shared_ptr handler) - { - text_layout_handlers_.push_back(std::move(handler)); - } - void RemoveTextLayoutHandler(const std::shared_ptr& handler) - { - const auto find_result = std::find(text_layout_handlers_.cbegin(), text_layout_handlers_.cend(), handler); - if (find_result != text_layout_handlers_.cend()) - text_layout_handlers_.erase(find_result); - } + void AddTextLayoutHandler(TextLayoutHandlerPtr handler); + + void RemoveTextLayoutHandler(const TextLayoutHandlerPtr& handler); protected: void OnSizeChangedCore(events::SizeChangedEventArgs& args) override final; @@ -122,7 +115,7 @@ namespace cru Microsoft::WRL::ComPtr text_format_; Microsoft::WRL::ComPtr text_layout_; - Vector> text_layout_handlers_; + Vector text_layout_handlers_; bool is_selecting_ = false; unsigned mouse_down_position_ = 0; 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(this)), time).AddStepHandler([=](Animation*, const float percentage) + AnimationBuilder(fmt::format(L"ToggleButton {}", reinterpret_cast(this)), time) + .AddStepHandler(CreatePtr([=](animations::AnimationDelegatePtr, const double percentage) { - current_circle_position_ = previous_position + delta * percentage; + current_circle_position_ = static_cast(previous_position + delta * percentage); Repaint(); - }).Create(); + })).Start(); OnToggleInternal(state); Repaint(); -- cgit v1.2.3