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
impl WindowContainer
Sourcepub fn new(
width: usize,
height: usize,
name: &str,
color: &str,
) -> Result<Self, WinErr>
pub fn new( width: usize, height: usize, name: &str, color: &str, ) -> Result<Self, WinErr>
Initalizes a new WindowContainer.
Sourcepub fn update(&mut self) -> Result<(), WinErr>
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();
}
Sourcepub fn clear(&mut self)
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();
}
Sourcepub fn get(&self, pos: (usize, usize)) -> Result<String, WinErr>
pub fn get(&self, pos: (usize, usize)) -> Result<String, WinErr>
Returns the hexidecimal value of a pixel at a position.
Sourcepub fn set(&mut self, pos: (usize, usize), val: &str) -> Result<(), WinErr>
pub fn set(&mut self, pos: (usize, usize), val: &str) -> Result<(), WinErr>
Sets a pixel to a hexidecimal value.
Sourcepub fn iter(&self) -> IntoIter<(String, (usize, usize))>
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();
}
Auto Trait Implementations§
impl Freeze for WindowContainer
impl !RefUnwindSafe for WindowContainer
impl !Send for WindowContainer
impl !Sync for WindowContainer
impl Unpin for WindowContainer
impl !UnwindSafe for WindowContainer
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