pub struct Renderer { /* private fields */ }
Expand description
This is the core of the library. It will send commands to the rendering server to print on screen.
§Usage
// get the renderer
let rdr = Renderer::get();
...
// start drawing on a frame
rdr.begin_draw();
... // use drawing functions (eg. draw_rect, draw_point...)
rdr.end_draw(); // this pushes the frame to the screen
...
Renderer::exit(); // to quit the program and reset terminal settings
Screen coordinates start in the top left at (0, 0)
Implementations§
Source§impl Renderer
impl Renderer
Sourcepub fn exit()
pub fn exit()
Exits the program and reset terminal setttings (should be called before the program ends).
Sourcepub fn get_size() -> Vec2
pub fn get_size() -> Vec2
Returns the screen dimension.
let size = Renderer::get_size();
size.x // width of the screen
size.y // height of the screen
Sourcepub fn begin_draw(&mut self)
pub fn begin_draw(&mut self)
Starts drawing a frame.
Will panic if called twice before an end_draw
Sourcepub fn clear_color(&mut self, c: Color)
pub fn clear_color(&mut self, c: Color)
Sets all the pixels’ color in the screen to c
(does not clear text).
Sourcepub fn clear_text(&mut self)
pub fn clear_text(&mut self)
Removes all text from the screen.
Sourcepub fn draw_line<A, B>(&mut self, p1: A, p2: B, c: Color)
pub fn draw_line<A, B>(&mut self, p1: A, p2: B, c: Color)
Draws a line of color c
between p1
and p2
.
Sourcepub fn draw_rect<A, B>(&mut self, p: A, s: B, c: Color)
pub fn draw_rect<A, B>(&mut self, p: A, s: B, c: Color)
Draws a rectangle of color c
and of size s
.
p
is the coordinate of the top left corner of the rectangle.
Sourcepub fn draw_rect_boundary<A, B>(&mut self, p: A, s: B, c: Color)
pub fn draw_rect_boundary<A, B>(&mut self, p: A, s: B, c: Color)
Same as draw_rect
but draws only the four sides of the rectangle.
Sourcepub fn draw_ellipse_boundary<A, B>(&mut self, c: A, s: B, col: Color)
pub fn draw_ellipse_boundary<A, B>(&mut self, c: A, s: B, col: Color)
Draws an ellipse of color col
. c
is the center of the ellipse and s
is the size of the rectangle
in which the ellipse is inscribed.
Sourcepub fn draw_point<A>(&mut self, p: A, c: Color)
pub fn draw_point<A>(&mut self, p: A, c: Color)
Sets the color of the pixel at p
to c
.
Sourcepub fn draw_image<A, B, C>(
&mut self,
img: Arc<Mutex<Image>>,
pos: A,
size: B,
offset: C,
alpha: Option<Color>,
)
pub fn draw_image<A, B, C>( &mut self, img: Arc<Mutex<Image>>, pos: A, size: B, offset: C, alpha: Option<Color>, )
Draws an image at position pos
.
Negative size results in flipped image. Alpha is used to ignore a given color while drawing.
Sourcepub fn draw_whole_image_alpha<A>(
&mut self,
img: Arc<Mutex<Image>>,
pos: A,
alpha: Color,
)
pub fn draw_whole_image_alpha<A>( &mut self, img: Arc<Mutex<Image>>, pos: A, alpha: Color, )
Draws the whole image at pos
, ignoring the color alpha
.
Equivalent to:
rdr.image(img, pos, img.size(), Vec2::ZERO, Some(alpha));
Sourcepub fn draw_whole_image<A>(&mut self, img: Arc<Mutex<Image>>, pos: A)
pub fn draw_whole_image<A>(&mut self, img: Arc<Mutex<Image>>, pos: A)
Draws the whole image at pos
.
Equivalent to:
rdr.image(img, pos, img.size(), Vec2::ZERO, None);
pub fn print_text_raw<A>( &mut self, text: &String, pos: A, background_mode: CharBackgroundMode, foreground_mode: CharForegroundMode, )
pub fn print_blended_text_raw<A>(&mut self, text: &String, pos: A)
pub fn print_colored_text_raw<A>( &mut self, text: &String, pos: A, background_color: Color, foreground_color: Color, )
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Renderer
impl !RefUnwindSafe for Renderer
impl Send for Renderer
impl Sync for Renderer
impl Unpin for Renderer
impl !UnwindSafe for Renderer
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters
when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle
.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other
into Self
, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T
.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters
when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self
into T
, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors
fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains
the unclamped color. Read more