Skip to main content

PositionExt

Trait PositionExt 

Source
pub trait PositionExt: View + Sized {
    // Provided methods
    fn position(
        self,
        x: impl IntoSignalF32,
        y: impl IntoSignalF32,
    ) -> PositionedChild<Self> { ... }
    fn position_anchor(
        self,
        anchor: UnitPoint,
        x: impl IntoSignalF32,
        y: impl IntoSignalF32,
    ) -> PositionedChild<Self> { ... }
    fn position_in(self, position: UnitPoint) -> PositionedChild<Self> { ... }
    fn position_in_anchor(
        self,
        anchor: UnitPoint,
        position: UnitPoint,
    ) -> PositionedChild<Self> { ... }
    fn position_in_offset(
        self,
        anchor: UnitPoint,
        position: UnitPoint,
        offset_x: impl IntoSignalF32,
        offset_y: impl IntoSignalF32,
    ) -> PositionedChild<Self> { ... }
    fn pin(self, constraints: PinConstraints) -> PositionedChild<Self> { ... }
}
Expand description

Extension trait for absolute positioning of views.

Use these methods inside an Absolute container.

Provided Methods§

Source

fn position( self, x: impl IntoSignalF32, y: impl IntoSignalF32, ) -> PositionedChild<Self>

Position view’s center at absolute (x, y) coordinates.

§Example
text("Hello").position(100.0, 50.0) // center at (100, 50)
Source

fn position_anchor( self, anchor: UnitPoint, x: impl IntoSignalF32, y: impl IntoSignalF32, ) -> PositionedChild<Self>

Position view’s anchor point at absolute coordinates.

§Example
text("Hello").position_anchor(UnitPoint::TOP_LEADING, 10.0, 10.0)
Source

fn position_in(self, position: UnitPoint) -> PositionedChild<Self>

Position view’s center at fractional location in parent.

The anchor point on the view matches the target position. e.g., UnitPoint::CENTER means view’s center at parent’s center.

§Example
text("Centered").position_in(UnitPoint::CENTER)
Source

fn position_in_anchor( self, anchor: UnitPoint, position: UnitPoint, ) -> PositionedChild<Self>

Position view’s anchor at fractional location in parent.

§Example
// Place view's top-left at parent's center
view.position_in_anchor(UnitPoint::TOP_LEADING, UnitPoint::CENTER)
Source

fn position_in_offset( self, anchor: UnitPoint, position: UnitPoint, offset_x: impl IntoSignalF32, offset_y: impl IntoSignalF32, ) -> PositionedChild<Self>

Position with fractional location plus offset.

Great for “16pt from bottom-right corner” patterns.

§Example
// FAB at bottom-right with 16pt inset
fab.position_in_offset(
    UnitPoint::BOTTOM_TRAILING,
    UnitPoint::BOTTOM_TRAILING,
    -16.0, -16.0
)
Source

fn pin(self, constraints: PinConstraints) -> PositionedChild<Self>

Position using edge pins and optional explicit size.

§Example
// Fill parent with 12pt inset
background.pin(PinConstraints::all(12.0));

// Bottom trailing fixed-size badge
badge.pin(
    PinConstraints::new()
        .trailing(12.0)
        .bottom(12.0)
        .width(28.0)
        .height(28.0)
);

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<V: View + Sized> PositionExt for V