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

        let run = timer.run();

        let (current_split, last_split_index) = if current_phase == TimerPhase::Ended {
            (run.segments().last(), run.len() - 1)
        } else {
            (
                timer.current_split(),
                timer.current_split_index().unwrap_or(0),
            )
        };

        let (comparison1, comparison2) = if current_phase != TimerPhase::NotRunning {
            let mut comparison1 = self
                .settings
                .comparison1
                .as_deref()
                .unwrap_or_else(|| timer.current_comparison());

            let comparison2 = self
                .settings
                .comparison2
                .as_deref()
                .unwrap_or_else(|| timer.current_comparison());

            let mut hide_comparison = self.settings.hide_second_comparison;

            if hide_comparison
                || !run.comparisons().any(|c| c == comparison2)
                || comparison2 == none::NAME
            {
                hide_comparison = true;
                if !run.comparisons().any(|c| c == comparison1) || comparison1 == none::NAME {
                    comparison1 = timer.current_comparison();
                }
            } else if !run.comparisons().any(|c| c == comparison1) || comparison1 == none::NAME {
                hide_comparison = true;
                comparison1 = comparison2;
            } else if comparison1 == comparison2 {
                hide_comparison = true;
            }

            let comparison1 = Some((
                comparison::shorten(comparison1),
                comparison_single_segment_time(run, last_split_index, comparison1, timing_method),
            ));

            let comparison2 = if !hide_comparison {
                Some((
                    comparison::shorten(comparison2),
                    comparison_single_segment_time(
                        run,
                        last_split_index,
                        comparison2,
                        timing_method,
                    ),
                ))
            } else {
                None
            };

            (comparison1, comparison2)
        } else {
            Default::default()
        };

        let display_icon = self.settings.display_icon;
        let icon_change = self
            .icon_id
            .update_with(current_split.filter(|_| display_icon).map(Segment::icon))
            .map(Into::into);

        state.background = self.settings.background;

        self.timer
            .update_state(&mut state.timer, timer, layout_settings);

        self.segment_timer
            .update_state(&mut state.segment_timer, timer, layout_settings);

        update_comparison(&mut state.comparison1, comparison1);
        update_comparison(&mut state.comparison2, comparison2);

        match current_split.filter(|_| self.settings.show_segment_name) {
            Some(segment) => {
                let segment_name = state.segment_name.get_or_insert_with(String::new);
                segment_name.clear();
                segment_name.push_str(segment.name());
            }
            None => state.segment_name = None,
        }

        state.icon_change = icon_change;
    }
/// 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(
        &mut self,
        state: &mut State,
        timer: &Snapshot<'_>,
        layout_settings: &GeneralLayoutSettings,
    ) {
        let current_phase = timer.current_phase();
        let timing_method = self
            .settings
            .timer
            .timing_method
            .unwrap_or_else(|| timer.current_timing_method());
        let run = timer.run();
        let (current_split, last_split_index) = if current_phase == TimerPhase::Ended {
            (run.segments().last(), run.len() - 1)
        } else {
            (
                timer.current_split(),
                timer.current_split_index().unwrap_or(0),
            )
        };
        let (comparison1, comparison2) = if current_phase != TimerPhase::NotRunning {
            let mut comparison1 = self
                .settings
                .comparison1
                .as_deref()
                .unwrap_or_else(|| timer.current_comparison());
            let comparison2 = self
                .settings
                .comparison2
                .as_deref()
                .unwrap_or_else(|| timer.current_comparison());
            let mut hide_comparison = self.settings.hide_second_comparison;
            if hide_comparison
                || !run.comparisons().any(|c| c == comparison2)
                || comparison2 == none::NAME
            {
                hide_comparison = true;
                if !run.comparisons().any(|c| c == comparison1) || comparison1 == none::NAME {
                    comparison1 = timer.current_comparison();
                }
            } else if !run.comparisons().any(|c| c == comparison1) || comparison1 == none::NAME {
                hide_comparison = true;
                comparison1 = comparison2;
            } else if comparison1 == comparison2 {
                hide_comparison = true;
            }
            let comparison1 = Some((
                comparison::shorten(comparison1),
                comparison_single_segment_time(run, last_split_index, comparison1, timing_method),
            ));
            let comparison2 = if !hide_comparison {
                Some((
                    comparison::shorten(comparison2),
                    comparison_single_segment_time(
                        run,
                        last_split_index,
                        comparison2,
                        timing_method,
                    ),
                ))
            } else {
                None
            };
            (comparison1, comparison2)
        } else {
            Default::default()
        };
        let display_icon = self.settings.display_icon;
        let icon_change = self
            .icon_id
            .update_with(current_split.filter(|_| display_icon).map(Segment::icon))
            .map(Into::into);
        state.background = self.settings.background;
        self.timer
            .update_state(&mut state.timer, timer, layout_settings);
        self.segment_timer
            .update_state(&mut state.segment_timer, timer, layout_settings);
        update_comparison(&mut state.comparison1, comparison1);
        update_comparison(&mut state.comparison2, comparison2);
        match current_split.filter(|_| self.settings.show_segment_name) {
            Some(segment) => {
                let segment_name = state.segment_name.get_or_insert_with(String::new);
                segment_name.clear();
                segment_name.push_str(segment.name());
            }
            None => state.segment_name = None,
        }
        state.icon_change = icon_change;
    }
