use std::rc::Rc; use taffy::{AlignItems, JustifyContent, prelude::length}; use crate::{ animation::{Animation, AnimationEasing}, components::Component, drawing::{self, Color}, event::{CallbackDataCommon, EventListenerCollection, EventListenerKind}, layout::{Layout, WidgetID}, renderer_vk::text::{FontWeight, TextStyle}, widget::{ rectangle::{Rectangle, RectangleParams}, text::{TextLabel, TextParams}, util::WLength, }, }; pub struct Params<'a> { pub text: &'a str, pub color: drawing::Color, pub border_color: drawing::Color, pub round: WLength, pub style: taffy::Style, pub text_style: TextStyle, } impl Default for Params<'_> { fn default() -> Self { Self { text: "Text", color: drawing::Color::new(1.0, 1.0, 1.0, 1.0), border_color: drawing::Color::new(0.0, 0.0, 0.0, 1.0), round: WLength::Units(4.0), style: Default::default(), text_style: TextStyle::default(), } } } pub struct Button { initial_color: drawing::Color, initial_border_color: drawing::Color, pub body: WidgetID, // Rectangle pub text_id: WidgetID, // Text text_node: taffy::NodeId, } impl Component for Button {} impl Button { pub fn set_text<'a, 'b, C>(&self, callback_data: &mut CallbackDataCommon, text: &str) { callback_data.call_on_widget(self.text_id, |label: &mut TextLabel| { label.set_text(text); }); callback_data.mark_redraw(); callback_data.mark_dirty(self.text_node); } } fn anim_hover(rect: &mut Rectangle, button: &Button, pos: f32) { let brightness = pos * 0.5; let border_brightness = pos; rect.params.color.r = button.initial_color.r + brightness; rect.params.color.g = button.initial_color.g + brightness; rect.params.color.b = button.initial_color.b + brightness; rect.params.border_color.r = button.initial_border_color.r + border_brightness; rect.params.border_color.g = button.initial_border_color.g + border_brightness; rect.params.border_color.b = button.initial_border_color.b + border_brightness; rect.params.border = 3.0; } fn anim_hover_in(button: Rc