pub struct CollapsingHeader { /* private fields */ }egui only.Expand description
A header which can be collapsed/expanded, revealing a contained Ui region.
egui::CollapsingHeader::new("Heading")
.show(ui, |ui| {
ui.label("Body");
});
// Short version:
ui.collapsing("Heading", |ui| { ui.label("Body"); });If you want to customize the header contents, see CollapsingState::show_header.
Implementations§
Source§impl CollapsingHeader
impl CollapsingHeader
Sourcepub fn new(text: impl Into<WidgetText>) -> CollapsingHeader
pub fn new(text: impl Into<WidgetText>) -> CollapsingHeader
The CollapsingHeader starts out collapsed unless you call default_open.
The label is used as an Id source.
If the label is unique and static this is fine,
but if it changes or there are several CollapsingHeader with the same title
you need to provide a unique id source with Self::id_salt.
Sourcepub fn custom(
ui: &mut Ui,
id_salt: impl AsIdSalt,
ui_header: impl FnOnce(&mut Ui),
ui_body: impl FnOnce(&mut Ui),
)
pub fn custom( ui: &mut Ui, id_salt: impl AsIdSalt, ui_header: impl FnOnce(&mut Ui), ui_body: impl FnOnce(&mut Ui), )
Show a collapsing header where you draw the header contents yourself.
Unlike Self::new, which only takes a text label, the header here is an
arbitrary closure, so you can put e.g. checkboxes, buttons or several widgets
next to the expand/collapse arrow. Only the arrow toggles the open state.
id_salt must be unique within the parent Ui.
The header starts out collapsed.
This is a convenience wrapper around CollapsingState::show_header.
Use CollapsingState directly if you need more control,
e.g. to make it open by default or to get the responses back.
let mut enabled = true;
egui::CollapsingHeader::custom(
ui,
"my_custom_header",
|ui| {
ui.checkbox(&mut enabled, "Enabled");
},
|ui| {
ui.label("Body");
},
);Sourcepub fn default_open(self, open: bool) -> CollapsingHeader
pub fn default_open(self, open: bool) -> CollapsingHeader
By default, the CollapsingHeader is collapsed.
Call .default_open(true) to change this.
Sourcepub fn open(self, open: Option<bool>) -> CollapsingHeader
pub fn open(self, open: Option<bool>) -> CollapsingHeader
Calling .open(Some(true)) will make the collapsing header open this frame (or stay open).
Calling .open(Some(false)) will make the collapsing header close this frame (or stay closed).
Calling .open(None) has no effect (default).
Sourcepub fn id_salt(self, id_salt: impl AsIdSalt) -> CollapsingHeader
pub fn id_salt(self, id_salt: impl AsIdSalt) -> CollapsingHeader
Explicitly set the source of the Id of this widget, instead of using title label.
This is useful if the title label is dynamic or not unique.
Sourcepub fn enabled(self, enabled: bool) -> CollapsingHeader
pub fn enabled(self, enabled: bool) -> CollapsingHeader
If you set this to false, the CollapsingHeader will be grayed out and un-clickable.
This is a convenience for Ui::disable.
Sourcepub fn show_background(self, show_background: bool) -> CollapsingHeader
pub fn show_background(self, show_background: bool) -> CollapsingHeader
Should the CollapsingHeader show a background behind it? Default: false.
To show it behind all CollapsingHeader you can just use:
ui.visuals_mut().collapsing_header_frame = true;Sourcepub fn icon(
self,
icon_fn: impl FnOnce(&mut Ui, f32, &Response) + 'static,
) -> CollapsingHeader
pub fn icon( self, icon_fn: impl FnOnce(&mut Ui, f32, &Response) + 'static, ) -> CollapsingHeader
Use the provided function to render a different CollapsingHeader icon.
Defaults to a triangle that animates as the CollapsingHeader opens and closes.
For example:
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);
}
egui::CollapsingHeader::new("Circles")
.icon(circle_icon)
.show(ui, |ui| { ui.label("Hi!"); });Source§impl CollapsingHeader
impl CollapsingHeader
pub fn show<R>( self, ui: &mut Ui, add_body: impl FnOnce(&mut Ui) -> R, ) -> CollapsingResponse<R>
pub fn show_unindented<R>( self, ui: &mut Ui, add_body: impl FnOnce(&mut Ui) -> R, ) -> CollapsingResponse<R>
Auto Trait Implementations§
impl !RefUnwindSafe for CollapsingHeader
impl !Send for CollapsingHeader
impl !Sync for CollapsingHeader
impl !UnwindSafe for CollapsingHeader
impl Forget for CollapsingHeader
impl Freeze for CollapsingHeaderwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<RichText> is !null: Freeze,
PhantomData<ArcInner<RichText>>: Freeze,
*const ArcInner<LayoutJob> is !null: Freeze,
PhantomData<ArcInner<LayoutJob>>: Freeze,
*const ArcInner<Galley> is !null: Freeze,
PhantomData<ArcInner<Galley>>: Freeze,
NonZero<u64>: Freeze,
*const dyn FnOnce(&mut Ui, f32, &Response) is !null: Freeze,
PhantomData<dyn FnOnce(&mut Ui, f32, &Response)>: Freeze,
impl Move for CollapsingHeader
impl Unpin for CollapsingHeader
impl UnsafeUnpin for CollapsingHeaderwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<RichText> is !null: UnsafeUnpin,
PhantomData<ArcInner<RichText>>: UnsafeUnpin,
*const ArcInner<LayoutJob> is !null: UnsafeUnpin,
PhantomData<ArcInner<LayoutJob>>: UnsafeUnpin,
*const ArcInner<Galley> is !null: UnsafeUnpin,
PhantomData<ArcInner<Galley>>: UnsafeUnpin,
NonZeroU64Inner: UnsafeUnpin,
*const dyn FnOnce(&mut Ui, f32, &Response) is !null: UnsafeUnpin,
PhantomData<dyn FnOnce(&mut Ui, f32, &Response)>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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