pub fn update_state(
        &self,
        state: &mut State,
        timer: &Snapshot<'_>,
        layout_settings: &GeneralLayoutSettings,
    ) {
        let method = self
            .settings
            .timing_method
            .unwrap_or_else(|| timer.current_timing_method());

        let phase = timer.current_phase();

        let (time, semantic_color) = if self.settings.is_segment_timer {
            let last_split_index = if phase == TimerPhase::Ended {
                timer.run().len() - 1
            } else {
                timer.current_split_index().unwrap_or_default()
            };
            let mut segment_time = calculate_live_segment_time(timer, method, last_split_index);

            if segment_time.is_none() && method == TimingMethod::GameTime {
                segment_time =
                    calculate_live_segment_time(timer, TimingMethod::RealTime, last_split_index);
            }

            (segment_time, SemanticColor::Default)
        } else {
            let time = timer.current_time();
            let time = time[method].or(time.real_time).unwrap_or_default();
            let current_comparison = timer.current_comparison();

            let semantic_color = match phase {
                TimerPhase::Running if time >= TimeSpan::zero() => {
                    let pb_split_time = timer
                        .current_split()
                        .unwrap()
                        .comparison(current_comparison)[method];

                    if let Some(pb_split_time) = pb_split_time {
                        split_color(
                            timer,
                            Some(time - pb_split_time),
                            timer.current_split_index().unwrap(),
                            true,
                            false,
                            current_comparison,
                            method,
                        )
                        .or(SemanticColor::AheadGainingTime)
                    } else {
                        SemanticColor::AheadGainingTime
                    }
                }
                TimerPhase::Paused => SemanticColor::Paused,
                TimerPhase::Ended => {
                    let pb_time = timer
                        .run()
                        .segments()
                        .last()
                        .unwrap()
                        .comparison(current_comparison)[method];

                    if pb_time.map_or(true, |t| time < t) {
                        SemanticColor::PersonalBest
                    } else {
                        SemanticColor::BehindLosingTime
                    }
                }
                _ => SemanticColor::NotRunning,
            };

            (Some(time), semantic_color)
        };

        let visual_color = if let Some(color) = self.settings.color_override {
            color
        } else {
            semantic_color.visualize(layout_settings)
        };

        let (top_color, bottom_color) = if self.settings.show_gradient {
            top_and_bottom_color(visual_color)
        } else {
            (visual_color, visual_color)
        };

        state.background = self.settings.background;

        state.time.clear();
        let _ = write!(
            state.time,
            "{}",
            formatter::Time::with_digits_format(self.settings.digits_format).format(time),
        );

        state.fraction.clear();
        let _ = write!(
            state.fraction,
            "{}",
            formatter::Fraction::with_accuracy(self.settings.accuracy).format(time),
        );

        state.updates_frequently = phase.is_running() && time.is_some();
        state.semantic_color = semantic_color;
        state.top_color = top_color;
        state.bottom_color = bottom_color;
        state.height = self.settings.height;
    }
/// Updates the component's state based on the timer and layout settings
/// provided.
Updates the component's state based on the timer and layout settings
provided.
Updates the component ' s state based on the timer and layout settings provided .
pub fn update_state(
        &self,
        state: &mut State,
        timer: &Snapshot<'_>,
        layout_settings: &GeneralLayoutSettings,
    ) {
        let method = self
            .settings
            .timing_method
            .unwrap_or_else(|| timer.current_timing_method());
        let phase = timer.current_phase();
        let (time, semantic_color) = if self.settings.is_segment_timer {
            let last_split_index = if phase == TimerPhase::Ended {
                timer.run().len() - 1
            } else {
                timer.current_split_index().unwrap_or_default()
            };
            let mut segment_time = calculate_live_segment_time(timer, method, last_split_index);
            if segment_time.is_none() && method == TimingMethod::GameTime {
                segment_time =
                    calculate_live_segment_time(timer, TimingMethod::RealTime, last_split_index);
            }
            (segment_time, SemanticColor::Default)
        } else {
            let time = timer.current_time();
            let time = time[method].or(time.real_time).unwrap_or_default();
            let current_comparison = timer.current_comparison();
            let semantic_color = match phase {
                TimerPhase::Running if time >= TimeSpan::zero() => {
                    let pb_split_time = timer
                        .current_split()
                        .unwrap()
                        .comparison(current_comparison)[method];
                    if let Some(pb_split_time) = pb_split_time {
                        split_color(
                            timer,
                            Some(time - pb_split_time),
                            timer.current_split_index().unwrap(),
                            true,
                            false,
                            current_comparison,
                            method,
                        )
                        .or(SemanticColor::AheadGainingTime)
                    } else {
                        SemanticColor::AheadGainingTime
                    }
                }
                TimerPhase::Paused => SemanticColor::Paused,
                TimerPhase::Ended => {
                    let pb_time = timer
                        .run()
                        .segments()
                        .last()
                        .unwrap()
                        .comparison(current_comparison)[method];
                    if pb_time.map_or(true, |t| time < t) {
                        SemanticColor::PersonalBest
                    } else {
                        SemanticColor::BehindLosingTime
                    }
                }
                _ => SemanticColor::NotRunning,
            };
            (Some(time), semantic_color)
        };
        let visual_color = if let Some(color) = self.settings.color_override {
            color
        } else {
            semantic_color.visualize(layout_settings)
        };
        let (top_color, bottom_color) = if self.settings.show_gradient {
            top_and_bottom_color(visual_color)
        } else {
            (visual_color, visual_color)
        };
        state.background = self.settings.background;
        state.time.clear();
        let _ = write!(
            state.time,
            "{}",
            formatter::Time::with_digits_format(self.settings.digits_format).format(time),
        );
        state.fraction.clear();
        let _ = write!(
            state.fraction,
            "{}",
            formatter::Fraction::with_accuracy(self.settings.accuracy).format(time),
        );
        state.updates_frequently = phase.is_running() && time.is_some();
        state.semantic_color = semantic_color;
        state.top_color = top_color;
        state.bottom_color = bottom_color;
        state.height = self.settings.height;
    }
