25Element DefaultTransform(EntryState params) {
36class ButtonBase :
public ComponentBase,
public ButtonOption {
38 explicit ButtonBase(ButtonOption option) : ButtonOption(std::move(option)) {}
42 const bool active = Active();
43 const bool focused = Focused();
44 const bool focused_or_hover = focused || mouse_hover_;
46 float target = focused_or_hover ? 1.f : 0.f;
47 if (target != animator_background_.to()) {
48 SetAnimationTarget(target);
51 const EntryState state{
52 std::string(*label),
false, active, focused_or_hover, Index(),
55 auto element = (transform ? transform : DefaultTransform)
57 element |= AnimatedColorStyle();
65 if (animated_colors.background.enabled) {
68 animated_colors.background.inactive,
69 animated_colors.background.active));
71 if (animated_colors.foreground.enabled) {
74 animated_colors.foreground.inactive,
75 animated_colors.foreground.active));
80 void SetAnimationTarget(
float target) {
81 if (animated_colors.foreground.enabled) {
82 animator_foreground_ = animation::Animator(
83 &animation_foreground_, target, animated_colors.foreground.duration,
84 animated_colors.foreground.function);
86 if (animated_colors.background.enabled) {
87 animator_background_ = animation::Animator(
88 &animation_background_, target, animated_colors.background.duration,
89 animated_colors.background.function);
93 void OnAnimation(animation::Params& p)
override {
94 animator_background_.OnAnimation(p);
95 animator_foreground_.OnAnimation(p);
99 animation_background_ = 0.5F;
100 animation_foreground_ = 0.5F;
101 SetAnimationTarget(1.F);
108 bool OnEvent(Event event)
override {
109 if (event.is_mouse()) {
110 return OnMouseEvent(event);
120 bool OnMouseEvent(Event event) {
122 box_.Contain(event.mouse().x, event.mouse().y) && CaptureMouse(event);
138 bool Focusable() const final {
return true; }
141 bool mouse_hover_ =
false;
143 float animation_background_ = 0;
144 float animation_foreground_ = 0;
145 animation::Animator animator_background_ =
146 animation::Animator(&animation_background_);
147 animation::Animator animator_foreground_ =
148 animation::Animator(&animation_foreground_);
205 std::function<
void()> on_click,
207 option.
label = std::move(label);
208 option.
on_click = std::move(on_click);
An adapter. Own or reference a constant string. For convenience, this class convert multiple immutabl...
std::function< void()> on_click
static const Event Return
Component Button(ButtonOption options)
Draw a button. Execute a function when clicked.
Decorator bgcolor(Color)
Decorate using a background color.
Element nothing(Element element)
A decoration doing absolutely nothing.
Element text(std::wstring_view text)
Display a piece of unicode text.
Element bold(Element)
Use a bold font, for elements with more emphasis.
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Element focus(Element)
Set the child to be the one focused among its siblings.
Element border(Element)
Draw a border around the element.
Decorator color(Color)
Decorate using a foreground color.
static Color Interpolate(float t, const Color &a, const Color &b)
The FTXUI ftxui:: namespace.
std::function< Element(Element)> Decorator
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
Decorator reflect(Box &box)
std::shared_ptr< ComponentBase > Component