use super::actions::ReplaySpeed;
use crate::tokens::DESIGN_TOKENS;
use egui::Color32;
#[derive(Debug, Clone)]
pub struct ReplayColors {
pub play_color: Color32,
pub pause_color: Color32,
pub stop_color: Color32,
pub progress_bg: Color32,
pub progress_fill: Color32,
pub progress_cursor: Color32,
pub marker_color: Color32,
pub speed_color: Color32,
pub active_indicator: Color32,
pub disabled_color: Color32,
}
impl Default for ReplayColors {
fn default() -> Self {
Self {
play_color: DESIGN_TOKENS.semantic.extended.success,
pause_color: DESIGN_TOKENS.semantic.extended.favorite_gold,
stop_color: DESIGN_TOKENS.semantic.extended.error,
progress_bg: DESIGN_TOKENS.semantic.extended.chart_axis_bg,
progress_fill: DESIGN_TOKENS.semantic.extended.info,
progress_cursor: Color32::WHITE,
marker_color: DESIGN_TOKENS.semantic.extended.warning,
speed_color: DESIGN_TOKENS.semantic.extended.purple,
active_indicator: DESIGN_TOKENS.semantic.extended.success,
disabled_color: DESIGN_TOKENS.semantic.extended.disabled,
}
}
}
#[derive(Debug, Clone)]
pub struct ReplayLayout {
pub control_bar_height: f32,
pub btn_size: f32,
pub small_button_size: f32,
pub btn_spacing: f32,
pub progress_bar_height: f32,
pub progress_bar_width: Option<f32>,
pub padding: f32,
pub speed_dropdown_width: f32,
pub date_display_width: f32,
}
impl Default for ReplayLayout {
fn default() -> Self {
Self {
control_bar_height: DESIGN_TOKENS.sizing.replay.control_bar_height,
btn_size: DESIGN_TOKENS.sizing.replay.button_size,
small_button_size: DESIGN_TOKENS.sizing.button_sm,
btn_spacing: DESIGN_TOKENS.spacing.sm,
progress_bar_height: DESIGN_TOKENS.spacing.lg,
progress_bar_width: None,
padding: DESIGN_TOKENS.spacing.lg,
speed_dropdown_width: DESIGN_TOKENS.sizing.replay.speed_dropdown_width,
date_display_width: DESIGN_TOKENS.sizing.replay.date_display_width,
}
}
}
#[derive(Debug, Clone)]
pub struct ReplayBehavior {
pub default_speed: ReplaySpeed,
pub loop_playback: bool,
pub show_trading_panel: bool,
pub initial_capital: f64,
pub auto_scroll: bool,
pub lookahead_bars: usize,
pub pause_on_interaction: bool,
pub min_bar_duration: f64,
pub max_bar_duration: f64,
pub show_bar_counter: bool,
pub show_elapsed_time: bool,
pub show_remaining_time: bool,
}
impl Default for ReplayBehavior {
fn default() -> Self {
Self {
default_speed: ReplaySpeed::Normal,
loop_playback: false,
show_trading_panel: false,
initial_capital: 10000.0,
auto_scroll: true,
lookahead_bars: 10,
pause_on_interaction: false,
min_bar_duration: 0.01,
max_bar_duration: 10.0,
show_bar_counter: true,
show_elapsed_time: true,
show_remaining_time: true,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ReplayConfig {
pub colors: ReplayColors,
pub layout: ReplayLayout,
pub behavior: ReplayBehavior,
}
impl ReplayConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_colors(mut self, colors: ReplayColors) -> Self {
self.colors = colors;
self
}
pub fn with_layout(mut self, layout: ReplayLayout) -> Self {
self.layout = layout;
self
}
pub fn with_behavior(mut self, behavior: ReplayBehavior) -> Self {
self.behavior = behavior;
self
}
pub fn compact() -> Self {
Self {
layout: ReplayLayout {
control_bar_height: DESIGN_TOKENS.sizing.icon_xxl,
btn_size: DESIGN_TOKENS.sizing.icon_lg,
small_button_size: DESIGN_TOKENS.sizing.technical_labels.elliott_label_size,
btn_spacing: DESIGN_TOKENS.spacing.xs,
progress_bar_height: DESIGN_TOKENS.spacing.md,
padding: DESIGN_TOKENS.spacing.sm,
speed_dropdown_width: DESIGN_TOKENS.sizing.technical_labels.pattern_label_width
- DESIGN_TOKENS.spacing.xxxl,
date_display_width: DESIGN_TOKENS.sizing.replay.date_display_width
- DESIGN_TOKENS.spacing.section_lg,
..Default::default()
},
..Default::default()
}
}
pub fn minimal() -> Self {
Self {
layout: ReplayLayout {
control_bar_height: DESIGN_TOKENS.sizing.replay.button_size,
btn_size: DESIGN_TOKENS.sizing.button_sm,
small_button_size: DESIGN_TOKENS.sizing.icon_md,
btn_spacing: DESIGN_TOKENS.spacing.xs,
progress_bar_height: DESIGN_TOKENS.spacing.sm,
padding: DESIGN_TOKENS.spacing.sm,
speed_dropdown_width: DESIGN_TOKENS.sizing.technical_labels.line_label_width,
date_display_width: DESIGN_TOKENS.sizing.replay.date_display_width
- DESIGN_TOKENS.sizing.technical_labels.pattern_label_width
+ DESIGN_TOKENS.spacing.section_lg,
..Default::default()
},
behavior: ReplayBehavior {
show_bar_counter: false,
show_elapsed_time: false,
show_remaining_time: false,
..Default::default()
},
..Default::default()
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config_creation() {
let config = ReplayConfig::new();
assert_eq!(
config.layout.control_bar_height,
DESIGN_TOKENS.sizing.replay.control_bar_height
);
assert!(!config.behavior.loop_playback);
}
#[test]
fn test_compact_layout() {
let config = ReplayConfig::compact();
assert!(config.layout.control_bar_height < DESIGN_TOKENS.sizing.replay.control_bar_height);
}
#[test]
fn test_minimal_layout() {
let config = ReplayConfig::minimal();
assert!(!config.behavior.show_bar_counter);
}
}