pub struct Config {
pub width: u32,
pub height: u32,
pub color: Rgba<u8>,
pub border: Option<Rgba<u8>>,
pub path: &'static str,
pub font_path: Option<&'static str>,
}
Expand description
The Config
struct holds configuration settings for the drawing canvas.
It allows you to specify various parameters such as the width and height of the canvas, background color, optional border color, file paths for the canvas image and an optional font file.
Examples
use omage::{Config, Rgba};
// Create a new Config instance with specified settings
let config = Config::new(800, 600, Rgba([255, 255, 255, 255]), Some(Rgba([0, 0, 0, 255])),
"path/to/canvas/image.png", Some("path/to/font.ttf"));
Fields
width
: Width of the canvas.height
: Height of the canvas.color
: Background color of the canvas in Rgba format.border
: Optional border color of the canvas in Rgba format.path
: Path to the canvas image.font_path
: Optional path to the font file.
Methods
new
: Creates a newConfig
instance with the specified settings.
Note
The Config
struct is meant to be used to configure the canvas for drawing components,
and it provides a convenient way to customize various aspects of the canvas appearance.
Fields§
§width: u32
§height: u32
§color: Rgba<u8>
§border: Option<Rgba<u8>>
§path: &'static str
§font_path: Option<&'static str>
Implementations§
source§impl Config
impl Config
sourcepub fn new(
width: u32,
height: u32,
color: Rgba<u8>,
border: Option<Rgba<u8>>,
path: &'static str,
font_path: Option<&'static str>
) -> Self
pub fn new( width: u32, height: u32, color: Rgba<u8>, border: Option<Rgba<u8>>, path: &'static str, font_path: Option<&'static str> ) -> Self
Creates a new configuration for the drawing canvas.
Parameters
width
: Width of the canvas.height
: Height of the canvas.color
: Background color of the canvas in Rgba format.border
: Optional border color of the canvas in Rgba format.path
: Path to the canvas image.font_path
: Optional path to the font file.
Returns
A Config
instance with the specified settings.
Examples found in repository?
More examples
examples/blend.rs (line 8)
7 8 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
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new(WIDTH, HEIGHT, WHITE, Some(BLACK), "output.png", None);
let mut image = Image::new();
let circle1 = Components::Circle(config.width / 2, config.height / 2, 350, RED);
let circle2 = Components::Circle(
config.width / 2,
config.height / 2,
300,
Rgba([255, 0, 255, 120]),
);
let rectangle = Components::Rectangle(
100,
100,
config.width / 2 - 50,
config.height / 2 - 50,
Rgba([120, 0, 255, 19]),
);
image
.config(config)
.init()?
.add_components(vec![&circle1, &circle2, &rectangle])
.draw()?;
Ok(())
}
examples/line.rs (lines 8-15)
7 8 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 35 36 37
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new(
WIDTH,
HEIGHT,
BLACK,
Some(GREEN),
"output.png",
Some("./fonts/Roboto-Medium.ttf"),
);
let mut image = Image::new();
let line1 = Components::Line(0, 0, WIDTH, HEIGHT, GREEN);
let line2 = Components::Line(WIDTH, 0, 0, HEIGHT, GREEN);
let circle = Components::Circle(WIDTH / 2, HEIGHT / 2, 100, Rgba([0, 255, 0, 150]));
let text = Components::Text(
WIDTH / 2 - 210,
HEIGHT / 2 - 250,
40,
"Xiaolin Wu's Line Algorithm",
BLACK,
Some((GREEN, 3)),
);
image
.config(config)
.init()?
.add_components(vec![&line1, &line2, &circle, &text])
.draw()?;
Ok(())
}
examples/text.rs (lines 8-15)
7 8 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 35 36 37 38 39
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new(
WIDTH,
HEIGHT,
Rgba([255, 255, 255, 0]),
Some(WHITE),
"output.png",
Some("./fonts/Roboto-Medium.ttf"),
);
let mut image = Image::new();
let circle1 = Components::Circle(50, 55, 30, Rgba([255, 0, 0, 200]));
let circle2 = Components::Circle(75, 55, 30, Rgba([0, 255, 0, 200]));
let circle3 = Components::Circle(65, 35, 30, Rgba([0, 0, 255, 200]));
let text = "OMAGE";
let text = Components::Text(
config.width / 2 - 40,
config.height / 2 - 25,
50,
text,
Rgba([255, 255, 255, 255]),
Some((BLACK, 3)),
);
image
.config(config)
.init()?
.add_components(vec![&text, &circle1, &circle2, &circle3])
.draw()?;
Ok(())
}
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more