pub struct DisplayList { /* private fields */ }Expand description
A flat list of display items in paint order, ready for a renderer to replay.
The list is rebuilt from the widget tree whenever a node paints. Clips are
nested, so every DisplayItem::PushClip needs a later
DisplayItem::PopClip, which DisplayList::finish checks in debug
builds. Offsets nest the same way with DisplayItem::PushOffset and
DisplayItem::PopOffset.
Implementations§
Source§impl DisplayList
impl DisplayList
Sourcepub fn new() -> DisplayList
pub fn new() -> DisplayList
Creates an empty list.
use smudge_core::geometry::{Color, Corners, Rect};
use smudge_core::paint::{DisplayList, PaintOp};
let mut list = DisplayList::new();
list.push_op(PaintOp::FillRect {
rect: Rect::new(0.0, 0.0, 8.0, 8.0),
radius: Corners::ZERO,
color: Color::BLACK,
});
list.finish();
assert_eq!(list.len(), 1);Sourcepub fn extend_ops(&mut self, ops: &[PaintOp])
pub fn extend_ops(&mut self, ops: &[PaintOp])
Appends several drawing operations in order.
Sourcepub fn push_clip(&mut self, rect: Rect)
pub fn push_clip(&mut self, rect: Rect)
Starts a clip to rect, which applies to every following item until the
matching DisplayList::pop_clip.
Sourcepub fn pop_clip(&mut self)
pub fn pop_clip(&mut self)
Ends the most recent clip.
Callers must pair every call with an earlier
DisplayList::push_clip. DisplayList::finish reports an imbalance
in debug builds.
Sourcepub fn push_offset(&mut self, offset: Point)
pub fn push_offset(&mut self, offset: Point)
Starts an offset scope, which translates every following item by
offset until the matching DisplayList::pop_offset.
Scopes nest with clips and with each other. A clip pushed inside a scope holds its rectangle in the scope’s coordinates, so it moves with the scope.
Sourcepub fn pop_offset(&mut self)
pub fn pop_offset(&mut self)
Ends the most recent offset scope.
Callers must pair every call with an earlier
DisplayList::push_offset. DisplayList::finish reports an
imbalance in debug builds.
Sourcepub fn items(&self) -> &[DisplayItem]
pub fn items(&self) -> &[DisplayItem]
Returns the items in paint order.
Sourcepub fn finish(&mut self)
pub fn finish(&mut self)
Completes a build of the list.
The frame calls this once after rebuilding the list and before handing it to a renderer. In release builds it does nothing, because an unbalanced list is an internal invariant violation rather than input from outside the library.
§Panics
Panics in debug builds when a DisplayItem::PushClip has no matching
DisplayItem::PopClip, when a PopClip appears with no clip open,
or when an offset scope is unbalanced the same way.