refactor: simplify CollapsingHeader enable/disable code
This commit is contained in:
parent
7ac91970bd
commit
0c9b4858f0
1 changed files with 31 additions and 34 deletions
|
@ -281,43 +281,40 @@ impl CollapsingHeader {
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> CollapsingResponse<R> {
|
) -> CollapsingResponse<R> {
|
||||||
let header_enabled = self.enabled;
|
// Make sure contents are bellow header,
|
||||||
ui.wrap(|ui| {
|
// and make sure it is one unit (necessary for putting a `CollapsingHeader` in a grid).
|
||||||
ui.set_enabled(header_enabled);
|
ui.vertical(|ui| {
|
||||||
|
ui.set_enabled(self.enabled);
|
||||||
|
|
||||||
// Make sure contents are bellow header,
|
let Prepared {
|
||||||
// and make sure it is one unit (necessary for putting a `CollapsingHeader` in a grid).
|
id,
|
||||||
ui.vertical(|ui| {
|
header_response,
|
||||||
let Prepared {
|
mut state,
|
||||||
id,
|
} = self.begin(ui);
|
||||||
|
|
||||||
|
let ret_response = state.add_contents(ui, id, |ui| {
|
||||||
|
ui.indent(id, |ui| {
|
||||||
|
// make as wide as the header:
|
||||||
|
ui.expand_to_include_x(header_response.rect.right());
|
||||||
|
add_contents(ui)
|
||||||
|
})
|
||||||
|
.inner
|
||||||
|
});
|
||||||
|
ui.memory().collapsing_headers.insert(id, state);
|
||||||
|
|
||||||
|
if let Some(ret_response) = ret_response {
|
||||||
|
CollapsingResponse {
|
||||||
header_response,
|
header_response,
|
||||||
mut state,
|
body_response: Some(ret_response.response),
|
||||||
} = self.begin(ui);
|
body_returned: Some(ret_response.inner),
|
||||||
let ret_response = state.add_contents(ui, id, |ui| {
|
|
||||||
ui.indent(id, |ui| {
|
|
||||||
// make as wide as the header:
|
|
||||||
ui.expand_to_include_x(header_response.rect.right());
|
|
||||||
add_contents(ui)
|
|
||||||
})
|
|
||||||
.inner
|
|
||||||
});
|
|
||||||
ui.memory().collapsing_headers.insert(id, state);
|
|
||||||
|
|
||||||
if let Some(ret_response) = ret_response {
|
|
||||||
CollapsingResponse {
|
|
||||||
header_response,
|
|
||||||
body_response: Some(ret_response.response),
|
|
||||||
body_returned: Some(ret_response.inner),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
CollapsingResponse {
|
|
||||||
header_response,
|
|
||||||
body_response: None,
|
|
||||||
body_returned: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
.inner
|
CollapsingResponse {
|
||||||
|
header_response,
|
||||||
|
body_response: None,
|
||||||
|
body_returned: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.inner
|
.inner
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue