fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
    match msg {
        Msg::FractalSelected(selected) => {
            log::debug!("selected {}", selected);
            model.selected_fractal =
                SelectedFractal::from_str(selected.as_ref()).expect("unknown selected fractal");
            model.current_config = model.selected_fractal.default_config();
            log::debug!("config {:?}", model.current_config);
            model.current_animation_status = FractalAnimationStatus::NotStarted;
        }
        Msg::ConfigChanged(input, new_value) => {
            model.current_config.apply_change(input, new_value);
            model.current_animation_status = FractalAnimationStatus::NotStarted;
        }
        Msg::RunClicked => {
            log::debug!("clicked run");
            // Initialize a new animation
            let canvas = model.canvas.get().expect("get canvas element failed");
            model.current_animation = Some(
                model
                    .selected_fractal
                    .build_animation(&canvas, &model.current_config),
            );
            // If it's not currently animating, start the animation
            match model.current_animation_status {
                FractalAnimationStatus::Animating => {}
                _ => {
                    // There might already be an animation running. We don't want to double-up on
                    // the number of AnimationFrameRequested messages if that's the case.
                    orders.after_next_render(|_| Msg::AnimationFrameRequested);
                    model.current_animation_status = FractalAnimationStatus::Animating;
                }
            }
        }
        Msg::PauseClicked => {
            log::debug!("clicked pause");
            model.current_animation_status = FractalAnimationStatus::Paused;
        }
        Msg::ResumeClicked => {
            log::debug!("clicked pause");
            model.current_animation_status = FractalAnimationStatus::Animating;
            orders.after_next_render(|_| Msg::AnimationFrameRequested);
        }
        Msg::AnimationFrameRequested => {
            log::debug!("animation frame requested");
            match &mut model.current_animation {
                None => {}
                Some(animation) => {
                    // Animate until it says its done
                    if animation.draw_one_frame() {
                        // Request another frame only if the animation is still animating.
                        match model.current_animation_status {
                            FractalAnimationStatus::Animating => {
                                orders.after_next_render(|_| Msg::AnimationFrameRequested);
                            }
                            _ => {}
                        }
                    } else {
                        model.current_animation_status = FractalAnimationStatus::Done
                    }
                }
            }
        }
        Msg::CursorCoordsCanged(x, y) => {
            model.cursor_coords = [x, y];
            if let Some(animation) = &model.current_animation {
                let fractal_coords = animation.pixel_to_coordinate(x.into(), y.into());
                model.fractal_coords = Some(fractal_coords);
            }
        }
        Msg::CursorDown => {
            // Track where the cursor started being down, to begin selecting an area to zoom into.
            model.zoom_start_coords = Some(model.cursor_coords);
            log::debug!("Mouse down: {:?}", model.zoom_start_coords);
        }
        Msg::CursorUp => match model.zoom_start_coords {
            None => {}
            Some(zoom_start_coords) => {
                // If the cursor has been held down and was just raised up, compute the zoom and
                // resume the animation, if zoom is supported.
                let zoom_end_coords = model.cursor_coords;
                log::debug!("Mouse up: {:?}", zoom_end_coords);
                match &mut model.current_animation {
                    None => {}
                    Some(animation) => {
                        if animation.zoom(
                            f64::from(zoom_start_coords[0]),
                            f64::from(zoom_start_coords[1]),
                            f64::from(zoom_end_coords[0]),
                            f64::from(zoom_end_coords[1]),
                        ) {
                            // After `zoom()` is called, try to render the next frame. `zoom()`
                            // should prepare the animation.
                            orders.after_next_render(|_| Msg::AnimationFrameRequested);
                            model.current_animation_status = FractalAnimationStatus::Animating;
                        }
                    }
                }
            }
        },
    }
}
/// Handles events that send `Msg`s, resulting in updates to the Model.
Handles events that send `Msg`s, resulting in updates to the Model.
Handles events that send ` Msg ` s resulting in updates to the Model .
fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
    match msg {
        Msg::FractalSelected(selected) => {
            log::debug!("selected {}", selected);
            model.selected_fractal =
                SelectedFractal::from_str(selected.as_ref()).expect("unknown selected fractal");
            model.current_config = model.selected_fractal.default_config();
            log::debug!("config {:?}", model.current_config);
            model.current_animation_status = FractalAnimationStatus::NotStarted;
        }
        Msg::ConfigChanged(input, new_value) => {
            model.current_config.apply_change(input, new_value);
            model.current_animation_status = FractalAnimationStatus::NotStarted;
        }
        Msg::RunClicked => {
            log::debug!("clicked run");
            // Initialize a new animation
            let canvas = model.canvas.get().expect("get canvas element failed");
            model.current_animation = Some(
                model
                    .selected_fractal
                    .build_animation(&canvas, &model.current_config),
            );
            // If it's not currently animating, start the animation
            match model.current_animation_status {
                FractalAnimationStatus::Animating => {}
                _ => {
                    // There might already be an animation running. We don't want to double-up on
                    // the number of AnimationFrameRequested messages if that's the case.
                    orders.after_next_render(|_| Msg::AnimationFrameRequested);
                    model.current_animation_status = FractalAnimationStatus::Animating;
                }
            }
        }
        Msg::PauseClicked => {
            log::debug!("clicked pause");
            model.current_animation_status = FractalAnimationStatus::Paused;
        }
        Msg::ResumeClicked => {
            log::debug!("clicked pause");
            model.current_animation_status = FractalAnimationStatus::Animating;
            orders.after_next_render(|_| Msg::AnimationFrameRequested);
        }
        Msg::AnimationFrameRequested => {
            log::debug!("animation frame requested");
            match &mut model.current_animation {
                None => {}
                Some(animation) => {
                    // Animate until it says its done
                    if animation.draw_one_frame() {
                        // Request another frame only if the animation is still animating.
                        match model.current_animation_status {
                            FractalAnimationStatus::Animating => {
                                orders.after_next_render(|_| Msg::AnimationFrameRequested);
                            }
                            _ => {}
                        }
                    } else {
                        model.current_animation_status = FractalAnimationStatus::Done
                    }
                }
            }
        }
        Msg::CursorCoordsCanged(x, y) => {
            model.cursor_coords = [x, y];
            if let Some(animation) = &model.current_animation {
                let fractal_coords = animation.pixel_to_coordinate(x.into(), y.into());
                model.fractal_coords = Some(fractal_coords);
            }
        }
        Msg::CursorDown => {
            // Track where the cursor started being down, to begin selecting an area to zoom into.
            model.zoom_start_coords = Some(model.cursor_coords);
            log::debug!("Mouse down: {:?}", model.zoom_start_coords);
        }
        Msg::CursorUp => match model.zoom_start_coords {
            None => {}
            Some(zoom_start_coords) => {
                // If the cursor has been held down and was just raised up, compute the zoom and
                // resume the animation, if zoom is supported.
                let zoom_end_coords = model.cursor_coords;
                log::debug!("Mouse up: {:?}", zoom_end_coords);
                match &mut model.current_animation {
                    None => {}
                    Some(animation) => {
                        if animation.zoom(
                            f64::from(zoom_start_coords[0]),
                            f64::from(zoom_start_coords[1]),
                            f64::from(zoom_end_coords[0]),
                            f64::from(zoom_end_coords[1]),
                        ) {
                            // After `zoom()` is called, try to render the next frame. `zoom()`
                            // should prepare the animation.
                            orders.after_next_render(|_| Msg::AnimationFrameRequested);
                            model.current_animation_status = FractalAnimationStatus::Animating;
                        }
                    }
                }
            }
        },
    }
}
fn update ( msg : Msg , model : & mut Model , orders : & mut impl Orders < Msg > ) { match msg { Msg :: FractalSelected ( selected ) => { log :: debug ! ( " " selected ) ; model . selected_fractal = SelectedFractal :: from_str ( selected . as_ref ( ) ) . expect ( " " ) ; model . current_config = model . selected_fractal . default_config ( ) ; log :: debug ! ( " " model current_config ) ; model . current_animation_status = FractalAnimationStatus :: NotStarted ; } Msg :: ConfigChanged ( input , new_value ) => { model . current_config . apply_change ( input , new_value ) ; model . current_animation_status = FractalAnimationStatus :: NotStarted ; } Msg :: RunClicked => { log :: debug ! ( " " ) ; // Initialize a new animation let canvas = model . canvas . get ( ) . expect ( " " ) ; model . current_animation = Some ( model . selected_fractal . build_animation ( & canvas , & model . current_config ) , ) ; // If it's not currently animating, start the animation match model . current_animation_status { FractalAnimationStatus :: Animating => { } _ => { // There might already be an animation running. We don't want to double-up on // the number of AnimationFrameRequested messages if that's the case. orders . after_next_render ( | _ | Msg :: AnimationFrameRequested ) ; model . current_animation_status = FractalAnimationStatus :: Animating ; } } } Msg :: PauseClicked => { log :: debug ! ( " " ) ; model . current_animation_status = FractalAnimationStatus :: Paused ; } Msg :: ResumeClicked => { log :: debug ! ( " " ) ; model . current_animation_status = FractalAnimationStatus :: Animating ; orders . after_next_render ( | _ | Msg :: AnimationFrameRequested ) ; } Msg :: AnimationFrameRequested => { log :: debug ! ( " " ) ; match & mut model . current_animation { None => { } Some ( animation ) => { // Animate until it says its done if animation . draw_one_frame ( ) { // Request another frame only if the animation is still animating. match model . current_animation_status { FractalAnimationStatus :: Animating => { orders . after_next_render ( | _ | Msg :: AnimationFrameRequested ) ; } _ => { } } } else { model . current_animation_status = FractalAnimationStatus :: Done } } } } Msg :: CursorCoordsCanged ( x , y ) => { model . cursor_coords = [ x , y ] ; if let Some ( animation ) = & model . current_animation { let fractal_coords = animation . pixel_to_coordinate ( x . into ( ) , y . into ( ) ) ; model . fractal_coords = Some ( fractal_coords ) ; } } Msg :: CursorDown => { // Track where the cursor started being down, to begin selecting an area to zoom into. model . zoom_start_coords = Some ( model . cursor_coords ) ; log :: debug ! ( " " model zoom_start_coords ) ; } Msg :: CursorUp => match model . zoom_start_coords { None => { } Some ( zoom_start_coords ) => { // If the cursor has been held down and was just raised up, compute the zoom and // resume the animation, if zoom is supported. let zoom_end_coords = model . cursor_coords ; log :: debug ! ( " " zoom_end_coords ) ; match & mut model . current_animation { None => { } Some ( animation ) => { if animation . zoom ( f64 :: from ( zoom_start_coords [ 0 ] ) , f64 :: from ( zoom_start_coords [ 1 ] ) , f64 :: from ( zoom_end_coords [ 0 ] ) , f64 :: from ( zoom_end_coords [ 1 ] ) , ) { // After `zoom()` is called, try to render the next frame. `zoom()` // should prepare the animation. orders . after_next_render ( | _ | Msg :: AnimationFrameRequested ) ; model . current_animation_status = FractalAnimationStatus :: Animating ; } } } } } , } }
Handles events that send `Msg`s, resulting in updates to the Model.
Handles events that send ` Msg ` s resulting in updates to the Model .
msg
Msg
model
&mut Model
orders
&mut impl Orders<Msg>