diff options
Diffstat (limited to 'CruUI/ui/controls')
-rw-r--r-- | CruUI/ui/controls/text_block.cpp | 15 | ||||
-rw-r--r-- | CruUI/ui/controls/text_block.h | 17 | ||||
-rw-r--r-- | CruUI/ui/controls/toggle_button.cpp | 13 |
3 files changed, 26 insertions, 19 deletions
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<TextLayoutHandler>& 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<Microsoft::WRL::ComPtr<IDWriteTextLayout>>; + using TextLayoutHandlerPtr = FunctionPtr<void(Microsoft::WRL::ComPtr<IDWriteTextLayout>)>; static TextBlock* Create( const String& text = L"", @@ -85,16 +85,9 @@ namespace cru void SetTextFormat(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& text_format); - void AddTextLayoutHandler(std::shared_ptr<TextLayoutHandler> handler) - { - text_layout_handlers_.push_back(std::move(handler)); - } - void RemoveTextLayoutHandler(const std::shared_ptr<TextLayoutHandler>& 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<IDWriteTextFormat> text_format_; Microsoft::WRL::ComPtr<IDWriteTextLayout> text_layout_; - Vector<std::shared_ptr<TextLayoutHandler>> text_layout_handlers_; + Vector<TextLayoutHandlerPtr> 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<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(); |