Skip to main content

RenderBox

Trait RenderBox 

Source
pub trait RenderBox: RenderObject {
Show 44 methods // Required methods fn render_box_data(self: RenderHandle<Self>, app: &App) -> &RenderBoxData; fn render_box_data_mut( self: RenderHandle<Self>, app: &mut App, ) -> &mut RenderBoxData; // Provided methods fn constraints(self: RenderHandle<Self>, app: &App) -> BoxConstraints { ... } fn setup_parent_data( self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject, ) { ... } fn get_min_intrinsic_width( self: RenderHandle<Self>, app: &mut App, height: f64, ) -> f64 { ... } fn compute_min_intrinsic_width( self: RenderHandle<Self>, app: &mut App, height: f64, ) -> f64 { ... } fn get_max_intrinsic_width( self: RenderHandle<Self>, app: &mut App, height: f64, ) -> f64 { ... } fn compute_max_intrinsic_width( self: RenderHandle<Self>, app: &mut App, height: f64, ) -> f64 { ... } fn get_min_intrinsic_height( self: RenderHandle<Self>, app: &mut App, width: f64, ) -> f64 { ... } fn compute_min_intrinsic_height( self: RenderHandle<Self>, app: &mut App, width: f64, ) -> f64 { ... } fn get_max_intrinsic_height( self: RenderHandle<Self>, app: &mut App, width: f64, ) -> f64 { ... } fn compute_max_intrinsic_height( self: RenderHandle<Self>, app: &mut App, width: f64, ) -> f64 { ... } fn get_dry_layout( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, ) -> Size { ... } fn compute_dry_layout( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, ) -> Size { ... } fn get_dry_baseline( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, baseline: TextBaseline, ) -> Option<f64> { ... } fn compute_dry_baseline( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, baseline: TextBaseline, ) -> Option<f64> { ... } fn debug_cannot_compute_dry_layout( self: RenderHandle<Self>, failure: DryLayoutFailure<'_>, ) { ... } fn get_distance_to_baseline( self: RenderHandle<Self>, app: &mut App, baseline: TextBaseline, only_real: bool, ) -> Option<f64> { ... } fn get_distance_to_actual_baseline( self: RenderHandle<Self>, app: &mut App, baseline: TextBaseline, ) -> Option<f64> { ... } fn compute_distance_to_actual_baseline( self: RenderHandle<Self>, app: &mut App, baseline: TextBaseline, ) -> Option<f64> { ... } fn mark_needs_layout(self: RenderHandle<Self>, app: &mut App) { ... } fn perform_resize(self: RenderHandle<Self>, app: &mut App) { ... } fn size(self: RenderHandle<Self>, app: &App) -> Size { ... } fn apply_paint_transform( self: RenderHandle<Self>, app: &App, child: AnyRenderObject, transform: &mut Matrix4, ) { ... } fn paint_bounds(self: RenderHandle<Self>, app: &App) -> Rect { ... } fn has_size(self: RenderHandle<Self>, app: &App) -> bool { ... } fn handle_event( self: RenderHandle<Self>, app: &mut App, event: &PointerEvent, entry: &BoxHitTestEntry, ) { ... } fn hit_test( self: RenderHandle<Self>, app: &mut App, result: &mut BoxHitTestResult<'_>, position: Offset, ) -> bool { ... } fn hit_test_self( self: RenderHandle<Self>, _app: &App, _position: Offset, ) -> bool { ... } fn hit_test_children( self: RenderHandle<Self>, app: &mut App, result: &mut BoxHitTestResult<'_>, position: Offset, ) -> bool { ... } fn set_size(self: RenderHandle<Self>, app: &mut App, size: Size) { ... } fn layout( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, parent_uses_size: bool, ) { ... } fn as_box(self: RenderHandle<Self>) -> AnyRenderBox { ... } fn as_object(self: RenderHandle<Self>) -> AnyRenderObject { ... } fn adopt_child( self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject, ) { ... } fn drop_child( self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject, ) { ... } fn mark_needs_paint(self: RenderHandle<Self>, app: &mut App) { ... } fn mark_needs_composited_layer_update( self: RenderHandle<Self>, app: &mut App, ) { ... } fn mark_needs_compositing_bits_update( self: RenderHandle<Self>, app: &mut App, ) { ... } fn schedule_initial_layout(self: RenderHandle<Self>, app: &mut App) { ... } fn parent(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderObject> { ... } fn owner( self: RenderHandle<Self>, app: &App, ) -> Option<Handle<PipelineOwner>> { ... } fn attached(self: RenderHandle<Self>, app: &App) -> bool { ... } fn debug_needs_layout(self: RenderHandle<Self>, app: &App) -> bool { ... }
}
Expand description

