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§
Sourcefn render_box_data(self: RenderHandle<Self>, app: &App) -> &RenderBoxData
fn render_box_data(self: RenderHandle<Self>, app: &App) -> &RenderBoxData
Mixin field access.
Sourcefn render_box_data_mut(
self: RenderHandle<Self>,
app: &mut App,
) -> &mut RenderBoxData
fn render_box_data_mut( self: RenderHandle<Self>, app: &mut App, ) -> &mut RenderBoxData
See render_box_data.
Provided Methods§
Sourcefn constraints(self: RenderHandle<Self>, app: &App) -> BoxConstraints
fn constraints(self: RenderHandle<Self>, app: &App) -> BoxConstraints
Sourcefn setup_parent_data(
self: RenderHandle<Self>,
app: &mut App,
child: AnyRenderObject,
)
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.
Sourcefn get_min_intrinsic_width(
self: RenderHandle<Self>,
app: &mut App,
height: f64,
) -> f64
fn get_min_intrinsic_width( self: RenderHandle<Self>, app: &mut App, height: f64, ) -> f64
Sourcefn compute_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
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.
Sourcefn get_max_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
Sourcefn compute_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
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.
Sourcefn get_min_intrinsic_height(
self: RenderHandle<Self>,
app: &mut App,
width: f64,
) -> f64
fn get_min_intrinsic_height( self: RenderHandle<Self>, app: &mut App, width: f64, ) -> f64
Sourcefn compute_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
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.
Sourcefn get_max_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
Sourcefn compute_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
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.
Sourcefn get_dry_layout(
self: RenderHandle<Self>,
app: &mut App,
constraints: BoxConstraints,
) -> Size
fn get_dry_layout( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, ) -> Size
Sourcefn compute_dry_layout(
self: RenderHandle<Self>,
app: &mut App,
constraints: BoxConstraints,
) -> Size
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.
Sourcefn get_dry_baseline(
self: RenderHandle<Self>,
app: &mut App,
constraints: BoxConstraints,
baseline: TextBaseline,
) -> Option<f64>
fn get_dry_baseline( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, baseline: TextBaseline, ) -> Option<f64>
Sourcefn compute_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>
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).
Sourcefn debug_cannot_compute_dry_layout(
self: RenderHandle<Self>,
failure: DryLayoutFailure<'_>,
)
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.
Sourcefn get_distance_to_baseline(
self: RenderHandle<Self>,
app: &mut App,
baseline: TextBaseline,
only_real: bool,
) -> Option<f64>
fn get_distance_to_baseline( self: RenderHandle<Self>, app: &mut App, baseline: TextBaseline, only_real: bool, ) -> Option<f64>
Sourcefn get_distance_to_actual_baseline(
self: RenderHandle<Self>,
app: &mut App,
baseline: TextBaseline,
) -> Option<f64>
fn get_distance_to_actual_baseline( self: RenderHandle<Self>, app: &mut App, baseline: TextBaseline, ) -> Option<f64>
Sourcefn compute_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>
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:
-
For classes that use the
ContainerRenderObjectMixinchild model, consider implementingRenderBoxContainerDefaultsMixinand usingRenderBoxContainerDefaultsMixin::default_compute_distance_to_first_actual_baseline. -
For classes that define a particular baseline themselves, return that value directly.
-
For classes that have a child to which they wish to defer the computation, call
get_distance_to_actual_baselineon the child.
Sourcefn mark_needs_layout(self: RenderHandle<Self>, app: &mut App)
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.
Sourcefn perform_resize(self: RenderHandle<Self>, app: &mut App)
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.
Sourcefn size(self: RenderHandle<Self>, app: &App) -> Size
fn size(self: RenderHandle<Self>, app: &App) -> Size
The size of this box.
Sourcefn apply_paint_transform(
self: RenderHandle<Self>,
app: &App,
child: AnyRenderObject,
transform: &mut Matrix4,
)
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.
Sourcefn paint_bounds(self: RenderHandle<Self>, app: &App) -> Rect
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.
Sourcefn has_size(self: RenderHandle<Self>, app: &App) -> bool
fn has_size(self: RenderHandle<Self>, app: &App) -> bool
Whether this render object has undergone layout and has a size.
Sourcefn handle_event(
self: RenderHandle<Self>,
app: &mut App,
event: &PointerEvent,
entry: &BoxHitTestEntry,
)
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()).
Sourcefn hit_test(
self: RenderHandle<Self>,
app: &mut App,
result: &mut BoxHitTestResult<'_>,
position: Offset,
) -> bool
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.
Sourcefn hit_test_self(
self: RenderHandle<Self>,
_app: &App,
_position: Offset,
) -> bool
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.
Sourcefn hit_test_children(
self: RenderHandle<Self>,
app: &mut App,
result: &mut BoxHitTestResult<'_>,
position: Offset,
) -> bool
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.
Sourcefn set_size(self: RenderHandle<Self>, app: &mut App, size: Size)
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.
Sourcefn layout(
self: RenderHandle<Self>,
app: &mut App,
constraints: BoxConstraints,
parent_uses_size: bool,
)
fn layout( self: RenderHandle<Self>, app: &mut App, constraints: BoxConstraints, parent_uses_size: bool, )
See AnyRenderBox::layout.
Sourcefn as_box(self: RenderHandle<Self>) -> AnyRenderBox
fn as_box(self: RenderHandle<Self>) -> AnyRenderBox
The type-erased RenderBox handle. Free: the vtable is a const, and the id is copied.
Sourcefn as_object(self: RenderHandle<Self>) -> AnyRenderObject
fn as_object(self: RenderHandle<Self>) -> AnyRenderObject
The type-erased RenderObject handle, through as_box.
Sourcefn adopt_child(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject)
fn adopt_child(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject)
Sourcefn drop_child(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject)
fn drop_child(self: RenderHandle<Self>, app: &mut App, child: AnyRenderObject)
Sourcefn mark_needs_paint(self: RenderHandle<Self>, app: &mut App)
fn mark_needs_paint(self: RenderHandle<Self>, app: &mut App)
Sourcefn mark_needs_composited_layer_update(self: RenderHandle<Self>, app: &mut App)
fn mark_needs_composited_layer_update(self: RenderHandle<Self>, app: &mut App)
Sourcefn mark_needs_compositing_bits_update(self: RenderHandle<Self>, app: &mut App)
fn mark_needs_compositing_bits_update(self: RenderHandle<Self>, app: &mut App)
Sourcefn schedule_initial_layout(self: RenderHandle<Self>, app: &mut App)
fn schedule_initial_layout(self: RenderHandle<Self>, app: &mut App)
Sourcefn parent(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderObject>
fn parent(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderObject>
Sourcefn owner(self: RenderHandle<Self>, app: &App) -> Option<Handle<PipelineOwner>>
fn owner(self: RenderHandle<Self>, app: &App) -> Option<Handle<PipelineOwner>>
Sourcefn attached(self: RenderHandle<Self>, app: &App) -> bool
fn attached(self: RenderHandle<Self>, app: &App) -> bool
Sourcefn debug_needs_layout(self: RenderHandle<Self>, app: &App) -> bool
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".