livesplit_core/layout/
component_settings.rs

1use super::Component;
2use crate::component::{
3    blank_space, current_comparison, current_pace, delta, detailed_timer, graph, pb_chance,
4    possible_time_save, previous_segment, segment_time, separator, splits, sum_of_best, text,
5    timer, title, total_playtime,
6};
7use crate::platform::prelude::*;
8use serde::{Deserialize, Serialize};
9
10/// The settings for one of the components available.
11#[derive(Clone, Serialize, Deserialize)]
12pub enum ComponentSettings {
13    /// The Settings for the Blank Space Component.
14    BlankSpace(blank_space::Settings),
15    /// The Settings for the Current Comparison Component.
16    CurrentComparison(current_comparison::Settings),
17    /// The Settings for the Current Pace Component.
18    CurrentPace(current_pace::Settings),
19    /// The Settings for the Delta Component.
20    Delta(delta::Settings),
21    /// The Settings for the Detailed Timer Component.
22    DetailedTimer(Box<detailed_timer::Settings>),
23    /// The Settings for the Graph Component.
24    Graph(graph::Settings),
25    /// The Settings for the PB Chance Component.
26    PbChance(pb_chance::Settings),
27    /// The Settings for the Possible Time Save Component.
28    PossibleTimeSave(possible_time_save::Settings),
29    /// The Settings for the Previous Segment Component.
30    PreviousSegment(previous_segment::Settings),
31    /// The Settings for the Segment Time Component.
32    SegmentTime(segment_time::Settings),
33    /// The Settings for the Separator Component.
34    Separator,
35    /// The Settings for the Splits Component.
36    Splits(splits::Settings),
37    /// The Settings for the Sum Of Best Component.
38    SumOfBest(sum_of_best::Settings),
39    /// The Settings for the Text Component.
40    Text(text::Settings),
41    /// The Settings for the Timer Component.
42    Timer(timer::Settings),
43    /// The Settings for the Title Component.
44    Title(title::Settings),
45    /// The Settings for the Total Playtime Component.
46    TotalPlaytime(total_playtime::Settings),
47}
48
49impl From<ComponentSettings> for Component {
50    fn from(settings: ComponentSettings) -> Self {
51        match settings {
52            ComponentSettings::BlankSpace(settings) => {
53                Component::BlankSpace(blank_space::Component::with_settings(settings))
54            }
55            ComponentSettings::CurrentComparison(settings) => {
56                Component::CurrentComparison(current_comparison::Component::with_settings(settings))
57            }
58            ComponentSettings::CurrentPace(settings) => {
59                Component::CurrentPace(current_pace::Component::with_settings(settings))
60            }
61            ComponentSettings::Delta(settings) => {
62                Component::Delta(delta::Component::with_settings(settings))
63            }
64            ComponentSettings::DetailedTimer(settings) => Component::DetailedTimer(Box::new(
65                detailed_timer::Component::with_settings(*settings),
66            )),
67            ComponentSettings::Graph(settings) => {
68                Component::Graph(graph::Component::with_settings(settings))
69            }
70            ComponentSettings::PbChance(settings) => {
71                Component::PbChance(pb_chance::Component::with_settings(settings))
72            }
73            ComponentSettings::PossibleTimeSave(settings) => {
74                Component::PossibleTimeSave(possible_time_save::Component::with_settings(settings))
75            }
76            ComponentSettings::PreviousSegment(settings) => {
77                Component::PreviousSegment(previous_segment::Component::with_settings(settings))
78            }
79            ComponentSettings::SegmentTime(settings) => {
80                Component::SegmentTime(segment_time::Component::with_settings(settings))
81            }
82            ComponentSettings::Separator => Component::Separator(separator::Component::new()),
83            ComponentSettings::Splits(settings) => {
84                Component::Splits(splits::Component::with_settings(settings))
85            }
86            ComponentSettings::SumOfBest(settings) => {
87                Component::SumOfBest(sum_of_best::Component::with_settings(settings))
88            }
89            ComponentSettings::Text(settings) => {
90                Component::Text(text::Component::with_settings(settings))
91            }
92            ComponentSettings::Timer(settings) => {
93                Component::Timer(timer::Component::with_settings(settings))
94            }
95            ComponentSettings::Title(settings) => {
96                Component::Title(title::Component::with_settings(settings))
97            }
98            ComponentSettings::TotalPlaytime(settings) => {
99                Component::TotalPlaytime(total_playtime::Component::with_settings(settings))
100            }
101        }
102    }
103}