Struct Config

Source
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 new Config 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

Source

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?
examples/anti.rs (line 8)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let config = Config::new(WIDTH, HEIGHT, WHITE, None, "output.png", None);
9
10    let mut image = Image::new();
11
12    let circle = Components::Circle(config.width / 2, config.height / 2, 10, RED);
13
14    image.config(config).init()?.add_component(&circle).draw()?;
15    Ok(())
16}
More examples
Hide additional examples
examples/circle.rs (line 8)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let config = Config::new(WIDTH, HEIGHT, WHITE, Some(BLACK), "output.png", None);
9
10    let mut image = Image::new();
11
12    let circle = Components::Circle(config.width / 2, config.height / 2, 300, RED);
13
14    image.config(config).init()?.add_component(&circle).draw()?;
15    Ok(())
16}
examples/blend.rs (line 8)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let config = Config::new(WIDTH, HEIGHT, WHITE, Some(BLACK), "output.png", None);
9
10    let mut image = Image::new();
11
12    let circle1 = Components::Circle(config.width / 2, config.height / 2, 350, RED);
13    let circle2 = Components::Circle(
14        config.width / 2,
15        config.height / 2,
16        300,
17        Rgba([255, 0, 255, 120]),
18    );
19    let rectangle = Components::Rectangle(
20        100,
21        100,
22        config.width / 2 - 50,
23        config.height / 2 - 50,
24        Rgba([120, 0, 255, 19]),
25    );
26
27    image
28        .config(config)
29        .init()?
30        .add_components(vec![&circle1, &circle2, &rectangle])
31        .draw()?;
32    Ok(())
33}
examples/line.rs (lines 8-15)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let config = Config::new(
9        WIDTH,
10        HEIGHT,
11        BLACK,
12        Some(GREEN),
13        "output.png",
14        Some("./fonts/Roboto-Medium.ttf"),
15    );
16
17    let mut image = Image::new();
18
19    let line1 = Components::Line(0, 0, WIDTH, HEIGHT, GREEN);
20    let line2 = Components::Line(WIDTH, 0, 0, HEIGHT, GREEN);
21    let circle = Components::Circle(WIDTH / 2, HEIGHT / 2, 100, Rgba([0, 255, 0, 150]));
22    let text = Components::Text(
23        WIDTH / 2 - 210,
24        HEIGHT / 2 - 250,
25        40,
26        "Xiaolin Wu's Line Algorithm",
27        BLACK,
28        Some((GREEN, 3)),
29    );
30
31    image
32        .config(config)
33        .init()?
34        .add_components(vec![&line1, &line2, &circle, &text])
35        .draw()?;
36    Ok(())
37}
examples/text.rs (lines 8-15)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let config = Config::new(
9        WIDTH,
10        HEIGHT,
11        Rgba([255, 255, 255, 0]),
12        Some(WHITE),
13        "output.png",
14        Some("./fonts/Roboto-Medium.ttf"),
15    );
16
17    let mut image = Image::new();
18
19    let circle1 = Components::Circle(50, 55, 30, Rgba([255, 0, 0, 200]));
20    let circle2 = Components::Circle(75, 55, 30, Rgba([0, 255, 0, 200]));
21    let circle3 = Components::Circle(65, 35, 30, Rgba([0, 0, 255, 200]));
22
23    let text = "OMAGE";
24    let text = Components::Text(
25        config.width / 2 - 40,
26        config.height / 2 - 25,
27        50,
28        text,
29        Rgba([255, 255, 255, 255]),
30        Some((BLACK, 3)),
31    );
32
33    image
34        .config(config)
35        .init()?
36        .add_components(vec![&text, &circle1, &circle2, &circle3])
37        .draw()?;
38    Ok(())
39}

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.