A render object in a 2D Cartesian coordinate system.

Flutter’s counterpart is RenderBox. RenderObject::perform_layout is the leaf override; AnyRenderBox::layout is the framework wrapper. RenderObject’s tree operations are provided here and forward to as_object.

Required Methods§

Source

fn render_box_data(self: RenderHandle<Self>, app: &App) -> &RenderBoxData

Mixin field access.

Source

fn render_box_data_mut( self: RenderHandle<Self>, app: &mut App, ) -> &mut RenderBoxData

Provided Methods§

Source

fn constraints(self: RenderHandle<Self>, app: &App) -> BoxConstraints

The box constraints most recently supplied by the parent.

§Panics

If layout has not yet happened.

Source

fn setup_parent_data( self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject, )

Installs BoxParentData unless the child already has it.

The box default for RenderObject::setup_parent_data; override it here.

Source

fn get_min_intrinsic_width( self: RenderHandle<Self>, app: &mut App, height: f64, ) -> f64

Source

fn compute_min_intrinsic_width( self: RenderHandle<Self>, app: &mut App, height: f64, ) -> f64

Computes the value returned by get_min_intrinsic_width. Do not call this function directly, instead, call get_min_intrinsic_width.

Override in subclasses that implement RenderObject::perform_layout. This method should return the minimum width that this box could be without failing to correctly paint its contents within itself, without clipping.

If the layout algorithm is independent of the context (e.g. it always tries to be a particular size), or if the layout algorithm is width-in-height-out, or if the layout algorithm uses both the incoming width and height constraints (e.g. it always sizes itself to BoxConstraints::biggest), then the height argument should be ignored.

If the layout algorithm is strictly height-in-width-out, or is height-in-width-out when the width is unconstrained, then the height argument is the height to use.

The height argument will never be negative. It may be infinite.

If this algorithm depends on the intrinsic dimensions of a child, the intrinsic dimensions of that child should be obtained using the functions whose names start with get_, not compute_.

This function should never return a negative or infinite value.

§When the intrinsic dimensions cannot be known

There are cases where render objects do not have an efficient way to compute their intrinsic dimensions. For example, it may be prohibitively expensive to reify and measure every child of a lazy viewport, or the dimensions may be computed by a callback about which the render object cannot reason.

In such cases the intrinsic functions should panic when debug_checking_intrinsics is false and debug assertions are enabled, and return 0.0 otherwise. See RenderViewportBase::debug_throw_if_not_checking_intrinsics.

§Aspect-ratio-driven boxes

Some boxes always return a fixed size based on the constraints. For these boxes, the intrinsic functions should return the appropriate size when the incoming height or width argument is finite, treating that as a tight constraint in the respective direction and treating the other direction’s constraints as unbounded. When the incoming argument is not finite, then they should return the actual intrinsic dimensions based on the contents, as any other box would.

Source

fn get_max_intrinsic_width( self: RenderHandle<Self>, app: &mut App, height: f64, ) -> f64

Source

fn compute_max_intrinsic_width( self: RenderHandle<Self>, app: &mut App, height: f64, ) -> f64

Computes the value returned by get_max_intrinsic_width. Do not call this function directly, instead, call get_max_intrinsic_width.

Override in subclasses that implement RenderObject::perform_layout. This should return the smallest width beyond which increasing the width never decreases the preferred height. The preferred height is the value that would be returned by compute_min_intrinsic_height for that width.

If the layout algorithm is strictly height-in-width-out, or is height-in-width-out when the width is unconstrained, then this should return the same value as compute_min_intrinsic_width for the same height.

