mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Change arguments to animating panel functions to take &mut bool
This commit is contained in:
@@ -223,14 +223,14 @@ impl SidePanel {
|
|||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
self.show_inside_dyn(ui, false, Box::new(add_contents))
|
self.show_inside_dyn(ui, None, Box::new(add_contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show the panel inside a [`Ui`].
|
/// Show the panel inside a [`Ui`].
|
||||||
fn show_inside_dyn<'c, R>(
|
fn show_inside_dyn<'c, R>(
|
||||||
self,
|
self,
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
closable: bool,
|
is_expanded: Option<&mut bool>,
|
||||||
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
let Self {
|
let Self {
|
||||||
@@ -273,7 +273,7 @@ impl SidePanel {
|
|||||||
width = clamp_to_range(width, width_range).at_most(available_rect.width());
|
width = clamp_to_range(width, width_range).at_most(available_rect.width());
|
||||||
side.set_rect_width(&mut panel_rect, width);
|
side.set_rect_width(&mut panel_rect, width);
|
||||||
|
|
||||||
if closable && width <= width_range.min && width < old_width {
|
if is_expanded.is_some() && width <= width_range.min && width < old_width {
|
||||||
drag_to_close = true;
|
drag_to_close = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,7 +292,7 @@ impl SidePanel {
|
|||||||
}))
|
}))
|
||||||
.max_rect(panel_rect)
|
.max_rect(panel_rect)
|
||||||
.layout(Layout::top_down(Align::Min))
|
.layout(Layout::top_down(Align::Min))
|
||||||
.with_closable(closable),
|
.with_closable(is_expanded.is_some()),
|
||||||
);
|
);
|
||||||
panel_ui.expand_to_include_rect(panel_rect);
|
panel_ui.expand_to_include_rect(panel_rect);
|
||||||
panel_ui.set_clip_rect(panel_rect); // If we overflow, don't do so visibly (#4475)
|
panel_ui.set_clip_rect(panel_rect); // If we overflow, don't do so visibly (#4475)
|
||||||
@@ -370,8 +370,11 @@ impl SidePanel {
|
|||||||
ui.painter().vline(resize_x, panel_rect.y_range(), stroke);
|
ui.painter().vline(resize_x, panel_rect.y_range(), stroke);
|
||||||
}
|
}
|
||||||
|
|
||||||
if panel_ui.should_close() || drag_to_close {
|
if let Some(is_expanded) = is_expanded {
|
||||||
inner_response.response.set_close();
|
if panel_ui.should_close() || drag_to_close {
|
||||||
|
inner_response.response.set_close();
|
||||||
|
*is_expanded = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner_response
|
inner_response
|
||||||
@@ -383,14 +386,14 @@ impl SidePanel {
|
|||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
self.show_dyn(ctx, false, Box::new(add_contents))
|
self.show_dyn(ctx, None, Box::new(add_contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show the panel at the top level.
|
/// Show the panel at the top level.
|
||||||
fn show_dyn<'c, R>(
|
fn show_dyn<'c, R>(
|
||||||
self,
|
self,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
closable: bool,
|
is_expanded: Option<&mut bool>,
|
||||||
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
let side = self.side;
|
let side = self.side;
|
||||||
@@ -404,7 +407,7 @@ impl SidePanel {
|
|||||||
);
|
);
|
||||||
panel_ui.set_clip_rect(ctx.screen_rect());
|
panel_ui.set_clip_rect(ctx.screen_rect());
|
||||||
|
|
||||||
let inner_response = self.show_inside_dyn(&mut panel_ui, closable, add_contents);
|
let inner_response = self.show_inside_dyn(&mut panel_ui, is_expanded, add_contents);
|
||||||
let rect = inner_response.response.rect;
|
let rect = inner_response.response.rect;
|
||||||
|
|
||||||
match side {
|
match side {
|
||||||
@@ -420,13 +423,15 @@ impl SidePanel {
|
|||||||
|
|
||||||
/// Show the panel if `is_expanded` is `true`,
|
/// Show the panel if `is_expanded` is `true`,
|
||||||
/// otherwise don't show it, but with a nice animation between collapsed and expanded.
|
/// otherwise don't show it, but with a nice animation between collapsed and expanded.
|
||||||
|
///
|
||||||
|
/// The panel supports drag-to-close, and you can also call [`Ui::close`] from within the panel to close it.
|
||||||
pub fn show_animated<R>(
|
pub fn show_animated<R>(
|
||||||
self,
|
self,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
is_expanded: bool,
|
is_expanded: &mut bool,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> Option<InnerResponse<R>> {
|
) -> Option<InnerResponse<R>> {
|
||||||
let how_expanded = animate_expansion(ctx, self.id.with("animation"), is_expanded);
|
let how_expanded = animate_expansion(ctx, self.id.with("animation"), *is_expanded);
|
||||||
|
|
||||||
if 0.0 == how_expanded {
|
if 0.0 == how_expanded {
|
||||||
None
|
None
|
||||||
@@ -447,20 +452,21 @@ impl SidePanel {
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// Show the real panel:
|
// Show the real panel:
|
||||||
let closable = true;
|
Some(self.show_dyn(ctx, Some(is_expanded), Box::new(add_contents)))
|
||||||
Some(self.show_dyn(ctx, closable, Box::new(add_contents)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show the panel if `is_expanded` is `true`,
|
/// Show the panel if `is_expanded` is `true`,
|
||||||
/// otherwise don't show it, but with a nice animation between collapsed and expanded.
|
/// otherwise don't show it, but with a nice animation between collapsed and expanded.
|
||||||
|
///
|
||||||
|
/// The panel supports drag-to-close, and you can also call [`Ui::close`] from within the panel to close it.
|
||||||
pub fn show_animated_inside<R>(
|
pub fn show_animated_inside<R>(
|
||||||
self,
|
self,
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
is_expanded: bool,
|
is_expanded: &mut bool,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> Option<InnerResponse<R>> {
|
) -> Option<InnerResponse<R>> {
|
||||||
let how_expanded = animate_expansion(ui.ctx(), self.id.with("animation"), is_expanded);
|
let how_expanded = animate_expansion(ui.ctx(), self.id.with("animation"), *is_expanded);
|
||||||
|
|
||||||
if 0.0 == how_expanded {
|
if 0.0 == how_expanded {
|
||||||
None
|
None
|
||||||
@@ -481,20 +487,22 @@ impl SidePanel {
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// Show the real panel:
|
// Show the real panel:
|
||||||
let closable = true;
|
Some(self.show_inside_dyn(ui, Some(is_expanded), Box::new(add_contents)))
|
||||||
Some(self.show_inside_dyn(ui, closable, Box::new(add_contents)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show either a collapsed or a expanded panel, with a nice animation between.
|
/// Show either a collapsed or a expanded panel, with a nice animation between.
|
||||||
|
///
|
||||||
|
/// The panel supports drag-to-close, and you can also call [`Ui::close`] from within the panel to close it.
|
||||||
pub fn show_animated_between<R>(
|
pub fn show_animated_between<R>(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
is_expanded: bool,
|
is_expanded: &mut bool,
|
||||||
collapsed_panel: Self,
|
collapsed_panel: Self,
|
||||||
expanded_panel: Self,
|
expanded_panel: Self,
|
||||||
add_contents: impl FnOnce(&mut Ui, f32) -> R,
|
add_contents: impl FnOnce(&mut Ui, f32) -> R,
|
||||||
) -> Option<InnerResponse<R>> {
|
) -> Option<InnerResponse<R>> {
|
||||||
let how_expanded = animate_expansion(ctx, expanded_panel.id.with("animation"), is_expanded);
|
let how_expanded =
|
||||||
|
animate_expansion(ctx, expanded_panel.id.with("animation"), *is_expanded);
|
||||||
|
|
||||||
if 0.0 == how_expanded {
|
if 0.0 == how_expanded {
|
||||||
Some(collapsed_panel.show(ctx, |ui| add_contents(ui, how_expanded)))
|
Some(collapsed_panel.show(ctx, |ui| add_contents(ui, how_expanded)))
|
||||||
@@ -514,20 +522,26 @@ impl SidePanel {
|
|||||||
.show(ctx, |ui| add_contents(ui, how_expanded));
|
.show(ctx, |ui| add_contents(ui, how_expanded));
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(expanded_panel.show(ctx, |ui| add_contents(ui, how_expanded)))
|
Some(expanded_panel.show_dyn(
|
||||||
|
ctx,
|
||||||
|
Some(is_expanded),
|
||||||
|
Box::new(|ui| add_contents(ui, how_expanded)),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show either a collapsed or a expanded panel, with a nice animation between.
|
/// Show either a collapsed or a expanded panel, with a nice animation between.
|
||||||
|
///
|
||||||
|
/// The panel supports drag-to-close, and you can also call [`Ui::close`] from within the panel to close it.
|
||||||
pub fn show_animated_between_inside<R>(
|
pub fn show_animated_between_inside<R>(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
is_expanded: bool,
|
is_expanded: &mut bool,
|
||||||
collapsed_panel: Self,
|
collapsed_panel: Self,
|
||||||
expanded_panel: Self,
|
expanded_panel: Self,
|
||||||
add_contents: impl FnOnce(&mut Ui, f32) -> R,
|
add_contents: impl FnOnce(&mut Ui, f32) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
let how_expanded =
|
let how_expanded =
|
||||||
animate_expansion(ui.ctx(), expanded_panel.id.with("animation"), is_expanded);
|
animate_expansion(ui.ctx(), expanded_panel.id.with("animation"), *is_expanded);
|
||||||
|
|
||||||
if 0.0 == how_expanded {
|
if 0.0 == how_expanded {
|
||||||
collapsed_panel.show_inside(ui, |ui| add_contents(ui, how_expanded))
|
collapsed_panel.show_inside(ui, |ui| add_contents(ui, how_expanded))
|
||||||
@@ -546,7 +560,11 @@ impl SidePanel {
|
|||||||
.exact_width(fake_width)
|
.exact_width(fake_width)
|
||||||
.show_inside(ui, |ui| add_contents(ui, how_expanded))
|
.show_inside(ui, |ui| add_contents(ui, how_expanded))
|
||||||
} else {
|
} else {
|
||||||
expanded_panel.show_inside(ui, |ui| add_contents(ui, how_expanded))
|
expanded_panel.show_inside_dyn(
|
||||||
|
ui,
|
||||||
|
Some(is_expanded),
|
||||||
|
Box::new(|ui| add_contents(ui, how_expanded)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -729,14 +747,14 @@ impl TopBottomPanel {
|
|||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
self.show_inside_dyn(ui, false, Box::new(add_contents))
|
self.show_inside_dyn(ui, None, Box::new(add_contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show the panel inside a [`Ui`].
|
/// Show the panel inside a [`Ui`].
|
||||||
fn show_inside_dyn<'c, R>(
|
fn show_inside_dyn<'c, R>(
|
||||||
self,
|
self,
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
closable: bool,
|
is_expanded: Option<&mut bool>,
|
||||||
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
let Self {
|
let Self {
|
||||||
@@ -786,7 +804,10 @@ impl TopBottomPanel {
|
|||||||
clamp_to_range(height, height_range).at_most(available_rect.height());
|
clamp_to_range(height, height_range).at_most(available_rect.height());
|
||||||
side.set_rect_height(&mut panel_rect, height);
|
side.set_rect_height(&mut panel_rect, height);
|
||||||
|
|
||||||
if closable && height <= height_range.min && height < old_height {
|
if is_expanded.is_some()
|
||||||
|
&& height <= height_range.min
|
||||||
|
&& height < old_height
|
||||||
|
{
|
||||||
drag_to_close = true;
|
drag_to_close = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -805,7 +826,7 @@ impl TopBottomPanel {
|
|||||||
}))
|
}))
|
||||||
.max_rect(panel_rect)
|
.max_rect(panel_rect)
|
||||||
.layout(Layout::top_down(Align::Min))
|
.layout(Layout::top_down(Align::Min))
|
||||||
.with_closable(closable),
|
.with_closable(is_expanded.is_some()),
|
||||||
);
|
);
|
||||||
panel_ui.expand_to_include_rect(panel_rect);
|
panel_ui.expand_to_include_rect(panel_rect);
|
||||||
panel_ui.set_clip_rect(panel_rect); // If we overflow, don't do so visibly (#4475)
|
panel_ui.set_clip_rect(panel_rect); // If we overflow, don't do so visibly (#4475)
|
||||||
@@ -883,8 +904,11 @@ impl TopBottomPanel {
|
|||||||
ui.painter().hline(panel_rect.x_range(), resize_y, stroke);
|
ui.painter().hline(panel_rect.x_range(), resize_y, stroke);
|
||||||
}
|
}
|
||||||
|
|
||||||
if panel_ui.should_close() || drag_to_close {
|
if let Some(is_expanded) = is_expanded {
|
||||||
inner_response.response.set_close();
|
if panel_ui.should_close() || drag_to_close {
|
||||||
|
inner_response.response.set_close();
|
||||||
|
*is_expanded = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner_response
|
inner_response
|
||||||
@@ -896,14 +920,14 @@ impl TopBottomPanel {
|
|||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
self.show_dyn(ctx, false, Box::new(add_contents))
|
self.show_dyn(ctx, None, Box::new(add_contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show the panel at the top level.
|
/// Show the panel at the top level.
|
||||||
fn show_dyn<'c, R>(
|
fn show_dyn<'c, R>(
|
||||||
self,
|
self,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
closable: bool,
|
is_expanded: Option<&mut bool>,
|
||||||
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
let available_rect = ctx.available_rect();
|
let available_rect = ctx.available_rect();
|
||||||
@@ -918,7 +942,7 @@ impl TopBottomPanel {
|
|||||||
);
|
);
|
||||||
panel_ui.set_clip_rect(ctx.screen_rect());
|
panel_ui.set_clip_rect(ctx.screen_rect());
|
||||||
|
|
||||||
let inner_response = self.show_inside_dyn(&mut panel_ui, closable, add_contents);
|
let inner_response = self.show_inside_dyn(&mut panel_ui, is_expanded, add_contents);
|
||||||
let rect = inner_response.response.rect;
|
let rect = inner_response.response.rect;
|
||||||
|
|
||||||
match side {
|
match side {
|
||||||
@@ -939,13 +963,15 @@ impl TopBottomPanel {
|
|||||||
|
|
||||||
/// Show the panel if `is_expanded` is `true`,
|
/// Show the panel if `is_expanded` is `true`,
|
||||||
/// otherwise don't show it, but with a nice animation between collapsed and expanded.
|
/// otherwise don't show it, but with a nice animation between collapsed and expanded.
|
||||||
|
///
|
||||||
|
/// The panel supports drag-to-close, and you can also call [`Ui::close`] from within the panel to close it.
|
||||||
pub fn show_animated<R>(
|
pub fn show_animated<R>(
|
||||||
self,
|
self,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
is_expanded: bool,
|
is_expanded: &mut bool,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> Option<InnerResponse<R>> {
|
) -> Option<InnerResponse<R>> {
|
||||||
let how_expanded = animate_expansion(ctx, self.id.with("animation"), is_expanded);
|
let how_expanded = animate_expansion(ctx, self.id.with("animation"), *is_expanded);
|
||||||
|
|
||||||
if 0.0 == how_expanded {
|
if 0.0 == how_expanded {
|
||||||
None
|
None
|
||||||
@@ -968,19 +994,21 @@ impl TopBottomPanel {
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// Show the real panel:
|
// Show the real panel:
|
||||||
Some(self.show(ctx, add_contents))
|
Some(self.show_dyn(ctx, Some(is_expanded), Box::new(add_contents)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show the panel if `is_expanded` is `true`,
|
/// Show the panel if `is_expanded` is `true`,
|
||||||
/// otherwise don't show it, but with a nice animation between collapsed and expanded.
|
/// otherwise don't show it, but with a nice animation between collapsed and expanded.
|
||||||
|
///
|
||||||
|
/// The panel supports drag-to-close, and you can also call [`Ui::close`] from within the panel to close it.
|
||||||
pub fn show_animated_inside<R>(
|
pub fn show_animated_inside<R>(
|
||||||
self,
|
self,
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
is_expanded: bool,
|
is_expanded: &mut bool,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> Option<InnerResponse<R>> {
|
) -> Option<InnerResponse<R>> {
|
||||||
let how_expanded = animate_expansion(ui.ctx(), self.id.with("animation"), is_expanded);
|
let how_expanded = animate_expansion(ui.ctx(), self.id.with("animation"), *is_expanded);
|
||||||
|
|
||||||
if 0.0 == how_expanded {
|
if 0.0 == how_expanded {
|
||||||
None
|
None
|
||||||
@@ -1003,20 +1031,22 @@ impl TopBottomPanel {
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// Show the real panel:
|
// Show the real panel:
|
||||||
let closable = true;
|
Some(self.show_inside_dyn(ui, Some(is_expanded), Box::new(add_contents)))
|
||||||
Some(self.show_inside_dyn(ui, closable, Box::new(add_contents)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show either a collapsed or a expanded panel, with a nice animation between.
|
/// Show either a collapsed or a expanded panel, with a nice animation between.
|
||||||
|
///
|
||||||
|
/// The panel supports drag-to-close, and you can also call [`Ui::close`] from within the panel to close it.
|
||||||
pub fn show_animated_between<R>(
|
pub fn show_animated_between<R>(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
is_expanded: bool,
|
is_expanded: &mut bool,
|
||||||
collapsed_panel: Self,
|
collapsed_panel: Self,
|
||||||
expanded_panel: Self,
|
expanded_panel: Self,
|
||||||
add_contents: impl FnOnce(&mut Ui, f32) -> R,
|
add_contents: impl FnOnce(&mut Ui, f32) -> R,
|
||||||
) -> Option<InnerResponse<R>> {
|
) -> Option<InnerResponse<R>> {
|
||||||
let how_expanded = animate_expansion(ctx, expanded_panel.id.with("animation"), is_expanded);
|
let how_expanded =
|
||||||
|
animate_expansion(ctx, expanded_panel.id.with("animation"), *is_expanded);
|
||||||
|
|
||||||
if 0.0 == how_expanded {
|
if 0.0 == how_expanded {
|
||||||
Some(collapsed_panel.show(ctx, |ui| add_contents(ui, how_expanded)))
|
Some(collapsed_panel.show(ctx, |ui| add_contents(ui, how_expanded)))
|
||||||
@@ -1042,20 +1072,26 @@ impl TopBottomPanel {
|
|||||||
.show(ctx, |ui| add_contents(ui, how_expanded));
|
.show(ctx, |ui| add_contents(ui, how_expanded));
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(expanded_panel.show(ctx, |ui| add_contents(ui, how_expanded)))
|
Some(expanded_panel.show_dyn(
|
||||||
|
ctx,
|
||||||
|
Some(is_expanded),
|
||||||
|
Box::new(|ui| add_contents(ui, how_expanded)),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show either a collapsed or a expanded panel, with a nice animation between.
|
/// Show either a collapsed or a expanded panel, with a nice animation between.
|
||||||
|
///
|
||||||
|
/// The panel supports drag-to-close, and you can also call [`Ui::close`] from within the panel to close it.
|
||||||
pub fn show_animated_between_inside<R>(
|
pub fn show_animated_between_inside<R>(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
is_expanded: bool,
|
is_expanded: &mut bool,
|
||||||
collapsed_panel: Self,
|
collapsed_panel: Self,
|
||||||
expanded_panel: Self,
|
expanded_panel: Self,
|
||||||
add_contents: impl FnOnce(&mut Ui, f32) -> R,
|
add_contents: impl FnOnce(&mut Ui, f32) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
let how_expanded =
|
let how_expanded =
|
||||||
animate_expansion(ui.ctx(), expanded_panel.id.with("animation"), is_expanded);
|
animate_expansion(ui.ctx(), expanded_panel.id.with("animation"), *is_expanded);
|
||||||
|
|
||||||
if 0.0 == how_expanded {
|
if 0.0 == how_expanded {
|
||||||
collapsed_panel.show_inside(ui, |ui| add_contents(ui, how_expanded))
|
collapsed_panel.show_inside(ui, |ui| add_contents(ui, how_expanded))
|
||||||
@@ -1080,7 +1116,11 @@ impl TopBottomPanel {
|
|||||||
.exact_height(fake_height)
|
.exact_height(fake_height)
|
||||||
.show_inside(ui, |ui| add_contents(ui, how_expanded))
|
.show_inside(ui, |ui| add_contents(ui, how_expanded))
|
||||||
} else {
|
} else {
|
||||||
expanded_panel.show_inside(ui, |ui| add_contents(ui, how_expanded))
|
expanded_panel.show_inside_dyn(
|
||||||
|
ui,
|
||||||
|
Some(is_expanded),
|
||||||
|
Box::new(|ui| add_contents(ui, how_expanded)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -337,14 +337,13 @@ impl WrapApp {
|
|||||||
fn backend_panel(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) -> Command {
|
fn backend_panel(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) -> Command {
|
||||||
// The backend-panel can be toggled on/off.
|
// The backend-panel can be toggled on/off.
|
||||||
// We show a little animation when the user switches it.
|
// We show a little animation when the user switches it.
|
||||||
let is_open =
|
|
||||||
self.state.backend_panel.open || ctx.memory(|mem| mem.everything_is_visible());
|
|
||||||
|
|
||||||
let mut cmd = Command::Nothing;
|
let mut cmd = Command::Nothing;
|
||||||
|
|
||||||
|
let mut open = self.state.backend_panel.open;
|
||||||
|
|
||||||
egui::SidePanel::left("backend_panel")
|
egui::SidePanel::left("backend_panel")
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
.show_animated(ctx, is_open, |ui| {
|
.show_animated(ctx, &mut open, |ui| {
|
||||||
ui.add_space(4.0);
|
ui.add_space(4.0);
|
||||||
ui.vertical_centered(|ui| {
|
ui.vertical_centered(|ui| {
|
||||||
ui.heading("💻 Backend");
|
ui.heading("💻 Backend");
|
||||||
@@ -354,6 +353,8 @@ impl WrapApp {
|
|||||||
self.backend_panel_contents(ui, frame, &mut cmd);
|
self.backend_panel_contents(ui, frame, &mut cmd);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.state.backend_panel.open = open;
|
||||||
|
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user