Struct OutputSettingsBuilder

Source
pub struct OutputSettingsBuilder { /* private fields */ }
Expand description

Output settings builder.

Implementations§

Source§

impl OutputSettingsBuilder

Source

pub fn new() -> Self

Creates new output settings builder.

Examples found in repository?
examples/png-base64.rs (line 27)
9fn main() {
10    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
11
12    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
13    let centered = TextStyleBuilder::new()
14        .baseline(Baseline::Middle)
15        .alignment(Alignment::Center)
16        .build();
17
18    Text::with_text_style(
19        "embedded-graphics",
20        display.bounding_box().center(),
21        large_text,
22        centered,
23    )
24    .draw(&mut display)
25    .unwrap();
26
27    let output_settings = OutputSettingsBuilder::new().scale(2).build();
28    let output_image = display.to_grayscale_output_image(&output_settings);
29
30    println!(
31        "<img src=\"data:image/png;base64,{}\">",
32        output_image.to_base64_png().unwrap()
33    );
34}
More examples
Hide additional examples
examples/png-file.rs (line 27)
9fn main() {
10    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
11
12    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
13    let centered = TextStyleBuilder::new()
14        .baseline(Baseline::Middle)
15        .alignment(Alignment::Center)
16        .build();
17
18    Text::with_text_style(
19        "embedded-graphics",
20        display.bounding_box().center(),
21        large_text,
22        centered,
23    )
24    .draw(&mut display)
25    .unwrap();
26
27    let output_settings = OutputSettingsBuilder::new().scale(2).build();
28    let output_image = display.to_rgb_output_image(&output_settings);
29
30    let path = std::env::args_os()
31        .nth(1)
32        .expect("expected PNG file name argument");
33    output_image.save_png(path).unwrap();
34}
examples/themes.rs (line 30)
11fn main() {
12    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
13
14    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
15    let centered = TextStyleBuilder::new()
16        .baseline(Baseline::Middle)
17        .alignment(Alignment::Center)
18        .build();
19
20    Text::with_text_style(
21        "embedded-graphics",
22        display.bounding_box().center(),
23        large_text,
24        centered,
25    )
26    .draw(&mut display)
27    .unwrap();
28
29    // Uncomment one of the `theme` lines to use a different theme.
30    let output_settings = OutputSettingsBuilder::new()
31        //.theme(BinaryColorTheme::LcdGreen)
32        //.theme(BinaryColorTheme::LcdWhite)
33        .theme(BinaryColorTheme::LcdBlue)
34        //.theme(BinaryColorTheme::OledBlue)
35        //.theme(BinaryColorTheme::OledWhite)
36        .build();
37
38    let mut window = Window::new("Themes", &output_settings);
39    window.show_static(&display);
40}
Source

pub fn scale(self, scale: u32) -> Self

Sets the pixel scale.

A scale of 2 or higher is useful for viewing the simulator on high DPI displays.

§Panics

Panics if the scale is set to 0.

Examples found in repository?
examples/png-base64.rs (line 27)
9fn main() {
10    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
11
12    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
13    let centered = TextStyleBuilder::new()
14        .baseline(Baseline::Middle)
15        .alignment(Alignment::Center)
16        .build();
17
18    Text::with_text_style(
19        "embedded-graphics",
20        display.bounding_box().center(),
21        large_text,
22        centered,
23    )
24    .draw(&mut display)
25    .unwrap();
26
27    let output_settings = OutputSettingsBuilder::new().scale(2).build();
28    let output_image = display.to_grayscale_output_image(&output_settings);
29
30    println!(
31        "<img src=\"data:image/png;base64,{}\">",
32        output_image.to_base64_png().unwrap()
33    );
34}
More examples
Hide additional examples
examples/png-file.rs (line 27)
9fn main() {
10    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
11
12    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
13    let centered = TextStyleBuilder::new()
14        .baseline(Baseline::Middle)
15        .alignment(Alignment::Center)
16        .build();
17
18    Text::with_text_style(
19        "embedded-graphics",
20        display.bounding_box().center(),
21        large_text,
22        centered,
23    )
24    .draw(&mut display)
25    .unwrap();
26
27    let output_settings = OutputSettingsBuilder::new().scale(2).build();
28    let output_image = display.to_rgb_output_image(&output_settings);
29
30    let path = std::env::args_os()
31        .nth(1)
32        .expect("expected PNG file name argument");
33    output_image.save_png(path).unwrap();
34}
Source

pub fn theme(self, theme: BinaryColorTheme) -> Self

