pub struct CollapsingState { /* private fields */ }
Expand description

This is a a building block for building collapsing regions.

It is used by CollapsingHeader and Window, but can also be used on its own.

See CollapsingState::show_header for how to show a collapsing header with a custom header.

Implementations§

source§

impl CollapsingState

source

pub fn load(ctx: &Context, id: Id) -> Option<Self>

source

pub fn store(&self, ctx: &Context)

source

pub fn remove(&self, ctx: &Context)

source

pub fn id(&self) -> Id

source

pub fn load_with_default_open(ctx: &Context, id: Id, default_open: bool) -> Self

source

pub fn is_open(&self) -> bool

source

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

source

pub fn toggle(&mut self, ui: &Ui)

source

pub fn openness(&self, ctx: &Context) -> f32

0 for closed, 1 for open, with tweening

source

pub fn show_header<HeaderRet>( self, ui: &mut Ui, add_header: impl FnOnce(&mut Ui) -> HeaderRet ) -> HeaderResponse<'_, HeaderRet>

Shows header and body (if expanded).

The header will start with the default button in a horizontal layout, followed by whatever you add.

Will also store the state.

Returns the response of the collapsing button, the custom header, and the custom body.

let id = ui.make_persistent_id("my_collapsing_header");
egui::collapsing_header::CollapsingState::load_with_default_open(ui.ctx(), id, false)
    .show_header(ui, |ui| {
        ui.label("Header"); // you can put checkboxes or whatever here
    })
    .body(|ui| ui.label("Body"));
source

pub fn show_body_indented<R>( &mut self, header_response: &Response, ui: &mut Ui, add_body: impl FnOnce(&mut Ui) -> R ) -> Option<InnerResponse<R>>

Show body if we are open, with a nice animation between closed and open. Indent the body to show it belongs to the header.

Will also store the state.

source

pub fn show_body_unindented<R>( &mut self, ui: &mut Ui, add_body: impl FnOnce(&mut Ui) -> R ) -> Option<InnerResponse<R>>

Show body if we are open, with a nice animation between closed and open. Will also store the state.

source

pub fn show_toggle_button( &mut self, ui: &mut Ui, icon_fn: impl FnOnce(&mut Ui, f32, &Response) + 'static ) -> Response

Paint this CollapsingState’s toggle button. Takes an IconPainter as the icon.

fn circle_icon(ui: &mut egui::Ui, openness: f32, response: &egui::Response) {
    let stroke = ui.style().interact(&response).fg_stroke;
    let radius = egui::lerp(2.0..=3.0, openness);
    ui.painter().circle_filled(response.rect.center(), radius, stroke.color);
}

let mut state = egui::collapsing_header::CollapsingState::load_with_default_open(
    ui.ctx(),
    ui.make_persistent_id("my_collapsing_state"),
    false,
);

let header_res = ui.horizontal(|ui| {
    ui.label("Header");
    state.show_toggle_button(ui, circle_icon);
});

state.show_body_indented(&header_res.response, ui, |ui| ui.label("Body"));

Trait Implementations§

source§

impl Clone for CollapsingState

source§

fn clone(&self) -> CollapsingState

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for CollapsingState

source§

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

Formats the value using the given formatter. 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<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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

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

§

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

§

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

§

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.