pub trait DrawingBackend {
type ErrorType: Error;
// Required methods
fn get_size(&self) -> (u32, u32);
fn ensure_prepared(
&mut self,
) -> Result<(), DrawingErrorKind<Self::ErrorType>>;
fn present(&mut self) -> Result<(), DrawingErrorKind<Self::ErrorType>>;
fn draw_pixel<S: Color>(
&mut self,
point: BackendCoord,
color: &S,
) -> Result<(), DrawingErrorKind<Self::ErrorType>>;
// Provided methods
fn draw_line<S: BackendStyle>(
&mut self,
from: BackendCoord,
to: BackendCoord,
style: &S,
) -> Result<(), DrawingErrorKind<Self::ErrorType>> { ... }
fn draw_rect<S: BackendStyle>(
&mut self,
upper_left: BackendCoord,
bottom_right: BackendCoord,
style: &S,
fill: bool,
) -> Result<(), DrawingErrorKind<Self::ErrorType>> { ... }
fn draw_path<S: BackendStyle, I: IntoIterator<Item = BackendCoord>>(
&mut self,
path: I,
style: &S,
) -> Result<(), DrawingErrorKind<Self::ErrorType>> { ... }
fn draw_circle<S: BackendStyle>(
&mut self,
center: BackendCoord,
radius: u32,
style: &S,
fill: bool,
) -> Result<(), DrawingErrorKind<Self::ErrorType>> { ... }
fn draw_text<'a, C: Color>(
&mut self,
text: &str,
font: &FontDesc<'a>,
pos: BackendCoord,
color: &C,
) -> Result<(), DrawingErrorKind<Self::ErrorType>> { ... }
}Expand description
The drawing backend trait, which implemenets the low-level drawing APIs.
This trait has a set of default implementation. And the minimal requirement of
implementing a drawing backend is implementing the draw_pixel function.
If the drawing backend supports vector graphics, the other drawing APIs should be overrided by the backend specific implementation. Otherwise, the default implementation will use the pixel-based approach to draw other types of low-level shapes.
Required Associated Types§
Required Methods§
Sourcefn ensure_prepared(&mut self) -> Result<(), DrawingErrorKind<Self::ErrorType>>
fn ensure_prepared(&mut self) -> Result<(), DrawingErrorKind<Self::ErrorType>>
Ensure the backend is ready to draw
Sourcefn present(&mut self) -> Result<(), DrawingErrorKind<Self::ErrorType>>
fn present(&mut self) -> Result<(), DrawingErrorKind<Self::ErrorType>>
Finialize the drawing step and present all the changes.
This is used as the real-time rendering support.
The backend may implement in the following way, when ensure_prepared is called
it checks if it needs a fresh buffer and present is called rendering all the
pending changes on the screen.
Sourcefn draw_pixel<S: Color>(
&mut self,
point: BackendCoord,
color: &S,
) -> Result<(), DrawingErrorKind<Self::ErrorType>>
fn draw_pixel<S: Color>( &mut self, point: BackendCoord, color: &S, ) -> Result<(), DrawingErrorKind<Self::ErrorType>>
Draw a pixel on the drawing backend
point: The backend pixel-based coordinate to drawcolor: The color of the pixel
Provided Methods§
Sourcefn draw_line<S: BackendStyle>(
&mut self,
from: BackendCoord,
to: BackendCoord,
style: &S,
) -> Result<(), DrawingErrorKind<Self::ErrorType>>
fn draw_line<S: BackendStyle>( &mut self, from: BackendCoord, to: BackendCoord, style: &S, ) -> Result<(), DrawingErrorKind<Self::ErrorType>>
Draw a line on the drawing backend
from: The start point of the lineto: The end point of the linestyle: The style of the line
Sourcefn draw_rect<S: BackendStyle>(
&mut self,
upper_left: BackendCoord,
bottom_right: BackendCoord,
style: &S,
fill: bool,
) -> Result<(), DrawingErrorKind<Self::ErrorType>>
fn draw_rect<S: BackendStyle>( &mut self, upper_left: BackendCoord, bottom_right: BackendCoord, style: &S, fill: bool, ) -> Result<(), DrawingErrorKind<Self::ErrorType>>
Draw a rectangle on the drawing backend
upper_left: The coordinate of the upper-left corner of the rectbottom_right: The coordinate of the bottom-right corner of the rectstyle: The stylefill: If the rectangle should be filled
Sourcefn draw_path<S: BackendStyle, I: IntoIterator<Item = BackendCoord>>(
&mut self,
path: I,
style: &S,
) -> Result<(), DrawingErrorKind<Self::ErrorType>>
fn draw_path<S: BackendStyle, I: IntoIterator<Item = BackendCoord>>( &mut self, path: I, style: &S, ) -> Result<(), DrawingErrorKind<Self::ErrorType>>
Draw a path on the drawing backend
path: The iterator of key points of the pathstyle: The style of the path
Sourcefn draw_circle<S: BackendStyle>(
&mut self,
center: BackendCoord,
radius: u32,
style: &S,
fill: bool,
) -> Result<(), DrawingErrorKind<Self::ErrorType>>
fn draw_circle<S: BackendStyle>( &mut self, center: BackendCoord, radius: u32, style: &S, fill: bool, ) -> Result<(), DrawingErrorKind<Self::ErrorType>>
Draw a circle on the drawing backend
center: The center coordinate of the circleradius: The radius of the circlestyle: The style of the shapefill: If the circle should be filled
Sourcefn draw_text<'a, C: Color>(
&mut self,
text: &str,
font: &FontDesc<'a>,
pos: BackendCoord,
color: &C,
) -> Result<(), DrawingErrorKind<Self::ErrorType>>
fn draw_text<'a, C: Color>( &mut self, text: &str, font: &FontDesc<'a>, pos: BackendCoord, color: &C, ) -> Result<(), DrawingErrorKind<Self::ErrorType>>
Draw a text on the drawing backend
text: The text to drawfont: The description of the fontpos: The position backendcolor: The color of the text
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".