Skip to main content

CustomPaint

Struct CustomPaint 

Source
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: Size

The 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: bool

Whether 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: bool

Whether 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

Source

pub fn new() -> CustomPaint

Creates a CustomPaint; Dart’s named arguments are the setters.

Source

pub fn key(self, key: KeyRef) -> CustomPaint

Dart CustomPaint(key:).

Source

pub fn painter(self, painter: impl CustomPainter) -> CustomPaint

Dart CustomPaint(painter:).

Source

pub fn foreground_painter( self, foreground_painter: impl CustomPainter, ) -> CustomPaint

Dart CustomPaint(foregroundPainter:).

Source

pub fn size(self, size: Size) -> CustomPaint

Dart CustomPaint(size:).

Source

pub fn is_complex(self, is_complex: bool) -> CustomPaint

Dart CustomPaint(isComplex:).

Source

pub fn will_change(self, will_change: bool) -> CustomPaint

Dart CustomPaint(willChange:).

Source

pub fn child<K>(self, child: impl IntoWidget<K>) -> CustomPaint

Dart CustomPaint(child:).

Trait Implementations§

Source§

impl Debug for CustomPaint

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CustomPaint

Source§

fn default() -> CustomPaint

Returns the “default value” for a type. Read more
Source§

impl RenderObjectWidget for CustomPaint

Source§

type RenderObject = RenderCustomPaint

The render object this widget creates; Dart’s covariant RenderObject parameter type.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_render_object( &self, app: &mut App, _context: BuildContext, ) -> AnyRenderObject

Creates an instance of the RenderObject class that this widget represents, using the configuration described by this widget. Read more
Source§

fn update_render_object( &self, app: &mut App, _context: BuildContext, render_object: RenderHandle<RenderCustomPaint>, )

Copies the configuration described by this widget to the given render object, which will be of the same type as returned by this object’s create_render_object. Read more
Source§

fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<RenderCustomPaint>, )

A render object previously associated with this widget has been removed from the tree. The given 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, )

Dart’s 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

Dart’s toStringShort, for a widget that names itself apart from its type, as SizedBox.expand does; see Widget::to_string_short.
Source§

fn debug_check_constructor(&self)

Source§

fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )

Dart’s 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.
Source§

impl SingleChildRenderObjectWidget for CustomPaint

Source§

fn child(&self) -> Option<&WidgetRef>

The widget below this widget in the tree.
Source§

fn create_element(&self, app: &mut App, this: WidgetRef) -> AnyElement
where Self: Sized,

Creates the element that manages this widget’s child. Read more

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 CustomPaint
where *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
where Rc<dyn Key>: Unpin, Rc<dyn CustomPainter>: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for CustomPaint
where *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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<SingleChildRenderObjectKind> for W

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>