Skip to main content

StyledContainer

Struct StyledContainer 

Source
pub struct StyledContainer { /* private fields */ }

Implementations§

Source§

impl StyledContainer

Source

pub fn new( layout_style: LayoutStyle, style: impl Fn(Rect) -> RectStyle + 'static, children: Vec<Box<dyn LayoutItem>>, ) -> Result<StyledContainer, LayoutError>

Source

pub fn from_slots( layout_style: LayoutStyle, style: impl Fn(Rect) -> RectStyle + 'static, slots: Vec<ChildSlot>, ) -> Result<StyledContainer, LayoutError>

A styled box whose children are a mix of static widgets and reactive fragments (ChildSlots), reconciled into this box’s own node so they inherit its flex direction/gap — the transparent box-with-a-for path (see Container::from_slots).

Source

pub fn with_opacity( self, opacity: impl Fn() -> f32 + 'static, ) -> StyledContainer

Source

pub fn with_transform( self, transform: impl Fn(Rect) -> Option<[f32; 6]> + 'static, ) -> StyledContainer

Apply an affine transform (rotate/scale/translate) to the whole box each view(). The closure takes the laid-out rect and returns the 2×3 matrix, or None for identity.

Source

pub fn on_hover_style( self, f: impl Fn(Rect) -> RectStyle + 'static, ) -> StyledContainer

Paint the box with f while the mouse hovers it (a declarative style swap, like Button). Hover is mouse-only; touch never sets it, so a tap leaves no stuck hover state.

Source

pub fn on_active_style( self, f: impl Fn(Rect) -> RectStyle + 'static, ) -> StyledContainer

Paint the box with f while a primary pointer is held down inside it — the pressed / CSS :active state, which takes precedence over on_hover_style. Unlike hover it tracks touch as well as mouse, and it clears on release, on leaving the box, or once the press drags off, so it never sticks.

Source

pub fn on_press(self, f: impl Fn() + 'static) -> StyledContainer

Make the box itself pressable. The callback fires on a tap (release, not press) inside the box; a child widget that handles the press wins, and a scroll gesture started on the box does not fire it.

Source

pub fn on_alt_press( self, f: impl Fn(PointerButton) + 'static, ) -> StyledContainer

Fire f(button) on a tap with a non-primary button — Secondary (right) or Auxiliary (middle). Same tap-on-release semantics as Self::on_press: a child that handles the press wins, and travel past the tap slop cancels it.

Opt-in per box rather than folded into on_press, because a non-primary press otherwise falls through to whatever is behind it — silently swallowing right-clicks on every pressable box would break that.

Source

pub fn on_long_press(self, f: impl Fn() + 'static) -> StyledContainer

Fires once a press inside the box is held past ~500ms without moving past the tap slop, instead of on_press’s tap-on-release. There is no dedicated timer in the gesture pipeline, so the threshold is only checked on the next pointer event after the press (a move or the release) — it fires slightly late, never at exactly 500ms, and a release before that next check-in is a normal tap.

Source

pub fn on_drag_end(self, f: impl Fn(f32, f32) + 'static) -> StyledContainer

Make the box draggable. The callback fires with the pointer position (layout space) on a press inside the box and on every move until release — even after the pointer leaves the box. Map the coordinate to a value (slider) or an offset (reorder/resize). Fires once when a drag started on this box ends, with the position it finished at (layout space, local to the box, same as on_drag).

This is what makes a threshold gesture expressible: on_drag alone reports where the pointer is but never that it let go, so a swipe-to-dismiss or a drag-to-open can be tracked and never decided. A drag also ends when the pointer leaves the window or a child consumes the release; those carry no position, so the last one the drag reached is reported instead — the gesture always ends exactly once.

Source

pub fn on_drag(self, f: impl Fn(f32, f32) + 'static) -> StyledContainer

Source

pub fn on_hover(self, f: impl Fn(bool) + 'static) -> StyledContainer

Fire f(true) when the mouse enters the box and f(false) when it leaves (mouse only). Independent of on_hover_style: a box can observe hover without swapping its paint.

Registers the box as a pointer target, like on_scroll does for the same reason: a surface that carves its input region from its content (a click-through overlay) never receives a move event over a box it left out of that region, so a hover it did not register is a hover it can’t observe.

Source

pub fn on_scroll(self, f: impl Fn(f32, f32) + 'static) -> StyledContainer

Fire f(dx, dy) with the wheel delta while the mouse is over the box — scroll-to-adjust on a control (a volume or brightness chip, a stepper). Deltas are normalised to pixels, matching ScrollArea: a line delta counts as 20px, so one wheel notch is roughly ±60.

Scroll events carry no pointer position, so the box’s hover state is what targets them; this enables hover tracking on its own, without needing an on_hover_style. A scrollable child (a scroll area inside the box) hit-tests first and keeps the event.

Source

pub fn on_key(self, f: impl Fn(&Key) + 'static) -> StyledContainer

Fire f(&key) on every key press. This is a GLOBAL handler (key events reach every widget; there is no per-widget focus), so it suits app-level shortcuts, not focused text entry.

Source

pub fn on_focus(self, f: impl Fn(bool) + 'static) -> StyledContainer

Make the box focusable and fire f(true)/f(false) when it gains/loses keyboard focus. It joins the tab order (Tab/Shift-Tab reach it) and takes focus on tap. Use it to drive a focus ring or to build a custom focusable widget on top of a box.

Trait Implementations§

Source§

impl Component for StyledContainer

Source§

fn view(&self) -> RenderNode

Source§

fn on_event(&mut self, event: &Event) -> EventResult

Source§

fn debug_name(&self) -> &'static str

Human-readable widget type name for the devtools tree inspector.
Source§

impl Drop for StyledContainer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl LayoutItem for StyledContainer

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 for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more