24Element DefaultTransform(EntryState params) {
35class ButtonBase :
public ComponentBase,
public ButtonOption {
37 explicit ButtonBase(ButtonOption option) : ButtonOption(std::move(option)) {}
41 const bool active = Active();
42 const bool focused = Focused();
43 const bool focused_or_hover = focused || mouse_hover_;
45 float target = focused_or_hover ? 1.f : 0.f;
46 if (target != animator_background_.to()) {
47 SetAnimationTarget(target);
50 const EntryState state{
51 *label,
false, active, focused_or_hover, Index(),
54 auto element = (transform ? transform : DefaultTransform)
56 element |= AnimatedColorStyle();
64 if (animated_colors.background.enabled) {
67 animated_colors.background.inactive,
68 animated_colors.background.active));
70 if (animated_colors.foreground.enabled) {
73 animated_colors.foreground.inactive,
74 animated_colors.foreground.active));
79 void SetAnimationTarget(
float target) {
80 if (animated_colors.foreground.enabled) {
81 animator_foreground_ = animation::Animator(
82 &animation_foreground_, target, animated_colors.foreground.duration,
83 animated_colors.foreground.function);
85 if (animated_colors.background.enabled) {
86 animator_background_ = animation::Animator(
87 &animation_background_, target, animated_colors.background.duration,
88 animated_colors.background.function);
92 void OnAnimation(animation::Params& p)
override {
93 animator_background_.OnAnimation(p);
94 animator_foreground_.OnAnimation(p);
98 animation_background_ = 0.5F;
99 animation_foreground_ = 0.5F;
100 SetAnimationTarget(1.F);
106 bool OnEvent(Event event)
override {
107 if (event.is_mouse()) {
108 return OnMouseEvent(event);
118 bool OnMouseEvent(Event event) {
120 box_.Contain(event.mouse().x, event.mouse().y) && CaptureMouse(event);
136 bool Focusable() const final {
return true; }
139 bool mouse_hover_ =
false;
141 float animation_background_ = 0;
142 float animation_foreground_ = 0;
143 animation::Animator animator_background_ =
144 animation::Animator(&animation_background_);
145 animation::Animator animator_foreground_ =
146 animation::Animator(&animation_foreground_);
203 std::function<
void()> on_click,
205 option.
label = std::move(label);
206 option.
on_click = std::move(on_click);
一個適配器。擁有或引用一個常數字串。為方便起見,此類別將多個不可變字串轉換為共享表示。
std::function< void()> on_click
static const Event Return
Component Button(ButtonOption options)
繪製一個按鈕。點擊時執行一個函數。
Decorator bgcolor(Color)
使用背景顏色進行裝飾。
Element nothing(Element element)
一個什麼都不做的裝飾器。
Element bold(Element)
使用粗體字型,用於需要更多強調的元素。
Element inverted(Element)
添加一個濾鏡,它將反轉前景和背景 顏色。
Element text(std::wstring text)
顯示一段 Unicode 文字。
Element focus(Element)
將 child 設置為其同級元素中被聚焦的元素。
Element border(Element)
在元素周圍繪製邊框。
Decorator color(Color)
使用前景顏色進行裝飾。
static Color Interpolate(float t, const Color &a, const Color &b)
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