aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/controls
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-19 01:15:01 +0800
committercrupest <crupest@outlook.com>2018-09-19 01:15:01 +0800
commit85bb4d466efeb2540363065d7c0987a9d60f70e9 (patch)
treeea5e5aa738afb37a2d3bc4e74f9be64c15f3d188 /CruUI/ui/controls
parent4710715102df3806479985679bd8048631ccaab5 (diff)
downloadcru-85bb4d466efeb2540363065d7c0987a9d60f70e9.tar.gz
cru-85bb4d466efeb2540363065d7c0987a9d60f70e9.tar.bz2
cru-85bb4d466efeb2540363065d7c0987a9d60f70e9.zip
finish animation!!!
Diffstat (limited to 'CruUI/ui/controls')
-rw-r--r--CruUI/ui/controls/text_block.cpp15
-rw-r--r--CruUI/ui/controls/text_block.h17
-rw-r--r--CruUI/ui/controls/toggle_button.cpp13
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();