DrawCommand

Trait DrawCommand 

Source
pub trait DrawCommand:
    DynClone
    + Downcast
    + Send
    + Sync {
    // Required method
    fn apply_opacity(&mut self, opacity: f32);

    // Provided methods
    fn sample_region(&self) -> Option<SampleRegion> { ... }
    fn draw_region(&self) -> DrawRegion { ... }
    fn ordering_rect(
        &self,
        _position: PxPosition,
        _size: PxSize,
    ) -> Option<PxRect> { ... }
}
Expand description

Trait for graphics rendering commands that can be processed by draw pipelines.

Implement this trait for structs that represent graphics operations such as shape drawing, text rendering, image display, or custom visual effects.

§Example

use tessera_ui::DrawCommand;

#[derive(Clone, PartialEq)]
struct RectangleCommand {
    color: [f32; 4],
    corner_radius: f32,
}

impl DrawCommand for RectangleCommand {
    fn apply_opacity(&mut self, opacity: f32) {
        self.color[3] *= opacity.clamp(0.0, 1.0);
    }
}

Required Methods§

Source

fn apply_opacity(&mut self, opacity: f32)

Applies an opacity multiplier to this command.

In most cases you must implement this on your command to support opacity changes in the UI.

Provided Methods§

Source

fn sample_region(&self) -> Option<SampleRegion>

Specifies sample requirements for this draw operation.

As a default implementation, this returns None, indicating that the command does not need to sample from previously rendered content.

Override this method if your command requires sampling from prior contents.

Source

fn draw_region(&self) -> DrawRegion

Specifies the drawing region for this command.

As a default implementation, this returns DrawRegion::PaddedLocal with zero padding, indicating that the command draws within its own bounds.

Override this method if your command draws to a different region but do not want to affect layout calculations.

Source

fn ordering_rect(&self, _position: PxPosition, _size: PxSize) -> Option<PxRect>

Returns an absolute rectangle used for ordering decisions.

The default implementation returns None, which falls back to the draw region derived from the command size and position.

Implementations§

Source§

impl dyn DrawCommand

Source

pub fn is<__T: DrawCommand>(&self) -> bool

Returns true if the trait object wraps an object of type __T.

Source

pub fn downcast<__T: DrawCommand>( self: Box<Self>, ) -> Result<Box<__T>, Box<Self>>

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn’t.

Source

pub fn downcast_rc<__T: DrawCommand>( self: Rc<Self>, ) -> Result<Rc<__T>, Rc<Self>>

Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of type __T. Returns the original Rc-ed trait if it isn’t.

Source

pub fn downcast_ref<__T: DrawCommand>(&self) -> Option<&__T>

Returns a reference to the object within the trait object if it is of type __T, or None if it isn’t.

Source

pub fn downcast_mut<__T: DrawCommand>(&mut self) -> Option<&mut __T>

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn’t.

Implementors§