pub fn update_state ( & self , state : & mut State , timer : & Snapshot < ' _ > , layout_settings : & GeneralLayoutSettings , ) { let method = self . settings . timing_method . unwrap_or_else ( | | timer . current_timing_method ( ) ) ; let phase = timer . current_phase ( ) ; let ( time , semantic_color ) = if self . settings . is_segment_timer { let last_split_index = if phase == TimerPhase :: Ended { timer . run ( ) . len ( ) - 1 } else { timer . current_split_index ( ) . unwrap_or_default ( ) } ; let mut segment_time = calculate_live_segment_time ( timer , method , last_split_index ) ; if segment_time . is_none ( ) && method == TimingMethod :: GameTime { segment_time = calculate_live_segment_time ( timer , TimingMethod :: RealTime , last_split_index ) ; } ( segment_time , SemanticColor :: Default ) } else { let time = timer . current_time ( ) ; let time = time [ method ] . or ( time . real_time ) . unwrap_or_default ( ) ; let current_comparison = timer . current_comparison ( ) ; let semantic_color = match phase { TimerPhase :: Running if time >= TimeSpan :: zero ( ) => { let pb_split_time = timer . current_split ( ) . unwrap ( ) . comparison ( current_comparison ) [ method ] ; if let Some ( pb_split_time ) = pb_split_time { split_color ( timer , Some ( time - pb_split_time ) , timer . current_split_index ( ) . unwrap ( ) , true , false , current_comparison , method , ) . or ( SemanticColor :: AheadGainingTime ) } else { SemanticColor :: AheadGainingTime } } TimerPhase :: Paused => SemanticColor :: Paused , TimerPhase :: Ended => { let pb_time = timer . run ( ) . segments ( ) . last ( ) . unwrap ( ) . comparison ( current_comparison ) [ method ] ; if pb_time . map_or ( true , | t | time < t ) { SemanticColor :: PersonalBest } else { SemanticColor :: BehindLosingTime } } _ => SemanticColor :: NotRunning , } ; ( Some ( time ) , semantic_color ) } ; let visual_color = if let Some ( color ) = self . settings . color_override { color } else { semantic_color . visualize ( layout_settings ) } ; let ( top_color , bottom_color ) = if self . settings . show_gradient { top_and_bottom_color ( visual_color ) } else { ( visual_color , visual_color ) } ; state . background = self . settings . background ; state . time . clear ( ) ; let _ = write ! ( state time " " formatter Time with_digits_format ( self settings digits_format ) format ( time ) ) ; state . fraction . clear ( ) ; let _ = write ! ( state fraction " " formatter Fraction with_accuracy ( self settings accuracy ) format ( time ) ) ; state . updates_frequently = phase . is_running ( ) && time . is_some ( ) ; state . semantic_color = semantic_color ; state . top_color = top_color ; state . bottom_color = bottom_color ; state . height = self . settings . height ; }
Updates the component's state based on the timer and layout settings
provided.
Updates the component ' s state based on the timer and layout settings provided .
&self
state
&mut State
timer
&Snapshot<'_>
layout_settings
&GeneralLayoutSettings
&self
state
&mut State
timer
&Snapshot<'_>
layout_settings
&GeneralLayoutSettings