fn draw_digital_clock<D>(
    target: &mut D,
    clock_face: &Circle,
    time_str: &str,
) -> Result<(), D::Error>
where
    D: DrawTarget<Color = Rgb565>,
{
    // Create a styled text object for the time text.
    let mut text = Text::new(
        &time_str,
        Point::zero(),
        MonoTextStyle::new(&FONT_9X15, Rgb565::BLACK),
    );

    // Move text to be centered between the 12 o'clock point and the center of the clock face.
    text.translate_mut(
        clock_face.center()
            - text.bounding_box().center()
            - clock_face.bounding_box().size.y_axis() / 4,
    );

    // Add a background around the time digits.
    // Note that there is no bottom-right padding as this is added by the font renderer itself.
    let text_dimensions = text.bounding_box();
    Rectangle::new(
        text_dimensions.top_left - Point::new(3, 3),
        text_dimensions.size + Size::new(4, 4),
    )
    .into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
    .draw(target)?;

    // Draw the text after the background is drawn.
    text.draw(target)?;

    Ok(())
}
/// Draw digital clock just above center with BLACK text on a white background
Draw digital clock just above center with BLACK text on a white background
Draw digital clock just above center with BLACK text on a white background
fn draw_digital_clock<D>(
    target: &mut D,
    clock_face: &Circle,
    time_str: &str,
) -> Result<(), D::Error>
where
    D: DrawTarget<Color = Rgb565>,
{
    // Create a styled text object for the time text.
    let mut text = Text::new(
        &time_str,
        Point::zero(),
        MonoTextStyle::new(&FONT_9X15, Rgb565::BLACK),
    );
    // Move text to be centered between the 12 o'clock point and the center of the clock face.
    text.translate_mut(
        clock_face.center()
            - text.bounding_box().center()
            - clock_face.bounding_box().size.y_axis() / 4,
    );
    // Add a background around the time digits.
    // Note that there is no bottom-right padding as this is added by the font renderer itself.
    let text_dimensions = text.bounding_box();
    Rectangle::new(
        text_dimensions.top_left - Point::new(3, 3),
        text_dimensions.size + Size::new(4, 4),
    )
    .into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
    .draw(target)?;
    // Draw the text after the background is drawn.
    text.draw(target)?;
    Ok(())
}
fn draw_digital_clock < D > ( target : & mut D , clock_face : & Circle , time_str : & str , ) -> Result < ( ) , D :: Error > where D : DrawTarget < Color = Rgb565 > , { // Create a styled text object for the time text. let mut text = Text :: new ( & time_str , Point :: zero ( ) , MonoTextStyle :: new ( & FONT_9X15 , Rgb565 :: BLACK ) , ) ; // Move text to be centered between the 12 o'clock point and the center of the clock face. text . translate_mut ( clock_face . center ( ) - text . bounding_box ( ) . center ( ) - clock_face . bounding_box ( ) . size . y_axis ( ) / 4 , ) ; // Add a background around the time digits. // Note that there is no bottom-right padding as this is added by the font renderer itself. let text_dimensions = text . bounding_box ( ) ; Rectangle :: new ( text_dimensions . top_left - Point :: new ( 3 , 3 ) , text_dimensions . size + Size :: new ( 4 , 4 ) , ) . into_styled ( PrimitiveStyle :: with_fill ( Rgb565 :: WHITE ) ) . draw ( target ) ? ; // Draw the text after the background is drawn. text . draw ( target ) ? ; Ok ( ( ) ) }
Draw digital clock just above center with BLACK text on a white background
Draw digital clock just above center with BLACK text on a white background
target
&mut D
clock_face
&Circle
time_str
&str