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