Struct WindowContainer

Source
pub struct WindowContainer {
    pub bg_color: u32,
    /* private fields */
}
Expand description

Contains a Window, pixel buffer, and properties.

Fields§

§bg_color: u32

Implementations§

Source§

impl WindowContainer

Source

pub fn new( width: usize, height: usize, name: &str, color: &str, ) -> Result<Self, WinErr>

Initalizes a new WindowContainer.

Source

pub fn update(&mut self) -> Result<(), WinErr>

Updates the window with its pixel buffer. Pressing ESC will gracefully exit the program.

let mut window = window!(?500, 500, "Window", "FFFFFF");

loop {//can close by pressing ESC
    window.update();
}
Source

pub fn clear(&mut self)

clears the screen to the background color.

let mut window = window!(?500, 500, "Window", "FF00FF");
 
loop {
    window.clear();//clears to "FF00FF"
 
    //drawing code
 
    window.update();
}
Source

pub fn get(&self, pos: (usize, usize)) -> Result<String, WinErr>

Returns the hexidecimal value of a pixel at a position.

Source

pub fn set(&mut self, pos: (usize, usize), val: &str) -> Result<(), WinErr>

Sets a pixel to a hexidecimal value.

Source

pub fn iter(&self) -> IntoIter<(String, (usize, usize))>

returns an iterator over the pixel buffer, holding the hex value and position. Note that the iterator pulled from the buffer is no longer linked to the window, and modifying it will do nothing.

let window = window!(?500, 500, "Window", "FFFFFF");

for (val, pos) in window.iter() {
    let r = to_hex2(pos.0 as u8).unwrap();
    let g = to_hex2(pos.1 as u8).unwrap();
    let string = format!("{r}{g}00");

    window.set(pos, &string)?;
}

loop {
    window.update();
}
Source

pub fn circle( &mut self, pos: (usize, usize), r: usize, color: &str, ) -> Result<(), WinErr>

Draws a circle at a given position with a radius and color.

Source

pub fn line( &mut self, p1: (usize, usize), p2: (usize, usize), t: f64, color: &str, ) -> Result<(), WinErr>

Draws a line between 2 points, with a thickness and color.

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> 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> 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, 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.