pub trait Painter {
// Required methods
fn cache_policy(&self) -> CachePolicy;
fn fill(&mut self, color: Color);
fn fill_rect(&mut self, bounds: Rect, color: Color);
fn rect(&mut self, bounds: Rect, color: Color);
fn line(&mut self, from: Point, to: Point, color: Color);
fn text(
&mut self,
bounds: Rect,
style: &TextStyle,
color: Color,
msg: &str,
) -> Size;
fn line_height(&mut self, style: &TextStyle) -> u32;
fn text_width(&mut self, style: &TextStyle, msg: &str) -> u32;
fn image(&mut self, path: &str, bounds: Rect) -> Result<(), Error>;
fn dither(&mut self, bounds: Rect, first: Color, second: Color);
fn dither_overlay(&mut self, bounds: Rect, color: Color);
fn clip(&mut self, bounds: Option<Rect>);
}Expand description
The drawing operations a Widget’s paint can use. Kept small: only what the helpers in this
module need.
Coordinates are relative to the Widget’s own upper left-hand corner. A backend decides where
the pixels go (a GPU texture, a memory buffer, the screen with clipping).
Required Methods§
Sourcefn cache_policy(&self) -> CachePolicy
fn cache_policy(&self) -> CachePolicy
Sourcefn rect(&mut self, bounds: Rect, color: Color)
fn rect(&mut self, bounds: Rect, color: Color)
Draws a one-pixel rectangle outline.
§Arguments
bounds- The rectangle to outline.color- The line color.
Sourcefn line(&mut self, from: Point, to: Point, color: Color)
fn line(&mut self, from: Point, to: Point, color: Color)
Draws a one-pixel line.
§Arguments
from- The start point.to- The end point.color- The line color.
Sourcefn text(
&mut self,
bounds: Rect,
style: &TextStyle,
color: Color,
msg: &str,
) -> Size
fn text( &mut self, bounds: Rect, style: &TextStyle, color: Color, msg: &str, ) -> Size
Draws text within a rectangle, aligned by style, wrapped at the rectangle’s width, and
centered vertically when it fits (top-aligned when it doesn’t).
§Arguments
bounds- The rectangle to draw within.style- The font and alignment.color- The text color (overridesstyle.font_color).msg- The text to draw.
§Returns
The size of the text drawn; 0 by 0 if nothing was drawn.
Sourcefn line_height(&mut self, style: &TextStyle) -> u32
fn line_height(&mut self, style: &TextStyle) -> u32
Sourcefn text_width(&mut self, style: &TextStyle, msg: &str) -> u32
fn text_width(&mut self, style: &TextStyle, msg: &str) -> u32
Sourcefn image(&mut self, path: &str, bounds: Rect) -> Result<(), Error>
fn image(&mut self, path: &str, bounds: Rect) -> Result<(), Error>
Draws an image file, scaled to a rectangle.
§Arguments
path- Path to the image file.bounds- The rectangle to draw into.
§Returns
Ok(()) once the image is drawn.
§Errors
Returns Error::Image if the image cannot be loaded or drawn.
Sourcefn dither(&mut self, bounds: Rect, first: Color, second: Color)
fn dither(&mut self, bounds: Rect, first: Color, second: Color)
Fills a rectangle with a 50% checkerboard of two colors, for backends and displays with few
colors. The pixel at the rectangle’s upper left-hand corner is first.
§Arguments
bounds- The rectangle to fill.first- The color of the corner pixel.second- The other color.
Sourcefn dither_overlay(&mut self, bounds: Rect, color: Color)
fn dither_overlay(&mut self, bounds: Rect, color: Color)
Draws a color over every other pixel of a rectangle (the pixels a dither
would draw in first), blending with what is already there and leaving the other pixels
untouched. The pixel at the rectangle’s upper left-hand corner is drawn.
§Arguments
bounds- The rectangle to draw over.color- The color to blend; its alpha sets the strength.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".