Otherwise, the height argument should be ignored, and the returned value should be equal to or bigger than the value returned by compute_min_intrinsic_width.

The value returned by this method might not match the size that the object would actually take. For example, a box that always exactly sizes itself using BoxConstraints::biggest might well size itself bigger than its max intrinsic size.

Source

fn get_min_intrinsic_height( self: RenderHandle<Self>, app: &mut App, width: f64, ) -> f64

Source

fn compute_min_intrinsic_height( self: RenderHandle<Self>, app: &mut App, width: f64, ) -> f64

Computes the value returned by get_min_intrinsic_height. Do not call this function directly, instead, call get_min_intrinsic_height.

Override in subclasses that implement RenderObject::perform_layout. Should return the minimum height that this box could be without failing to correctly paint its contents within itself, without clipping.

If the layout algorithm is independent of the context, or if the layout algorithm is height-in-width-out, or if the layout algorithm uses both the incoming height and width constraints, then the width argument should be ignored.

If the layout algorithm is strictly width-in-height-out, or is width-in-height-out when the height is unconstrained, then the width argument is the width to use.

The width argument will never be negative. It may be infinite.

Source

fn get_max_intrinsic_height( self: RenderHandle<Self>, app: &mut App, width: f64, ) -> f64

Source

fn compute_max_intrinsic_height( self: RenderHandle<Self>, app: &mut App, width: f64, ) -> f64

Computes the value returned by get_max_intrinsic_height. Do not call this function directly, instead, call get_max_intrinsic_height.

Override in subclasses that implement RenderObject::perform_layout. Should return the smallest height beyond which increasing the height never decreases the preferred width. The preferred width is the value that would be returned by compute_min_intrinsic_width for that height.

If the layout algorithm is strictly width-in-height-out, or is width-in-height-out when the height is unconstrained, then this should return the same value as compute_min_intrinsic_height for the same width.

Otherwise, the width argument should be ignored, and the returned value should be equal to or bigger than the value returned by compute_min_intrinsic_height.

Source

fn get_dry_layout( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, ) -> Size

Source

fn compute_dry_layout( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, ) -> Size

Computes the value returned by get_dry_layout. Do not call this function directly, instead, call get_dry_layout.

Override in subclasses that implement RenderObject::perform_layout or perform_resize, or when setting RenderObject::sized_by_parent to true without overriding perform_resize. This method should return the Size that this box would like to be given the provided BoxConstraints.

The size returned by this method must match the size that the box will compute for itself in RenderObject::perform_layout (or perform_resize, if RenderObject::sized_by_parent is true).

If this algorithm depends on the size of a child, the size of that child should be obtained using its get_dry_layout method.

§When the size cannot be known

There are cases where render objects do not have an efficient way to compute their size. For example, the size may be computed by a callback about which the render object cannot reason. In such cases, the function should call debug_cannot_compute_dry_layout and return Size::ZERO.

Source

fn get_dry_baseline( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, baseline: TextBaseline, ) -> Option<f64>

Source

fn compute_dry_baseline( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, baseline: TextBaseline, ) -> Option<f64>

Computes the value returned by get_dry_baseline.

This method is for overriding only and shouldn’t be called directly. To get this box’s speculative baseline location for the given constraints, call get_dry_baseline instead.

The “dry” in the method name means the implementation must not produce observable side effects when called. For example, it must not change the size of the box, or its children’s paint offsets. Moreover, accessing the current layout of this box or a child box usually indicates a bug in the implementation, as the current layout is typically calculated using a set of BoxConstraints that’s different from the constraints given as the first parameter. To get the size of this box or a child box in this method’s implementation, use get_dry_layout instead.

The implementation must return a value that represents the distance from the top of the box to the first baseline of the box’s contents, for the given constraints, or None if the box has no baselines. It’s the same exact value compute_distance_to_actual_baseline would return, when this box was laid out at constraints in the same exact state.

Not all boxes support dry baseline computation. In such cases the box must call debug_cannot_compute_dry_layout and return a dummy baseline offset value (such as None).

Source

