Skip to main content

Collapse

Struct Collapse 

Source
pub struct Collapse<M> { /* private fields */ }
Expand description

A section that folds to its header.

The widget is the header — title, chevron, the toggle — and the node it sits on hosts the body as ordinary children below the header strip, the way Panel hosts children. Collapsing is the node’s height animating between the header alone and the full section; the body needs no hiding, because the node’s own clip crops it, mid-animation included.

let section = ui.add(stack, Collapse::new("Nettverk", Msg::Network), rect)?;
// body children of `section`, placed below Collapse::header_height
// ...
match message {
    Msg::Network(open) => widgets::set_open(&mut ui, section, open, FOLD_MS),
}

The widget cannot animate its own node — EventCtx deliberately has no tree access — so it emits fn(bool) -> M and the application answers with set_open, which flips the chevron and drives Ui::animate_layout. Inside a Ui::set_stack the siblings follow every frame, which is the whole accordion mechanism; Accordion packages the exclusivity.

§The expanded height is remembered, not configured

set_open notes the node’s height at the moment of collapse, so opening returns the section to wherever it really was — a section that grew a row while open comes back at its grown height. The one case with nothing to remember is a section built collapsed: with_expanded_height covers it.

Implementations§

Source§

impl<M> Collapse<M>

Source

pub fn new(title: impl Into<String>, message: fn(bool) -> M) -> Self

An open section titled title, reporting toggles through message.

Source

pub fn inert(title: impl Into<String>) -> Self

A section that folds and reports nothing, for one the application never reads the state of.

It drives its own height, which the one built with a message does not: a message is the application saying it will answer with set_open, and one without has nobody else to. So a decorative section on a panel folds when pressed and nothing has to be wired to it — which is what a form file wants, since a form file has no application to name.

Accordion is still the way to make a run of them exclusive; it drives them through set_open and works with these too.

Source

pub fn closed(self) -> Self

Starts the section collapsed. Pair with with_expanded_height, since a section that has never been open has no height to remember.

Source

pub fn with_expanded_height(self, height: i32) -> Self

Sets where the first opening goes, for a section built collapsed.

Source

pub fn with_role(self, role: Role) -> Self

Sets the header’s colour role.

Source

pub fn with_style(self, style: TextStyle) -> Self

Sets the title’s font and size.

Source

pub const fn is_open(&self) -> bool

Whether the section is open (or opening).

Source

pub fn header_height(&self, theme: &Theme) -> i32

The header strip’s height: the theme’s field height.

The strip the widget draws and the closed height set_open folds to — one definition, so they cannot drift.

Source

pub fn set_open_silent(&mut self, open: bool)

Flips the open state without emitting or animatingset_open calls this; so can an application restoring saved state before first paint.

Source

pub const fn expanded_height(&self) -> Option<i32>

The remembered expanded height, if any.

Source

pub fn set_expanded_height(&mut self, height: i32)

Remembers where opening should return to.

Trait Implementations§

Source§

impl<M: Clone> Clone for Collapse<M>

Source§

fn clone(&self) -> Collapse<M>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M: Debug> Debug for Collapse<M>

Source§

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

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

impl<M> Describe for Collapse<M>

Source§

const KIND: &'static str = "collapse"

The name a form file uses for this widget. Kebab-case.
Source§

const DOC: &'static str = "A section that folds away to its header and opens again."

One line saying what this widget is, for somebody choosing one. Read more
Source§

const GROUP: Group = Group::Container

Which shelf of the catalogue this belongs on.
Source§

const ICON: &'static Icon

The widget’s glyph: a small portrait of the thing, for a palette to draw beside — or instead of — its name. Read more
Source§

const PROPERTIES: &'static [Property]

Every property, in the order an inspector should show them.
Source§

fn get(&self, name: &str) -> Option<Value>

The current value. Read more
Source§

fn apply(&mut self, name: &str, value: Value) -> Result<(), Mismatch>

Applies a value, reporting only what went wrong. Read more
Source§

fn set(&mut self, name: &str, value: Value) -> Result<(), PropertyError>

Applies a value, reporting what went wrong and where.
Source§

impl<M: 'static> Widget<M> for Collapse<M>

Source§

fn describe(&self) -> Option<&dyn DynDescribe>

This widget’s property description, if it has one. Read more
Source§

fn describe_mut(&mut self) -> Option<&mut dyn DynDescribe>

The mutable half of describe.
Source§

fn measure(&self, ctx: &mut MeasureCtx<'_>, _offered: Offer) -> Measured

How big this widget would like to be, given what the caller can promise. Read more
Source§

fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Pen<'_>)

Draws into canvas, which is already clipped to this widget’s bounds intersected with the damage region being repainted. Read more
Source§

fn on_event(&mut self, event: &Event<'_>, ctx: &mut EventCtx<'_, M>) -> Handled

Reacts to an event routed to this widget.
Source§

fn accepts_pointer(&self) -> bool

Returns true if the pointer can hit this widget. Read more
Source§

fn focusable(&self) -> bool

Returns true if this widget can take keyboard focus.
Source§

fn preserves_focus(&self) -> bool

Returns true if a press on this widget should leave focus exactly where it is. Read more
Source§

fn animate(&mut self, now_ms: u64) -> Animation

Advances time-based state. Called only while this widget has asked to animate — see EventCtx::request_animation — and stops being called the moment it answers Wake::Never. Read more
Source§

fn snap(&mut self, now_ms: u64) -> Animation

Lands whatever is in flight at its end state, without animating it. Read more

Auto Trait Implementations§

§

impl<M> Freeze for Collapse<M>
where Option<fn(bool) -> M>: Freeze,

§

impl<M> RefUnwindSafe for Collapse<M>
where Option<fn(bool) -> M>: RefUnwindSafe,

§

impl<M> Send for Collapse<M>
where Option<fn(bool) -> M>: Send,

§

impl<M> Sync for Collapse<M>
where Option<fn(bool) -> M>: Sync,

§

impl<M> Unpin for Collapse<M>
where Option<fn(bool) -> M>: Unpin,

§

impl<M> UnsafeUnpin for Collapse<M>
where Option<fn(bool) -> M>: UnsafeUnpin,

§

impl<M> UnwindSafe for Collapse<M>
where Option<fn(bool) -> M>: UnwindSafe,

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

Source§

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

Borrows as dyn Any.
Source§

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

Mutably borrows as dyn Any.
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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynDescribe for T
where T: Describe,

Source§

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

Source§

fn properties(&self) -> &'static [Property]

Source§

fn get_property(&self, name: &str) -> Option<Value>

Source§

fn set_property( &mut self, name: &str, value: Value, ) -> Result<(), PropertyError>

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.