pub struct CustomPaint {
pub key: Option<KeyRef>,
pub painter: Option<Rc<dyn CustomPainter>>,
pub foreground_painter: Option<Rc<dyn CustomPainter>>,
pub size: Size,
pub is_complex: bool,
pub will_change: bool,
pub child: Option<WidgetRef>,
}Expand description
A widget that provides a canvas on which to draw during the paint phase.
When asked to paint, CustomPaint first asks its painter to paint on
the current canvas, then it paints its child, and then, after painting its child, it asks
its foreground_painter to paint. The coordinate system of the
canvas matches the coordinate system of the CustomPaint object. The painters are
expected to paint within a rectangle starting at the origin and encompassing a region of
the given size. (If the painters paint outside those bounds, there might be insufficient
memory allocated to rasterize the painting commands and the resulting behavior is
undefined.) To enforce painting within those bounds, consider wrapping this
CustomPaint with a ClipRect widget.
Painters are implemented by implementing CustomPainter.
Because custom paint calls its painters during paint, you cannot call
set_state or mark_needs_layout during the callback (the layout for this
frame has already happened).
Custom painters normally size themselves to their child. If they do not
have a child, they attempt to size themselves to the specified size, which
defaults to Size::ZERO. The parent may enforce constraints on this size.
The is_complex and will_change properties are
hints to the compositor’s raster cache.
See also:
CustomPainter, the trait to implement when creating custom painters.Canvas, the class that a custom painter uses to paint.
Fields§
§key: Option<KeyRef>§painter: Option<Rc<dyn CustomPainter>>The painter that paints before the children.
foreground_painter: Option<Rc<dyn CustomPainter>>The painter that paints after the children.
size: SizeThe size that this CustomPaint should aim for, given the layout
constraints, if there is no child.
Defaults to Size::ZERO.
If there’s a child, this is ignored, and the size of the child is used instead.
is_complex: boolWhether the painting is complex enough to benefit from caching.
The compositor contains a raster cache that holds bitmaps of layers in order to avoid the cost of repeatedly rendering those layers on each frame. If this flag is not set, then the compositor will apply its own heuristics to decide whether the layer containing this widget is complex enough to benefit from caching.
This flag can’t be set to true if both painter and
foreground_painter are None because this flag will be
ignored in such case.
will_change: boolWhether the raster cache should be told that this painting is likely to change in the next frame.
This hint tells the compositor not to cache the layer containing this widget because the cache will not be used in the future. If this hint is not set, the compositor will apply its own heuristics to decide whether the layer is likely to be reused in the future.
This flag can’t be set to true if both painter and
foreground_painter are None because this flag will be
ignored in such case.
child: Option<WidgetRef>Implementations§
Source§impl CustomPaint
impl CustomPaint
Sourcepub fn new() -> CustomPaint
pub fn new() -> CustomPaint
Creates a CustomPaint; Dart’s named arguments are the setters.
Sourcepub fn key(self, key: KeyRef) -> CustomPaint
pub fn key(self, key: KeyRef) -> CustomPaint
Dart CustomPaint(key:).
Sourcepub fn painter(self, painter: impl CustomPainter) -> CustomPaint
pub fn painter(self, painter: impl CustomPainter) -> CustomPaint
Dart CustomPaint(painter:).
Sourcepub fn foreground_painter(
self,
foreground_painter: impl CustomPainter,
) -> CustomPaint
pub fn foreground_painter( self, foreground_painter: impl CustomPainter, ) -> CustomPaint
Dart CustomPaint(foregroundPainter:).
Sourcepub fn size(self, size: Size) -> CustomPaint
pub fn size(self, size: Size) -> CustomPaint
Dart CustomPaint(size:).
Sourcepub fn is_complex(self, is_complex: bool) -> CustomPaint
pub fn is_complex(self, is_complex: bool) -> CustomPaint
Dart CustomPaint(isComplex:).
Sourcepub fn will_change(self, will_change: bool) -> CustomPaint
pub fn will_change(self, will_change: bool) -> CustomPaint
Dart CustomPaint(willChange:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> CustomPaint
pub fn child<K>(self, child: impl IntoWidget<K>) -> CustomPaint
Dart CustomPaint(child:).
Trait Implementations§
Source§impl Debug for CustomPaint
impl Debug for CustomPaint
Source§impl Default for CustomPaint
impl Default for CustomPaint
Source§fn default() -> CustomPaint
fn default() -> CustomPaint
Source§impl RenderObjectWidget for CustomPaint
impl RenderObjectWidget for CustomPaint
Source§type RenderObject = RenderCustomPaint
type RenderObject = RenderCustomPaint
covariant RenderObject parameter type.Source§fn create_render_object(
&self,
app: &mut App,
_context: BuildContext,
) -> AnyRenderObject
fn create_render_object( &self, app: &mut App, _context: BuildContext, ) -> AnyRenderObject
RenderObject class that this widget represents, using the
configuration described by this widget. Read moreSource§fn update_render_object(
&self,
app: &mut App,
_context: BuildContext,
render_object: RenderHandle<RenderCustomPaint>,
)
fn update_render_object( &self, app: &mut App, _context: BuildContext, render_object: RenderHandle<RenderCustomPaint>, )
create_render_object. Read moreSource§fn did_unmount_render_object(
&self,
app: &mut App,
render_object: RenderHandle<RenderCustomPaint>,
)
fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<RenderCustomPaint>, )
RenderObject will be of the same type as returned by this object’s
create_render_object.Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
toStringShort, for a widget that names itself apart from its type, as
SizedBox.expand does; see Widget::to_string_short.Source§fn debug_visit_onstage_children(
&self,
app: &App,
children: &[AnyElement],
visitor: &mut dyn FnMut(AnyElement),
)
fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )
debugVisitOnstageChildren of the element this widget makes, for a widget whose
Dart element subclass overrides it only to hide children (_OffstageElement,
_IndexedStackElement): calls visitor for each of children, in order, that is
onstage. Waft’s generic single- and multi-child elements stand in for those subclasses
and ask their widget here; an element of a widget’s own overrides
Element::debug_visit_onstage_children instead.Auto Trait Implementations§
impl !RefUnwindSafe for CustomPaint
impl !Send for CustomPaint
impl !Sync for CustomPaint
impl !UnwindSafe for CustomPaint
impl Forget for CustomPaint
impl Freeze for CustomPaintwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn CustomPainter> is !null: Freeze,
PhantomData<RcInner<dyn CustomPainter>>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
impl Move for CustomPaint
impl Unpin for CustomPaint
impl UnsafeUnpin for CustomPaintwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn CustomPainter> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn CustomPainter>>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<SingleChildRenderObjectKind> for Wwhere
W: SingleChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: RenderObjectWithChildMixin,
impl<W> IntoWidget<SingleChildRenderObjectKind> for Wwhere
W: SingleChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: RenderObjectWithChildMixin,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.