fn debug_cannot_compute_dry_layout( self: RenderHandle<Self>, failure: DryLayoutFailure<'_>, )

Called from compute_dry_layout or compute_dry_baseline if this box does not support calculating a dry layout.

When debug assertions are enabled and debug_checking_intrinsics is not true, this method panics with the given DryLayoutFailure.

Source

fn get_distance_to_baseline( self: RenderHandle<Self>, app: &mut App, baseline: TextBaseline, only_real: bool, ) -> Option<f64>

Source

fn get_distance_to_actual_baseline( self: RenderHandle<Self>, app: &mut App, baseline: TextBaseline, ) -> Option<f64>

Source

fn compute_distance_to_actual_baseline( self: RenderHandle<Self>, app: &mut App, baseline: TextBaseline, ) -> Option<f64>

Returns the distance from the y-coordinate of the position of the box to the y-coordinate of the first given baseline in the box’s contents, if any, or None otherwise.

Do not call this function directly. If you need to know the baseline of a child from an invocation of RenderObject::perform_layout or RenderObject::paint, call get_distance_to_baseline.

Subclasses should override this method to supply the distances to their baselines. When implementing this method, there are generally three strategies:

Source

fn mark_needs_layout(self: RenderHandle<Self>, app: &mut App)

Mark this render object’s layout information as dirty.

Flutter’s RenderBox.markNeedsLayout: it also clears the intrinsics, dry layout and baseline caches, and defers to the parent when they held anything.

Source

fn perform_resize(self: RenderHandle<Self>, app: &mut App)

Updates the box’s size using only the constraints.

By default this method sets size to the result of compute_dry_layout called with the current constraints. Instead of overriding this method, consider overriding compute_dry_layout.

Source

fn size(self: RenderHandle<Self>, app: &App) -> Size

The size of this box.

Source

fn apply_paint_transform( self: RenderHandle<Self>, app: &App, child: AnyRenderObject, transform: &mut Matrix4, )

Multiply the transform from the parent’s coordinate system to this box’s coordinate system into the given transform.

This function is used to convert coordinate systems between boxes. Subclasses that apply transforms during painting should override this function to factor those transforms into the calculation.

The RenderBox implementation takes care of adjusting the matrix for the position of the given child as determined during layout and stored on the child’s parent data.

Source

fn paint_bounds(self: RenderHandle<Self>, app: &App) -> Rect

An estimate of the bounds within which this render object will paint: the box’s own size.

Source

fn has_size(self: RenderHandle<Self>, app: &App) -> bool

Whether this render object has undergone layout and has a size.

Source

fn handle_event( self: RenderHandle<Self>, app: &mut App, event: &PointerEvent, entry: &BoxHitTestEntry, )

Override this method to handle pointer events that hit this render object.

For RenderBox objects, the entry argument is a BoxHitTestEntry. From this object you can determine the position of the hit test in the local coordinates of the render object (via entry.local_position()).

Source

fn hit_test( self: RenderHandle<Self>, app: &mut App, result: &mut BoxHitTestResult<'_>, position: Offset, ) -> bool

Determines the set of render objects located at the given position.

Returns true, and adds any render objects that contain the point to the given hit test result, if this render object or one of its descendants absorbs the hit (preventing objects below this one from being hit). Returns false if the hit can continue to other objects below this one.

The caller is responsible for transforming position from global coordinates to its location relative to the origin of this RenderBox. This RenderBox is responsible for checking whether the given position is within its bounds.

§Panics

In debug builds, if this box has not been laid out.

Source

fn hit_test_self( self: RenderHandle<Self>, _app: &App, _position: Offset, ) -> bool

Override this method if this render object can be hit even if its children were not hit.

Returns true if the specified position should be considered a hit on this render object.

Source

fn hit_test_children( self: RenderHandle<Self>, app: &mut App, result: &mut BoxHitTestResult<'_>, position: Offset, ) -> bool

Override this method to check whether any children are located at the given position.

Subclasses should return true if at least one child reported a hit at the specified position.

Source

fn set_size(self: RenderHandle<Self>, app: &mut App, size: Size)

Sets the size of this box. Call from RenderObject::perform_layout or RenderObject::perform_resize.

Source

fn layout( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, parent_uses_size: bool, )

Source

fn as_box(self: RenderHandle<Self>) -> AnyRenderBox

The type-erased RenderBox handle. Free: the vtable is a const, and the id is copied.

Source

fn as_object(self: RenderHandle<Self>) -> AnyRenderObject

The type-erased RenderObject handle, through as_box.

Source

fn adopt_child(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject)

Source

fn drop_child(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject)

Source

fn mark_needs_paint(self: RenderHandle<Self>, app: &mut App)

Source

fn mark_needs_composited_layer_update(self: RenderHandle<Self>, app: &mut App)

Source

fn mark_needs_compositing_bits_update(self: RenderHandle<Self>, app: &mut App)

Source

fn schedule_initial_layout(self: RenderHandle<Self>, app: &mut App)

Source

fn parent(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderObject>

Source

fn owner(self: RenderHandle<Self>, app: &App) -> Option<Handle<PipelineOwner>>

Source

fn attached(self: RenderHandle<Self>, app: &App) -> bool

Source

fn debug_needs_layout(self: RenderHandle<Self>, app: &App) -> bool

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl RenderBox for RenderAbsorbPointer

Source§

impl RenderBox for RenderAnimatedOpacity

Source§

impl RenderBox for RenderAnimatedSize

Source§

impl RenderBox for RenderAspectRatio

Source§

impl RenderBox for RenderBackdropFilter

Source§

impl RenderBox for RenderBaseline

Source§

impl RenderBox for RenderClipOval

Source§

impl RenderBox for RenderClipPath

Source§

impl RenderBox for RenderClipRRect

Source§

impl RenderBox for RenderClipRSuperellipse

Source§

impl RenderBox for RenderClipRect

Source§

impl RenderBox for RenderColoredBox

Source§

impl RenderBox for RenderCompositionLayerView

Source§

impl RenderBox for RenderConstrainedBox

Source§

impl RenderBox for RenderConstrainedOverflowBox

Source§

impl RenderBox for RenderConstraintsTransformBox

Source§

impl RenderBox for RenderCustomMultiChildLayoutBox

Source§

impl RenderBox for RenderCustomPaint

Source§

impl RenderBox for RenderCustomSingleChildLayoutBox

Source§

impl RenderBox for RenderDecoratedBox

Source§

impl RenderBox for RenderEditable

Source§

impl RenderBox for RenderFittedBox

Source§

impl RenderBox for RenderFlex

Source§

impl RenderBox for RenderFollowerLayer

Source§

impl RenderBox for RenderFractionalTranslation

Source§

impl RenderBox for RenderFractionallySizedOverflowBox

Source§

impl RenderBox for RenderIgnorePointer

Source§

impl RenderBox for RenderImage

Source§

impl RenderBox for RenderIndexedStack

Source§

impl RenderBox for RenderIntrinsicHeight

Source§

impl RenderBox for RenderIntrinsicWidth

Source§

impl RenderBox for RenderLeaderLayer

Source§

impl RenderBox for RenderLimitedBox

Source§

impl RenderBox for RenderMetaData

Source§

impl RenderBox for RenderMouseRegion

Source§

impl RenderBox for RenderOffstage

Source§

impl RenderBox for RenderOpacity

Source§

impl RenderBox for RenderPadding

Source§

impl RenderBox for RenderParagraph

Source§

impl RenderBox for RenderPointerListener

Source§

impl RenderBox for RenderPositionedBox

Source§

impl RenderBox for RenderRepaintBoundary

Source§

impl RenderBox for RenderShrinkWrappingViewport

Source§

impl RenderBox for RenderSizedOverflowBox

Source§

impl RenderBox for RenderStack

Source§

impl RenderBox for RenderTable

Source§

impl RenderBox for RenderTransform

Source§

impl RenderBox for RenderVideoFrameView

Source§

impl RenderBox for RenderViewport

Source§

impl RenderBox for RenderWrap

Source§

impl<T: PartialEq + 'static> RenderBox for RenderAnnotatedRegion<T>