Configurable label text style for CollapsingHeader
CollapsingHeader: change label text style & enable options
@@ -138,6 +138,7 @@ pub struct CollapsingHeader {
label: Label,
default_open: bool,
id_source: Id,
+ enabled: bool,
}
impl CollapsingHeader {
@@ -154,6 +155,7 @@ impl CollapsingHeader {
label,
default_open: false,
id_source,
+ enabled: true,
}
}
@@ -170,6 +172,21 @@ impl CollapsingHeader {
self.id_source = Id::new(id_source);
self
}
+
+ /// By default, the `CollapsingHeader` text style is `TextStyle::Button`.
+ /// Call `.text_style(style)` to change this.
+ pub fn text_style(mut self, text_style: TextStyle) -> Self {
+ self.label = self.label.text_style(text_style);
+ self
+ }
+
+ /// If you set this to `false`, the `CollapsingHeader` will be grayed out and un-clickable.
+ ///
+ /// This is a convenience for [`Ui::set_enabled`].
+ pub fn enabled(mut self, enabled: bool) -> Self {
+ self.enabled = enabled;
+ self
+ }
}
struct Prepared {
@@ -188,6 +205,7 @@ impl CollapsingHeader {
label,
default_open,
id_source,
+ enabled: _,
} = self;
// TODO: horizontal layout, with icon and text as labels. Insert background behind using Frame.
@@ -263,6 +281,10 @@ impl CollapsingHeader {
ui: &mut Ui,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> CollapsingResponse<R> {
+ let header_enabled = self.enabled;
+ ui.wrap(|ui| {
+ ui.set_enabled(header_enabled);
+
// Make sure contents are bellow header,
// and make sure it is one unit (necessary for putting a `CollapsingHeader` in a grid).
ui.vertical(|ui| {
@@ -296,6 +318,8 @@ impl CollapsingHeader {
}
})
.inner
+ })
+ .inner
}
}
