Skip to main content

ConstraintsTransformBox

Struct ConstraintsTransformBox 

Source
pub struct ConstraintsTransformBox {
    pub key: Option<KeyRef>,
    pub text_direction: Option<TextDirection>,
    pub alignment: AlignmentGeometry,
    pub constraints_transform: BoxConstraintsTransform,
    pub clip_behavior: Clip,
    pub debug_transform_type: String,
    pub child: Option<WidgetRef>,
}
Expand description

A container widget that applies an arbitrary transform to its constraints, and sizes its child using the resulting BoxConstraints, optionally clipping, or treating the overflow as an error.

This container sizes its child using a BoxConstraints created by applying constraints_transform to its own constraints. This container will then attempt to adopt the same size, within the limits of its own constraints. If it ends up with a different size, it will align the child based on alignment. If the container cannot expand enough to accommodate the entire child, the child will be clipped if clip_behavior is not Clip::None.

When child is None, this widget becomes as small as possible and never overflows.

This widget can be used to ensure some of the child’s natural dimensions are honored. For instance, if the child requires a minimum height to fully display its content, constraints_transform can be set to max_height_unconstrained, so that the child may still grow vertically when the parent fails to provide enough vertical space:

ConstrainedBox::new(BoxConstraints::new().min_height(40.0).max_height(100.0)).child(
    ConstraintsTransformBox::new(ConstraintsTransformBox::max_height_unconstrained)
        .child(Text::new("Hello World!")),
)

See also:

  • ConstrainedBox, which renders a box which imposes constraints on its child.
  • OverflowBox, a widget that imposes additional constraints on its child, and allows the child to overflow itself.
  • UnconstrainedBox which allows its children to render themselves unconstrained and expands to fit them.

Fields§

§key: Option<KeyRef>§text_direction: Option<TextDirection>

The text direction to use when interpreting the alignment if it is an AlignmentDirectional.

Defaults to None, in which case Directionality::maybe_of is used to determine the text direction.

§alignment: AlignmentGeometry

The alignment to use when laying out the child, if it has a different size than this widget.

If this is an AlignmentDirectional, then text_direction must not be None.

See also:

  • Alignment for non-Directionality-aware alignments.
  • AlignmentDirectional for Directionality-aware alignments.
§constraints_transform: BoxConstraintsTransform

The function used to transform the incoming BoxConstraints, to size child.

The function must return a BoxConstraints that is normalized.

See ConstraintsTransformBox for predefined common BoxConstraintsTransforms.

§clip_behavior: Clip

How to clip a child that overflows this box.

Defaults to Clip::None.

§debug_transform_type: String

A description of the transform to show in a dump, when it is not one of the predefined transforms this widget knows.

§child: Option<WidgetRef>

Implementations§

Source§

impl ConstraintsTransformBox

Source

pub fn new( constraints_transform: BoxConstraintsTransform, ) -> ConstraintsTransformBox

Creates a widget that uses a function to transform the constraints it passes to its child; Dart’s optional named arguments are the setters.

Source

pub fn debug_transform_type( self, debug_transform_type: impl Into<String>, ) -> ConstraintsTransformBox

Dart ConstraintsTransformBox(debugTransformType:).

Source

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

Dart ConstraintsTransformBox(key:).

Source

pub fn text_direction( self, text_direction: TextDirection, ) -> ConstraintsTransformBox

Dart ConstraintsTransformBox(textDirection:).

Source

pub fn alignment(self, alignment: AlignmentGeometry) -> ConstraintsTransformBox

Dart ConstraintsTransformBox(alignment:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> ConstraintsTransformBox

Dart ConstraintsTransformBox(clipBehavior:).

Source

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

Dart ConstraintsTransformBox(child:).

Source

pub fn unmodified(constraints: BoxConstraints) -> BoxConstraints

A BoxConstraintsTransform that always returns its argument as-is (i.e., it is an identity function).

The ConstraintsTransformBox becomes a proxy widget that has no effect on layout if constraints_transform is set to this.

Source

pub fn unconstrained(_constraints: BoxConstraints) -> BoxConstraints

A BoxConstraintsTransform that always returns a BoxConstraints that imposes no constraints on either dimension.

Setting constraints_transform to this allows child to render at its “natural” size (equivalent to an UnconstrainedBox with constrained_axis set to None).

Source

pub fn width_unconstrained(constraints: BoxConstraints) -> BoxConstraints

A BoxConstraintsTransform that removes the width constraints from the input.

Setting constraints_transform to this allows child to render at its “natural” width (equivalent to an UnconstrainedBox with constrained_axis set to Axis::Horizontal).

Source

pub fn height_unconstrained(constraints: BoxConstraints) -> BoxConstraints

A BoxConstraintsTransform that removes the height constraints from the input.

Setting constraints_transform to this allows child to render at its “natural” height (equivalent to an UnconstrainedBox with constrained_axis set to Axis::Vertical).

Source

pub fn max_height_unconstrained(constraints: BoxConstraints) -> BoxConstraints

A BoxConstraintsTransform that removes the max_height constraint from the input.

Setting constraints_transform to this allows child to render at its “natural” height or the min_height of the incoming BoxConstraints, whichever is larger.

Source

pub fn max_width_unconstrained(constraints: BoxConstraints) -> BoxConstraints

A BoxConstraintsTransform that removes the max_width constraint from the input.

Setting constraints_transform to this allows child to render at its “natural” width or the min_width of the incoming BoxConstraints, whichever is larger.

Source

pub fn max_unconstrained(constraints: BoxConstraints) -> BoxConstraints

A BoxConstraintsTransform that removes both the max_width and the max_height constraints from the input.

Setting constraints_transform to this allows child to render at least its “natural” size, and grow along an axis if the incoming BoxConstraints has a larger minimum constraint on that axis.

Trait Implementations§

Source§

impl Debug for ConstraintsTransformBox

Source§

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

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

impl RenderObjectWidget for ConstraintsTransformBox

Source§

type RenderObject = RenderConstraintsTransformBox

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

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

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 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<RenderConstraintsTransformBox>, )

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 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§

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

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§

impl SingleChildRenderObjectWidget for ConstraintsTransformBox

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§

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>