Sets the binary color theme.

The binary color theme defines the mapping between the two display colors and the output. The variants provided by the BinaryColorTheme enum simulate the color scheme of commonly used display types.

Most binary color displays are relatively small individual pixels are hard to recognize on higher resolution screens. Because of this some scaling is automatically applied to the output when a theme is set and no scaling was specified explicitly.

Note that a theme should only be set when an monochrome display is used. Setting a theme when using a color display will cause an corrupted output.

Examples found in repository?
examples/themes.rs (line 33)
11fn main() {
12    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
13
14    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
15    let centered = TextStyleBuilder::new()
16        .baseline(Baseline::Middle)
17        .alignment(Alignment::Center)
18        .build();
19
20    Text::with_text_style(
21        "embedded-graphics",
22        display.bounding_box().center(),
23        large_text,
24        centered,
25    )
26    .draw(&mut display)
27    .unwrap();
28
29    // Uncomment one of the `theme` lines to use a different theme.
30    let output_settings = OutputSettingsBuilder::new()
31        //.theme(BinaryColorTheme::LcdGreen)
32        //.theme(BinaryColorTheme::LcdWhite)
33        .theme(BinaryColorTheme::LcdBlue)
34        //.theme(BinaryColorTheme::OledBlue)
35        //.theme(BinaryColorTheme::OledWhite)
36        .build();
37
38    let mut window = Window::new("Themes", &output_settings);
39    window.show_static(&display);
40}
Source

pub fn pixel_spacing(self, pixel_spacing: u32) -> Self

Sets the gap between pixels.

Most lower resolution displays have visible gaps between individual pixels. This effect can be simulated by setting the pixel spacing to a value greater than 0.

Source

pub fn max_fps(self, max_fps: u32) -> Self

Sets the FPS limit of the window.

Source

pub fn build(self) -> OutputSettings

Builds the output settings.

Examples found in repository?
examples/png-base64.rs (line 27)
9fn main() {
10    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
11
12    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
13    let centered = TextStyleBuilder::new()
14        .baseline(Baseline::Middle)
15        .alignment(Alignment::Center)
16        .build();
17
18    Text::with_text_style(
19        "embedded-graphics",
20        display.bounding_box().center(),
21        large_text,
22        centered,
23    )
24    .draw(&mut display)
25    .unwrap();
26
27    let output_settings = OutputSettingsBuilder::new().scale(2).build();
28    let output_image = display.to_grayscale_output_image(&output_settings);
29
30    println!(
31        "<img src=\"data:image/png;base64,{}\">",
32        output_image.to_base64_png().unwrap()
33    );
34}
More examples
Hide additional examples
examples/png-file.rs (line 27)
9fn main() {
10    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
11
12    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
13    let centered = TextStyleBuilder::new()
14        .baseline(Baseline::Middle)
15        .alignment(Alignment::Center)
16        .build();
17
18    Text::with_text_style(
19        "embedded-graphics",
20        display.bounding_box().center(),
21        large_text,
22        centered,
23    )
24    .draw(&mut display)
25    .unwrap();
26
27    let output_settings = OutputSettingsBuilder::new().scale(2).build();
28    let output_image = display.to_rgb_output_image(&output_settings);
29
30    let path = std::env::args_os()
31        .nth(1)
32        .expect("expected PNG file name argument");
33    output_image.save_png(path).unwrap();
34}
examples/themes.rs (line 36)
11fn main() {
12    let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(256, 64));
13
14    let large_text = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
15    let centered = TextStyleBuilder::new()
16        .baseline(Baseline::Middle)
17        .alignment(Alignment::Center)
18        .build();
19
20    Text::with_text_style(
21        "embedded-graphics",
22        display.bounding_box().center(),
23        large_text,
24        centered,
25    )
26    .draw(&mut display)
27    .unwrap();
28
29    // Uncomment one of the `theme` lines to use a different theme.
30    let output_settings = OutputSettingsBuilder::new()
31        //.theme(BinaryColorTheme::LcdGreen)
32        //.theme(BinaryColorTheme::LcdWhite)
33        .theme(BinaryColorTheme::LcdBlue)
34        //.theme(BinaryColorTheme::OledBlue)
35        //.theme(BinaryColorTheme::OledWhite)
36        .build();
37
38    let mut window = Window::new("Themes", &output_settings);
39    window.show_static(&display);
40}

Trait Implementations§

Source§

impl Default for OutputSettingsBuilder

Source§

fn default() -> OutputSettingsBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.