Skip to main content

Painter

Trait Painter 

Source
pub trait Painter {
    // Required methods
    fn clear(&mut self, color: Rgba);
    fn draw_text_box(&mut self, rect: TileRect, color: Rgba);
    fn draw_text(&mut self, pos: TilePos, text: &str, color: Rgba);
    fn draw_glyph(&mut self, pos: TilePos, glyph: char, color: Rgba);
    fn draw_pixel_rect(
        &mut self,
        px: u32,
        py: u32,
        pw: u32,
        ph: u32,
        color: Rgba,
    );
    fn draw_gb_tile(
        &mut self,
        pos: TilePos,
        tile_id: u8,
        fallback: &str,
        color: Rgba,
    );

    // Provided methods
    fn draw_text_px(&mut self, px: u32, py: u32, text: &str, color: Rgba) { ... }
    fn measure_text_px(&self, text: &str) -> u32 { ... }
    fn draw_text_px_scaled(
        &mut self,
        px: u32,
        py: u32,
        text: &str,
        scale: u32,
        color: Rgba,
    ) { ... }
    fn measure_text_px_scaled(&self, text: &str, scale: u32) -> u32 { ... }
    fn supports_proportional(&self) -> bool { ... }
    fn draw_rgba(
        &mut self,
        dst_px: u32,
        dst_py: u32,
        dst_w: u32,
        dst_h: u32,
        pixels: &[Rgba],
        src_w: u32,
        src_h: u32,
        flip_x: bool,
        flip_y: bool,
    ) { ... }
}

Required Methods§

Source

fn clear(&mut self, color: Rgba)

Source

fn draw_text_box(&mut self, rect: TileRect, color: Rgba)

Source

fn draw_text(&mut self, pos: TilePos, text: &str, color: Rgba)

Source

fn draw_glyph(&mut self, pos: TilePos, glyph: char, color: Rgba)

Source

fn draw_pixel_rect(&mut self, px: u32, py: u32, pw: u32, ph: u32, color: Rgba)

Source

fn draw_gb_tile( &mut self, pos: TilePos, tile_id: u8, fallback: &str, color: Rgba, )

Pixel backend draws tile_id via the fallback text glyph. Recording backends log only tile_id.

Provided Methods§

Source

fn draw_text_px(&mut self, px: u32, py: u32, text: &str, color: Rgba)

Draw text starting at pixel (px, py) with proportional per-glyph advance. Default: round to the nearest tile and use Painter::draw_text.

Source

fn measure_text_px(&self, text: &str) -> u32

The pixel width text would occupy via Painter::draw_text_px. Default: 8px per char (the tile cell width).

Source

fn draw_text_px_scaled( &mut self, px: u32, py: u32, text: &str, scale: u32, color: Rgba, )

Draw text at pixel (px, py) scaled by an integer factor — every glyph pixel becomes a scale × scale block. Powers big title/heading text. The default ignores scale and falls back to Painter::draw_text_px, so recording/mock backends stay unchanged; pixel backends override it.

Source

fn measure_text_px_scaled(&self, text: &str, scale: u32) -> u32

The pixel width text occupies via Painter::draw_text_px_scaled. Default: Painter::measure_text_px × scale.

Source

fn supports_proportional(&self) -> bool

Whether this backend renders true proportional pixel text (overrides the two methods above). The layout engine only takes its proportional path when this is true, so recording/mock backends stay on the tile path.

Source

fn draw_rgba( &mut self, dst_px: u32, dst_py: u32, dst_w: u32, dst_h: u32, pixels: &[Rgba], src_w: u32, src_h: u32, flip_x: bool, flip_y: bool, )

Blit a full-colour src_w × src_h RGBA image (row-major) into the pixel box (dst_px, dst_py, dst_w, dst_h), nearest-neighbour scaled to fill the box. Fully-transparent (a == 0) source pixels are skipped; flip_x/ flip_y mirror the source. Used by the layout engine’s image element.

Default: per-destination-pixel via Painter::draw_pixel_rect, so every existing backend (incl. recording/mock painters) works unchanged; pixel backends may override for speed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§