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>
impl<M> Collapse<M>
Sourcepub fn new(title: impl Into<String>, message: fn(bool) -> M) -> Self
pub fn new(title: impl Into<String>, message: fn(bool) -> M) -> Self
An open section titled title, reporting toggles through message.
Sourcepub fn inert(title: impl Into<String>) -> Self
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.
Sourcepub fn closed(self) -> Self
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.
Sourcepub fn with_expanded_height(self, height: i32) -> Self
pub fn with_expanded_height(self, height: i32) -> Self
Sets where the first opening goes, for a section built collapsed.
Sourcepub fn with_style(self, style: TextStyle) -> Self
pub fn with_style(self, style: TextStyle) -> Self
Sets the title’s font and size.
Sourcepub fn header_height(&self, theme: &Theme) -> i32
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.
Sourcepub fn set_open_silent(&mut self, open: bool)
pub fn set_open_silent(&mut self, open: bool)
Flips the open state without emitting or animating — set_open
calls this; so can an application restoring saved state before first
paint.
Sourcepub const fn expanded_height(&self) -> Option<i32>
pub const fn expanded_height(&self) -> Option<i32>
The remembered expanded height, if any.
Sourcepub fn set_expanded_height(&mut self, height: i32)
pub fn set_expanded_height(&mut self, height: i32)
Remembers where opening should return to.
Trait Implementations§
Source§impl<M> Describe for Collapse<M>
impl<M> Describe for Collapse<M>
Source§const DOC: &'static str = "A section that folds away to its header and opens again."
const DOC: &'static str = "A section that folds away to its header and opens again."
Source§const ICON: &'static Icon
const ICON: &'static Icon
Source§const PROPERTIES: &'static [Property]
const PROPERTIES: &'static [Property]
Source§impl<M: 'static> Widget<M> for Collapse<M>
impl<M: 'static> Widget<M> for Collapse<M>
Source§fn describe(&self) -> Option<&dyn DynDescribe>
fn describe(&self) -> Option<&dyn DynDescribe>
Source§fn describe_mut(&mut self) -> Option<&mut dyn DynDescribe>
fn describe_mut(&mut self) -> Option<&mut dyn DynDescribe>
describe.Source§fn measure(&self, ctx: &mut MeasureCtx<'_>, _offered: Offer) -> Measured
fn measure(&self, ctx: &mut MeasureCtx<'_>, _offered: Offer) -> Measured
Source§fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Pen<'_>)
fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Pen<'_>)
canvas, which is already clipped to this widget’s bounds
intersected with the damage region being repainted. Read moreSource§fn on_event(&mut self, event: &Event<'_>, ctx: &mut EventCtx<'_, M>) -> Handled
fn on_event(&mut self, event: &Event<'_>, ctx: &mut EventCtx<'_, M>) -> Handled
Source§fn accepts_pointer(&self) -> bool
fn accepts_pointer(&self) -> bool
true if the pointer can hit this widget. Read moreSource§fn preserves_focus(&self) -> bool
fn preserves_focus(&self) -> bool
true if a press on this widget should leave focus exactly where
it is. Read moreSource§fn animate(&mut self, now_ms: u64) -> Animation
fn animate(&mut self, now_ms: u64) -> Animation
EventCtx::request_animation — and stops being called
the moment it answers Wake::Never. Read moreAuto Trait Implementations§
impl<M> Freeze for Collapse<M>
impl<M> RefUnwindSafe for Collapse<M>
impl<M> Send for Collapse<M>
impl<M> Sync for Collapse<M>
impl<M> Unpin for Collapse<M>
impl<M> UnsafeUnpin for Collapse<M>
impl<M> UnwindSafe for Collapse<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynDescribe for Twhere
T: Describe,
impl<T> DynDescribe for Twhere
T: Describe,
Source§fn kind(&self) -> &'static str
fn kind(&self) -> &'static str
Describe::KIND.Source§fn properties(&self) -> &'static [Property]
fn properties(&self) -> &'static [Property]
Describe::PROPERTIES.Source§fn get_property(&self, name: &str) -> Option<Value>
fn get_property(&self, name: &str) -> Option<Value>
Describe::get.Source§fn set_property(
&mut self,
name: &str,
value: Value,
) -> Result<(), PropertyError>
fn set_property( &mut self, name: &str, value: Value, ) -> Result<(), PropertyError>
Describe::set.