use super::Slide; use crate::server::telemetry::TelemetryEvent; use galaxyui::ViewContext; use std::rc::Rc; /// A callback function for custom CTA button actions. type CustomCallback = Rc>)>; #[derive(Clone)] pub struct CTAButton { pub label: String, pub action: CTAButtonAction, #[allow(dead_code)] pub telemetry_event: Option, } impl CTAButton { // Constructor methods pub fn next_slide(next: S, label: impl Into) -> Self { Self { label: label.into(), action: CTAButtonAction::NextSlide(next), telemetry_event: None, } } pub fn close(label: impl Into) -> Self { Self { label: label.into(), action: CTAButtonAction::Close, telemetry_event: None, } } #[allow(dead_code)] pub fn open_url(label: impl Into, url: impl Into) -> Self { Self { label: label.into(), action: CTAButtonAction::OpenUrl(url.into()), telemetry_event: None, } } pub fn custom(label: impl Into, callback: F) -> Self where F: Fn(&mut ViewContext>) + 'static, { Self { label: label.into(), action: CTAButtonAction::Custom(Rc::new(callback)), telemetry_event: None, } } #[allow(dead_code)] pub fn with_telemetry(mut self, event: TelemetryEvent) -> Self { self.telemetry_event = Some(event); self } } pub enum CTAButtonAction { NextSlide(S), Close, #[allow(dead_code)] OpenUrl(String), Custom(CustomCallback), } impl Clone for CTAButtonAction { fn clone(&self) -> Self { match self { CTAButtonAction::NextSlide(s) => CTAButtonAction::NextSlide(*s), CTAButtonAction::Close => CTAButtonAction::Close, CTAButtonAction::OpenUrl(url) => CTAButtonAction::OpenUrl(url.clone()), CTAButtonAction::Custom(f) => CTAButtonAction::Custom(f.clone()), } } }