From f337ddb0f9307fee2676e5775c9a57b852a7023f Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Mon, 17 Aug 2026 17:38:56 +0200 Subject: [PATCH] Fix lints in `atom_widget.rs` Co-Authored-By: Claude Opus 5 (1M context) --- crates/egui/src/atomics/atom_widget.rs | 49 +++++++++++++++----------- crates/egui/src/atomics/mod.rs | 4 +-- crates/egui/src/widgets/button.rs | 3 +- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/crates/egui/src/atomics/atom_widget.rs b/crates/egui/src/atomics/atom_widget.rs index 4a0a7c151..e303dc95c 100644 --- a/crates/egui/src/atomics/atom_widget.rs +++ b/crates/egui/src/atomics/atom_widget.rs @@ -1,4 +1,7 @@ -use crate::{Atom, AtomExt, AtomKind, AtomLayout, Atoms, Button, Color32, Context, Id, InnerResponse, IntoAtoms, Layout, Response, Sense, Spacing, Style, Ui, UiBuilder, Visuals, Widget, WidgetRect}; +use crate::{ + Atom, AtomExt as _, AtomKind, AtomLayout, Atoms, Button, Context, Id, InnerResponse, IntoAtoms, + Layout, Response, Sense, Spacing, Style, Ui, UiBuilder, Visuals, WidgetRect, +}; use emath::{Align, Pos2, Rect, Vec2}; use epaint::Direction; @@ -24,23 +27,23 @@ pub trait AtomWidget<'a> { } impl<'a> AtomWidget<'a> for AtomLayout<'a> { - fn atom_ui(self, ui: &mut AtomWidgetContext, response: &mut Response) -> AtomLayout<'a> { + fn atom_ui(self, _ui: &mut AtomWidgetContext, _response: &mut Response) -> Self { self } } impl<'a> AtomWidget<'a> for Atom<'a> { - fn atom_ui(self, ui: &mut AtomWidgetContext, response: &mut Response) -> AtomLayout<'a> { + fn atom_ui(self, _ui: &mut AtomWidgetContext, _response: &mut Response) -> AtomLayout<'a> { AtomLayout::new(self) } } impl<'a> AtomWidget<'a> for AtomKind<'a> { - fn atom_ui(self, ui: &mut AtomWidgetContext, response: &mut Response) -> AtomLayout<'a> { + fn atom_ui(self, _ui: &mut AtomWidgetContext, _response: &mut Response) -> AtomLayout<'a> { AtomLayout::new(self) } } impl<'a> AtomWidget<'a> for Atoms<'a> { - fn atom_ui(self, ui: &mut AtomWidgetContext, response: &mut Response) -> AtomLayout<'a> { + fn atom_ui(self, _ui: &mut AtomWidgetContext, _response: &mut Response) -> AtomLayout<'a> { AtomLayout::new(self) } } @@ -111,11 +114,11 @@ impl IsAtomWidgetContext for Ui { } fn read_response(&self, id: Id) -> Response { - read_or_default_response(&self, id, Sense::hover()) + read_or_default_response(self, id, Sense::hover()) } - fn child_ui(&mut self, builder: UiBuilder) -> Ui { - Ui::new_child(self, builder) + fn child_ui(&mut self, builder: UiBuilder) -> Self { + Self::new_child(self, builder) } } @@ -148,7 +151,7 @@ impl<'ui, 'layout> AtomUi<'ui, 'layout> { &mut self, builder: AtomLayout<'layout>, mut atom: Atom<'layout>, - add_content: impl FnOnce(&mut AtomUi) -> R, + add_content: impl FnOnce(&mut AtomUi<'_, '_>) -> R, ) -> InnerResponse { let mut child = AtomUi::new(self.ctx, builder); let inner = add_content(&mut child); @@ -164,7 +167,7 @@ impl<'ui, 'layout> AtomUi<'ui, 'layout> { pub fn vertical( &mut self, atom: Atom<'layout>, - add_content: impl FnOnce(&mut AtomUi) -> R, + add_content: impl FnOnce(&mut AtomUi<'_, '_>) -> R, ) -> InnerResponse { self.scope_builder( AtomLayout::default().direction(Direction::TopDown), @@ -181,18 +184,19 @@ impl<'ui, 'layout> AtomUi<'ui, 'layout> { pub fn immediate_scope( &mut self, mut ui_builder: UiBuilder, - mut atom: Atom<'layout>, + atom: Atom<'layout>, add_content: impl FnOnce(&mut Ui) -> R, ) -> InnerResponse { let sizing_id = self.ctx.make_auto_id(); - let mut sizing_response = self.ctx.read_response(sizing_id); + let sizing_response = self.ctx.read_response(sizing_id); - let mut size = Vec2::ZERO; - if sizing_response.rect.is_finite() && sizing_response.rect.is_positive() { - size = sizing_response + let size = if sizing_response.rect.is_finite() && sizing_response.rect.is_positive() { + sizing_response .intrinsic_size() - .unwrap_or(sizing_response.rect.size()); - } + .unwrap_or_else(|| sizing_response.rect.size()) + } else { + Vec2::ZERO + }; let placement_response = self.add(atom.clone(), AtomLayout::new(atom.atom_size(size))); @@ -251,19 +255,22 @@ impl<'ui, 'layout> AtomUi<'ui, 'layout> { impl Ui { pub fn atom_builder( &mut self, - builder: AtomLayout, - add_contents: impl FnOnce(&mut AtomUi) -> T, + builder: AtomLayout<'_>, + add_contents: impl FnOnce(&mut AtomUi<'_, '_>) -> T, ) -> InnerResponse { let mut ui = AtomUi::new(self, builder); let inner = add_contents(&mut ui); - let AtomUi { ctx, layout } = ui; + let AtomUi { ctx: _, layout } = ui; InnerResponse { inner, response: self.add(layout), } } - pub fn atom(&mut self, add_contents: impl FnOnce(&mut AtomUi) -> T) -> InnerResponse { + pub fn atom( + &mut self, + add_contents: impl FnOnce(&mut AtomUi<'_, '_>) -> T, + ) -> InnerResponse { self.atom_builder(AtomLayout::default(), add_contents) } } diff --git a/crates/egui/src/atomics/mod.rs b/crates/egui/src/atomics/mod.rs index aa8919702..60fae4441 100644 --- a/crates/egui/src/atomics/mod.rs +++ b/crates/egui/src/atomics/mod.rs @@ -2,16 +2,16 @@ mod atom; mod atom_ext; mod atom_kind; mod atom_layout; +mod atom_widget; mod atoms; mod sized_atom; mod sized_atom_kind; -mod atom_widget; pub use atom::*; pub use atom_ext::*; pub use atom_kind::*; pub use atom_layout::*; +pub use atom_widget::*; pub use atoms::*; pub use sized_atom::*; pub use sized_atom_kind::*; -pub use atom_widget::*; diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index 82f8f43f0..bc55307d6 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -3,8 +3,7 @@ use epaint::Margin; use crate::{ Atom, AtomExt as _, AtomKind, AtomLayout, AtomWidget, AtomWidgetContext, Atoms, Color32, CornerRadius, FontSelection, Frame, Image, IntoAtoms, NumExt as _, Response, Sense, Stroke, - TextStyle, TextWrapMode, Vec2, WidgetInfo, WidgetText, WidgetType, - impl_widget_for_atom_widget, + TextStyle, TextWrapMode, Vec2, WidgetInfo, WidgetText, WidgetType, impl_widget_for_atom_widget, widget_style::{ButtonStyle, Classes, HasClasses, SELECTED_CLASS, WidgetState}, };