From 6d5e2acaed1f9fd2108f2af921f2d27c3455c7f2 Mon Sep 17 00:00:00 2001 From: norlock Date: Wed, 17 Jul 2024 00:59:09 +0200 Subject: [PATCH] fmt and clippy Fix collapse action --- crates/egui/src/containers/collapsing_header.rs | 12 +++--------- crates/egui/src/containers/window.rs | 6 ++---- crates/egui_demo_lib/src/demo/about.rs | 10 +++++++--- crates/egui_demo_lib/src/demo/demo_app_windows.rs | 3 ++- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/crates/egui/src/containers/collapsing_header.rs b/crates/egui/src/containers/collapsing_header.rs index 48e4dfbb993..5cba637098e 100644 --- a/crates/egui/src/containers/collapsing_header.rs +++ b/crates/egui/src/containers/collapsing_header.rs @@ -66,14 +66,8 @@ impl CollapsingState { match action { WindowAction::Show => self.state.shown = true, WindowAction::Hide => self.state.shown = false, - WindowAction::Expand => { - self.state.shown = true; - self.state.expanded = true; - } - WindowAction::Collapse => { - self.state.shown = true; - self.state.expanded = true; - } + WindowAction::Expand => self.state.expanded = true, + WindowAction::Collapse => self.state.expanded = false, WindowAction::ToggleShow => { self.state.shown = !self.state.shown; } @@ -309,7 +303,7 @@ pub struct HeaderResponse<'ui, HeaderRet> { } impl<'ui, HeaderRet> HeaderResponse<'ui, HeaderRet> { - #[deprecated = "Use het `HeaderResponse::is_expanded`"] + #[deprecated = "Use the `HeaderResponse::is_expanded` instead"] pub fn is_open(&self) -> bool { self.is_expanded() } diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 2ded86a7082..30b0f0aa099 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -91,8 +91,8 @@ impl<'open> Window<'open> { self } - /// Call this to programmatically expand, collapse, show, hide the window. - /// The Option value will be taken, so the option will be set to None. + /// Call this to programmatically expand/collapse or to show/hide the window. + /// The passed Option value will be taken, so the option will be set to None. #[inline] pub fn window_action(mut self, action: &mut Option) -> Self { self.window_action = action.take(); @@ -477,8 +477,6 @@ impl<'open> Window<'open> { // Add border padding to the inner margin to prevent it from covering the contents window_frame.inner_margin += border_padding; - //let is_explicitly_closed = matches!(open, Some(false)); - //let is_open = !is_explicitly_closed || ctx.memory(|mem| mem.everything_is_visible()); let all_visible = ctx.memory(|mem| mem.everything_is_visible()); let area_id = area.id; diff --git a/crates/egui_demo_lib/src/demo/about.rs b/crates/egui_demo_lib/src/demo/about.rs index 0795a226277..f21b2e7ff20 100644 --- a/crates/egui_demo_lib/src/demo/about.rs +++ b/crates/egui_demo_lib/src/demo/about.rs @@ -1,5 +1,5 @@ -use egui::WindowAction; use crate::demo::Demo; +use egui::WindowAction; #[derive(Default)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -25,7 +25,12 @@ impl crate::Demo for About { } impl About { - pub fn show_action(&mut self, ctx: &egui::Context, open: &mut bool, action: &mut Option) { + pub fn show_action( + &mut self, + ctx: &egui::Context, + open: &mut bool, + action: &mut Option, + ) { egui::Window::new(self.name()) .default_width(320.0) .default_height(480.0) @@ -38,7 +43,6 @@ impl About { self.ui(ui); }); } - } impl crate::View for About { diff --git a/crates/egui_demo_lib/src/demo/demo_app_windows.rs b/crates/egui_demo_lib/src/demo/demo_app_windows.rs index c3dac45822d..61eae8e6649 100644 --- a/crates/egui_demo_lib/src/demo/demo_app_windows.rs +++ b/crates/egui_demo_lib/src/demo/demo_app_windows.rs @@ -296,7 +296,8 @@ impl DemoWindows { /// Show the open windows. fn show_windows(&mut self, ctx: &Context) { - self.about.show_action(ctx, &mut self.about_is_open, &mut self.about_window_action); + self.about + .show_action(ctx, &mut self.about_is_open, &mut self.about_window_action); self.demos.windows(ctx); self.tests.windows(ctx); }