60 std::function<
void()> on_click,
65 std::function<
void()> on_click,
67 : label_(std::move(label)),
68 on_click_(std::move(on_click)),
69 option_(std::move(option)) {}
73 const bool active = Active();
74 const bool focused = Focused();
75 const bool focused_or_hover = focused || mouse_hover_;
77 float target = focused_or_hover ? 1.F : 0.F;
78 if (target != animator_background_.to()) {
79 SetAnimationTarget(target);
91 (option_->transform ? option_->transform : DefaultTransform)
93 return element | AnimatedColorStyle() | focus_management |
reflect(box_);
98 if (option_->animated_colors.background.enabled) {
99 style = style |
bgcolor(Color::Interpolate(
100 animation_foreground_,
101 option_->animated_colors.background.inactive,
102 option_->animated_colors.background.active));
104 if (option_->animated_colors.foreground.enabled) {
105 style = style |
color(Color::Interpolate(
106 animation_foreground_,
107 option_->animated_colors.foreground.inactive,
108 option_->animated_colors.foreground.active));
113 void SetAnimationTarget(
float target) {
114 if (option_->animated_colors.foreground.enabled) {
115 animator_foreground_ =
117 option_->animated_colors.foreground.duration,
118 option_->animated_colors.foreground.function);
120 if (option_->animated_colors.background.enabled) {
121 animator_background_ =
123 option_->animated_colors.background.duration,
124 option_->animated_colors.background.function);
129 animator_background_.OnAnimation(p);
130 animator_foreground_.OnAnimation(p);
135 animation_background_ = 0.5F;
136 animation_foreground_ = 0.5F;
137 SetAnimationTarget(1.F);
140 bool OnEvent(
Event event)
override {
142 return OnMouseEvent(event);
145 if (event == Event::Return) {
152 bool OnMouseEvent(
Event event) {
154 box_.Contain(event.
mouse().
x, event.
mouse().
y) && CaptureMouse(event);
170 bool Focusable()
const final {
return true; }
174 std::function<void()> on_click_;
175 bool mouse_hover_ =
false;
178 float animation_background_ = 0;
179 float animation_foreground_ = 0;
186 return Make<Impl>(std::move(label), std::move(on_click), std::move(option));
Component Button(ConstStringRef label, std::function< void()> on_click, Ref< ButtonOption >=ButtonOption::Simple())
Draw a button. Execute a function when clicked.
arguments for |ButtonOption::transform|, |CheckboxOption::transform|, |Radiobox::transform|,...