Skip to content

Commit 8e868cd

Browse files
Zeenobithacknus
authored andcommitted
Expose state override for HeaderResponse (emilk#4200)
I'm trying to create some custom collapsing headers that add additional buttons inside the header itself. Because of this, I load the `CollapsingState` in my special widget manually. But because `HeaderResponse` owns the `Ui` and the `CollapsingState`, there is no way for me to open/close the collapsing header based on response of the inner widget. Initially, I considered just exposing `state` member of `HeaderResponse`, but that exposes too much of the API at the wrong time, in my opinion. So instead I found it'd be safer to just expose the open/close API to the response itself, and that's what this PR does.
1 parent 1b54ae6 commit 8e868cd

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

crates/egui/src/containers/collapsing_header.rs

+12
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ pub struct HeaderResponse<'ui, HeaderRet> {
272272
}
273273

274274
impl<'ui, HeaderRet> HeaderResponse<'ui, HeaderRet> {
275+
pub fn is_open(&self) -> bool {
276+
self.state.is_open()
277+
}
278+
279+
pub fn set_open(&mut self, open: bool) {
280+
self.state.set_open(open);
281+
}
282+
283+
pub fn toggle(&mut self) {
284+
self.state.toggle(self.ui);
285+
}
286+
275287
/// Returns the response of the collapsing button, the custom header, and the custom body.
276288
pub fn body<BodyRet>(
277289
mut self,

0 commit comments

Comments
 (0)