pub fn update_state ( & mut self , state : & mut State , timer : & Snapshot < ' _ > , layout_settings : & GeneralLayoutSettings , ) { let current_phase = timer . current_phase ( ) ; let timing_method = self . settings . timer . timing_method . unwrap_or_else ( | | timer . current_timing_method ( ) ) ; let run = timer . run ( ) ; let ( current_split , last_split_index ) = if current_phase == TimerPhase :: Ended { ( run . segments ( ) . last ( ) , run . len ( ) - 1 ) } else { ( timer . current_split ( ) , timer . current_split_index ( ) . unwrap_or ( 0 ) , ) } ; let ( comparison1 , comparison2 ) = if current_phase != TimerPhase :: NotRunning { let mut comparison1 = self . settings . comparison1 . as_deref ( ) . unwrap_or_else ( | | timer . current_comparison ( ) ) ; let comparison2 = self . settings . comparison2 . as_deref ( ) . unwrap_or_else ( | | timer . current_comparison ( ) ) ; let mut hide_comparison = self . settings . hide_second_comparison ; if hide_comparison || ! run . comparisons ( ) . any ( | c | c == comparison2 ) || comparison2 == none :: NAME { hide_comparison = true ; if ! run . comparisons ( ) . any ( | c | c == comparison1 ) || comparison1 == none :: NAME { comparison1 = timer . current_comparison ( ) ; } } else if ! run . comparisons ( ) . any ( | c | c == comparison1 ) || comparison1 == none :: NAME { hide_comparison = true ; comparison1 = comparison2 ; } else if comparison1 == comparison2 { hide_comparison = true ; } let comparison1 = Some ( ( comparison :: shorten ( comparison1 ) , comparison_single_segment_time ( run , last_split_index , comparison1 , timing_method ) , ) ) ; let comparison2 = if ! hide_comparison { Some ( ( comparison :: shorten ( comparison2 ) , comparison_single_segment_time ( run , last_split_index , comparison2 , timing_method , ) , ) ) } else { None } ; ( comparison1 , comparison2 ) } else { Default :: default ( ) } ; let display_icon = self . settings . display_icon ; let icon_change = self . icon_id . update_with ( current_split . filter ( | _ | display_icon ) . map ( Segment :: icon ) ) . map ( Into :: into ) ; state . background = self . settings . background ; self . timer . update_state ( & mut state . timer , timer , layout_settings ) ; self . segment_timer . update_state ( & mut state . segment_timer , timer , layout_settings ) ; update_comparison ( & mut state . comparison1 , comparison1 ) ; update_comparison ( & mut state . comparison2 , comparison2 ) ; match current_split . filter ( | _ | self . settings . show_segment_name ) { Some ( segment ) => { let segment_name = state . segment_name . get_or_insert_with ( String :: new ) ; segment_name . clear ( ) ; segment_name . push_str ( segment . name ( ) ) ; } None => state . segment_name = None , } state . icon_change = icon_change ; }
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 .
&mut self
state
&mut State
timer
&Snapshot<'_>
layout_settings
&GeneralLayoutSettings
&mut self
state
&mut State
timer
&Snapshot<'_>
layout_settings
&GeneralLayoutSettings