aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/controls')
-rw-r--r--src/ui/controls/button.cpp30
-rw-r--r--src/ui/controls/button.h4
-rw-r--r--src/ui/controls/linear_layout.cpp50
-rw-r--r--src/ui/controls/text_box.cpp19
-rw-r--r--src/ui/controls/text_box.h3
-rw-r--r--src/ui/controls/text_control.cpp19
-rw-r--r--src/ui/controls/text_control.h9
-rw-r--r--src/ui/controls/toggle_button.cpp15
8 files changed, 61 insertions, 88 deletions
diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp
index db0b71c2..e600eb89 100644
--- a/src/ui/controls/button.cpp
+++ b/src/ui/controls/button.cpp
@@ -6,33 +6,31 @@ namespace cru::ui::controls
{
using graph::CreateSolidBrush;
- Button::Button() : Control(true)
+ Button::Button() : Control(true),
+ normal_border_{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::RoyalBlue))},
+ pressed_border_{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Blue))}
{
- normal_border_ = BorderProperty::Create();
- normal_border_->SetBrush(CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::RoyalBlue)));
- normal_border_->SetWidth(2);
- normal_border_->SetRadiusX(6);
- normal_border_->SetRadiusY(6);
+ normal_border_.SetStrokeWidth(2);
+ normal_border_.SetRadiusX(6);
+ normal_border_.SetRadiusY(6);
- pressed_border_ = BorderProperty::Create();
- pressed_border_->SetBrush(CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Blue)));
- pressed_border_->SetWidth(2);
- pressed_border_->SetRadiusX(6);
- pressed_border_->SetRadiusY(6);
+ pressed_border_.SetStrokeWidth(2);
+ pressed_border_.SetRadiusX(6);
+ pressed_border_.SetRadiusY(6);
SetBordered(true);
- SetBorderProperty(normal_border_);
+ GetBorderProperty() = normal_border_;
}
void Button::OnMouseClickBegin(MouseButton button)
{
- SetBorderProperty(pressed_border_);
- Repaint();
+ GetBorderProperty() = pressed_border_;
+ InvalidateBorder();
}
void Button::OnMouseClickEnd(MouseButton button)
{
- SetBorderProperty(normal_border_);
- Repaint();
+ GetBorderProperty() = normal_border_;
+ InvalidateBorder();
}
}
diff --git a/src/ui/controls/button.h b/src/ui/controls/button.h
index 011f97d2..e0ece85a 100644
--- a/src/ui/controls/button.h
+++ b/src/ui/controls/button.h
@@ -32,7 +32,7 @@ namespace cru::ui::controls
void OnMouseClickEnd(MouseButton button) override final;
private:
- BorderProperty::Ptr normal_border_;
- BorderProperty::Ptr pressed_border_;
+ BorderProperty normal_border_;
+ BorderProperty pressed_border_;
};
}
diff --git a/src/ui/controls/linear_layout.cpp b/src/ui/controls/linear_layout.cpp
index 7921745a..fb5d3db7 100644
--- a/src/ui/controls/linear_layout.cpp
+++ b/src/ui/controls/linear_layout.cpp
@@ -1,5 +1,7 @@
#include "linear_layout.h"
+#include <algorithm>
+
namespace cru::ui::controls
{
LinearLayout::LinearLayout(const Orientation orientation)
@@ -28,33 +30,33 @@ namespace cru::ui::controls
// First measure Content and Exactly and count Stretch.
if (orientation_ == Orientation::Horizontal)
- ForeachChild([&](Control* const control)
- {
- const auto mode = control->GetLayoutParams()->width.mode;
- if (mode == MeasureMode::Content || mode == MeasureMode::Exactly)
+ for(auto control: GetChildren())
{
- control->Measure(AtLeast0(rest_available_size_for_children));
- const auto size = control->GetDesiredSize();
- rest_available_size_for_children.width -= size.width;
- secondary_side_child_max_length = std::max(size.height, secondary_side_child_max_length);
+ const auto mode = control->GetLayoutParams()->width.mode;
+ if (mode == MeasureMode::Content || mode == MeasureMode::Exactly)
+ {
+ control->Measure(AtLeast0(rest_available_size_for_children));
+ const auto size = control->GetDesiredSize();
+ rest_available_size_for_children.width -= size.width;
+ secondary_side_child_max_length = std::max(size.height, secondary_side_child_max_length);
+ }
+ else
+ stretch_control_list.push_back(control);
}
- else
- stretch_control_list.push_back(control);
- });
else
- ForeachChild([&](Control* const control)
- {
- const auto mode = control->GetLayoutParams()->height.mode;
- if (mode == MeasureMode::Content || mode == MeasureMode::Exactly)
+ for(auto control: GetChildren())
{
- control->Measure(AtLeast0(rest_available_size_for_children));
- const auto size = control->GetDesiredSize();
- rest_available_size_for_children.height -= size.height;
- secondary_side_child_max_length = std::max(size.width, secondary_side_child_max_length);
+ const auto mode = control->GetLayoutParams()->height.mode;
+ if (mode == MeasureMode::Content || mode == MeasureMode::Exactly)
+ {
+ control->Measure(AtLeast0(rest_available_size_for_children));
+ const auto size = control->GetDesiredSize();
+ rest_available_size_for_children.height -= size.height;
+ secondary_side_child_max_length = std::max(size.width, secondary_side_child_max_length);
+ }
+ else
+ stretch_control_list.push_back(control);
}
- else
- stretch_control_list.push_back(control);
- });
if (orientation_ == Orientation::Horizontal)
{
@@ -97,7 +99,7 @@ namespace cru::ui::controls
void LinearLayout::OnLayoutContent(const Rect& rect)
{
float current_main_side_anchor = 0;
- ForeachChild([this, &current_main_side_anchor, rect](Control* control)
+ for(auto control: GetChildren())
{
const auto layout_params = control->GetLayoutParams();
const auto size = control->GetDesiredSize();
@@ -133,6 +135,6 @@ namespace cru::ui::controls
control->Layout(calculate_rect(calculate_secondary_side_anchor(rect.width, size.width), current_main_side_anchor));
current_main_side_anchor += size.height;
}
- });
+ }
}
}
diff --git a/src/ui/controls/text_box.cpp b/src/ui/controls/text_box.cpp
index 54b2f7ab..d6c3d132 100644
--- a/src/ui/controls/text_box.cpp
+++ b/src/ui/controls/text_box.cpp
@@ -1,6 +1,7 @@
#include "text_box.h"
#include <cwctype>
+#include <cassert>
#include "graph/graph.h"
#include "exception.h"
@@ -21,12 +22,6 @@ namespace cru::ui::controls
caret_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black));
- caret_action_ = CreateActionPtr([this]
- {
- is_caret_show_ = !is_caret_show_;
- Repaint();
- });
-
SetBordered(true);
}
@@ -48,17 +43,21 @@ namespace cru::ui::controls
void TextBox::OnGetFocusCore(events::FocusChangeEventArgs& args)
{
TextControl::OnGetFocusCore(args);
- assert(caret_timer_ == nullptr);
+ assert(!caret_timer_.has_value());
is_caret_show_ = true;
- caret_timer_ = SetInterval(Application::GetInstance()->GetCaretInfo().caret_blink_duration, caret_action_);
+ caret_timer_ = SetInterval(Application::GetInstance()->GetCaretInfo().caret_blink_duration, [this]
+ {
+ is_caret_show_ = !is_caret_show_;
+ Repaint();
+ });
}
void TextBox::OnLoseFocusCore(events::FocusChangeEventArgs& args)
{
Control::OnLoseFocusCore(args);
- assert(caret_timer_ != nullptr);
+ assert(caret_timer_.has_value());
caret_timer_->Cancel();
- caret_timer_ = nullptr;
+ caret_timer_ = std::nullopt;
is_caret_show_ = false;
}
diff --git a/src/ui/controls/text_box.h b/src/ui/controls/text_box.h
index 37e04835..a2f4e6e8 100644
--- a/src/ui/controls/text_box.h
+++ b/src/ui/controls/text_box.h
@@ -46,8 +46,7 @@ namespace cru::ui::controls
private:
unsigned caret_position_ = 0;
- TimerTask caret_timer_;
- ActionPtr caret_action_;
+ std::optional<TimerTask> caret_timer_{};
Microsoft::WRL::ComPtr<ID2D1Brush> caret_brush_;
bool is_caret_show_ = false;
};
diff --git a/src/ui/controls/text_control.cpp b/src/ui/controls/text_control.cpp
index 3c5d7c33..5769af58 100644
--- a/src/ui/controls/text_control.cpp
+++ b/src/ui/controls/text_control.cpp
@@ -3,6 +3,7 @@
#include "ui/window.h"
#include "graph/graph.h"
#include "exception.h"
+#include <cassert>
namespace cru::ui::controls
{
@@ -49,19 +50,6 @@ namespace cru::ui::controls
Repaint();
}
- void TextControl::AddTextLayoutHandler(TextLayoutHandlerPtr handler)
- {
- text_layout_handlers_.push_back(std::move(handler));
- }
-
- void TextControl::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 TextControl::SetSelectable(const bool is_selectable)
{
if (!is_selectable)
@@ -115,7 +103,7 @@ namespace cru::ui::controls
ThrowIfFailed(layout->GetMetrics(&text_metrics));
const auto metrics_count = text_metrics.lineCount * text_metrics.maxBidiReorderingDepth;
- Vector<DWRITE_HIT_TEST_METRICS> hit_test_metrics(metrics_count);
+ std::vector<DWRITE_HIT_TEST_METRICS> hit_test_metrics(metrics_count);
UINT32 actual_count;
layout->HitTestTextRange(
range.value().position, range.value().count,
@@ -238,8 +226,5 @@ namespace cru::ui::controls
size.width, size.height,
&text_layout_
));
-
- for (const auto& handler : text_layout_handlers_)
- (*handler)(text_layout_);
}
}
diff --git a/src/ui/controls/text_control.h b/src/ui/controls/text_control.h
index 01bb5565..18a258f2 100644
--- a/src/ui/controls/text_control.h
+++ b/src/ui/controls/text_control.h
@@ -12,8 +12,6 @@ namespace cru::ui::controls
const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush
);
public:
- using TextLayoutHandlerPtr = FunctionPtr<void(Microsoft::WRL::ComPtr<IDWriteTextLayout>)>;
-
TextControl(const TextControl& other) = delete;
TextControl(TextControl&& other) = delete;
TextControl& operator=(const TextControl& other) = delete;
@@ -41,11 +39,6 @@ namespace cru::ui::controls
void SetTextFormat(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& text_format);
-
- void AddTextLayoutHandler(TextLayoutHandlerPtr handler);
-
- void RemoveTextLayoutHandler(const TextLayoutHandlerPtr& handler);
-
bool IsSelectable() const
{
return is_selectable_;
@@ -96,8 +89,6 @@ namespace cru::ui::controls
Microsoft::WRL::ComPtr<IDWriteTextLayout> text_layout_;
private:
- Vector<TextLayoutHandlerPtr> text_layout_handlers_;
-
bool is_selectable_ = false;
bool is_selecting_ = false;
diff --git a/src/ui/controls/toggle_button.cpp b/src/ui/controls/toggle_button.cpp
index 3cd5d3ef..c0244bb6 100644
--- a/src/ui/controls/toggle_button.cpp
+++ b/src/ui/controls/toggle_button.cpp
@@ -1,7 +1,5 @@
#include "toggle_button.h"
-#include <fmt/format.h>
-
#include "graph/graph.h"
#include "ui/animations/animation.h"
@@ -61,12 +59,13 @@ namespace cru::ui::controls
const auto time = total_time * (std::abs(delta) / (inner_circle_x * 2));
// ReSharper disable once CppExpressionWithoutSideEffects
- AnimationBuilder(fmt::format(L"ToggleButton {}", reinterpret_cast<size_t>(this)), time)
- .AddStepHandler(CreatePtr<animations::AnimationStepHandlerPtr>([=](animations::AnimationDelegatePtr, const double percentage)
- {
- current_circle_position_ = static_cast<float>(previous_position + delta * percentage);
- Repaint();
- })).Start();
+ AnimationBuilder(Format(L"ToggleButton {}", reinterpret_cast<size_t>(this)), time)
+ .AddStepHandler([=](auto, const double percentage)
+ {
+ current_circle_position_ = static_cast<float>(previous_position + delta * percentage);
+ Repaint();
+ })
+ .Start();
RaiseToggleEvent(state);
Repaint();