pub trait Painter {
// Required methods
fn push(&mut self, cmd: DrawCmd);
fn push_clipped(&mut self, cmd: DrawCmd, clip: Option<Rect>);
}Expand description
Minimal command sink accepted by legacy paint APIs.
Implementations decide how optional clips are represented. The built-in
PaintCtx implementation opens a nested rectangular clip layer.
§Examples
use ailloli_ui_core::{Color, Rect};
use ailloli_ui_runtime::scene::{DrawCmd, DrawRect, PaintCtx, Painter};
let mut painter = PaintCtx::new();
Painter::push(&mut painter, DrawCmd::Rect(DrawRect {
rect: Rect::new(0.0, 0.0, 2.0, 2.0), color: Color::WHITE,
}));
assert_eq!(painter.layers[0].cmds.len(), 1);Required Methods§
Sourcefn push(&mut self, cmd: DrawCmd)
fn push(&mut self, cmd: DrawCmd)
Submits one command without adding a clip.
§Examples
use ailloli_ui_core::{Color, Rect};
use ailloli_ui_runtime::scene::{DrawCmd, DrawRect, PaintCtx, Painter};
let mut painter = PaintCtx::new();
painter.push(DrawCmd::Rect(DrawRect { rect: Rect::new(0.0, 0.0, 1.0, 1.0), color: Color::WHITE }));
assert_eq!(painter.layers[0].cmds.len(), 1);Sourcefn push_clipped(&mut self, cmd: DrawCmd, clip: Option<Rect>)
fn push_clipped(&mut self, cmd: DrawCmd, clip: Option<Rect>)
Submits one command under clip, or unclipped when it is None.
§Examples
use ailloli_ui_core::{Color, Rect};
use ailloli_ui_runtime::scene::{DrawCmd, DrawRect, PaintCtx, Painter};
let mut painter = PaintCtx::new();
let clip = Rect::new(0.0, 0.0, 3.0, 3.0);
painter.push_clipped(DrawCmd::Rect(DrawRect { rect: clip, color: Color::WHITE }), Some(clip));
assert_eq!(painter.into_scene().layers[0].clip.scissor_rect(), Some(clip));Implementors§
impl<'a> Painter for PaintContext<'a>
Implements the Painter contract for PaintContext<'a>.