diff options
author | Zeenobit <zeenobit.exe@gmail.com> | 2024-03-21 07:13:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-21 12:13:32 +0100 |
commit | e4f209ec50692db9f551d3ddf81ce5f8046cf7f7 (patch) | |
tree | 51553e45574197d0aac201ee670c37dc247c381b | |
parent | 7d3d7ce0cab1b82c11c9302e01c0770c8e1986db (diff) |
Expose state override for `HeaderResponse` (#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.
-rw-r--r-- | crates/egui/src/containers/collapsing_header.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/egui/src/containers/collapsing_header.rs b/crates/egui/src/containers/collapsing_header.rs index cb48ca1e..6fb7662a 100644 --- a/crates/egui/src/containers/collapsing_header.rs +++ b/crates/egui/src/containers/collapsing_header.rs @@ -272,6 +272,18 @@ pub struct HeaderResponse<'ui, HeaderRet> { } impl<'ui, HeaderRet> HeaderResponse<'ui, HeaderRet> { + pub fn is_open(&self) -> bool { + self.state.is_open() + } + + pub fn set_open(&mut self, open: bool) { + self.state.set_open(open); + } + + pub fn toggle(&mut self) { + self.state.toggle(self.ui); + } + /// Returns the response of the collapsing button, the custom header, and the custom body. pub fn body<BodyRet>( mut self, |