1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Fix lints in atom_widget.rs

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lucas Meurer
2026-08-17 17:38:56 +02:00
parent 3ea5daf199
commit f337ddb0f9
3 changed files with 31 additions and 25 deletions

View File

@@ -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 emath::{Align, Pos2, Rect, Vec2};
use epaint::Direction; use epaint::Direction;
@@ -24,23 +27,23 @@ pub trait AtomWidget<'a> {
} }
impl<'a> AtomWidget<'a> for AtomLayout<'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 self
} }
} }
impl<'a> AtomWidget<'a> for Atom<'a> { 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) AtomLayout::new(self)
} }
} }
impl<'a> AtomWidget<'a> for AtomKind<'a> { 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) AtomLayout::new(self)
} }
} }
impl<'a> AtomWidget<'a> for Atoms<'a> { 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) AtomLayout::new(self)
} }
} }
@@ -111,11 +114,11 @@ impl IsAtomWidgetContext for Ui {
} }
fn read_response(&self, id: Id) -> Response { 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 { fn child_ui(&mut self, builder: UiBuilder) -> Self {
Ui::new_child(self, builder) Self::new_child(self, builder)
} }
} }
@@ -148,7 +151,7 @@ impl<'ui, 'layout> AtomUi<'ui, 'layout> {
&mut self, &mut self,
builder: AtomLayout<'layout>, builder: AtomLayout<'layout>,
mut atom: Atom<'layout>, mut atom: Atom<'layout>,
add_content: impl FnOnce(&mut AtomUi) -> R, add_content: impl FnOnce(&mut AtomUi<'_, '_>) -> R,
) -> InnerResponse<R> { ) -> InnerResponse<R> {
let mut child = AtomUi::new(self.ctx, builder); let mut child = AtomUi::new(self.ctx, builder);
let inner = add_content(&mut child); let inner = add_content(&mut child);
@@ -164,7 +167,7 @@ impl<'ui, 'layout> AtomUi<'ui, 'layout> {
pub fn vertical<R>( pub fn vertical<R>(
&mut self, &mut self,
atom: Atom<'layout>, atom: Atom<'layout>,
add_content: impl FnOnce(&mut AtomUi) -> R, add_content: impl FnOnce(&mut AtomUi<'_, '_>) -> R,
) -> InnerResponse<R> { ) -> InnerResponse<R> {
self.scope_builder( self.scope_builder(
AtomLayout::default().direction(Direction::TopDown), AtomLayout::default().direction(Direction::TopDown),
@@ -181,18 +184,19 @@ impl<'ui, 'layout> AtomUi<'ui, 'layout> {
pub fn immediate_scope<R>( pub fn immediate_scope<R>(
&mut self, &mut self,
mut ui_builder: UiBuilder, mut ui_builder: UiBuilder,
mut atom: Atom<'layout>, atom: Atom<'layout>,
add_content: impl FnOnce(&mut Ui) -> R, add_content: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> { ) -> InnerResponse<R> {
let sizing_id = self.ctx.make_auto_id(); 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; let size = if sizing_response.rect.is_finite() && sizing_response.rect.is_positive() {
if sizing_response.rect.is_finite() && sizing_response.rect.is_positive() { sizing_response
size = sizing_response
.intrinsic_size() .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))); 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 { impl Ui {
pub fn atom_builder<T>( pub fn atom_builder<T>(
&mut self, &mut self,
builder: AtomLayout, builder: AtomLayout<'_>,
add_contents: impl FnOnce(&mut AtomUi) -> T, add_contents: impl FnOnce(&mut AtomUi<'_, '_>) -> T,
) -> InnerResponse<T> { ) -> InnerResponse<T> {
let mut ui = AtomUi::new(self, builder); let mut ui = AtomUi::new(self, builder);
let inner = add_contents(&mut ui); let inner = add_contents(&mut ui);
let AtomUi { ctx, layout } = ui; let AtomUi { ctx: _, layout } = ui;
InnerResponse { InnerResponse {
inner, inner,
response: self.add(layout), response: self.add(layout),
} }
} }
pub fn atom<T>(&mut self, add_contents: impl FnOnce(&mut AtomUi) -> T) -> InnerResponse<T> { pub fn atom<T>(
&mut self,
add_contents: impl FnOnce(&mut AtomUi<'_, '_>) -> T,
) -> InnerResponse<T> {
self.atom_builder(AtomLayout::default(), add_contents) self.atom_builder(AtomLayout::default(), add_contents)
} }
} }

View File

@@ -2,16 +2,16 @@ mod atom;
mod atom_ext; mod atom_ext;
mod atom_kind; mod atom_kind;
mod atom_layout; mod atom_layout;
mod atom_widget;
mod atoms; mod atoms;
mod sized_atom; mod sized_atom;
mod sized_atom_kind; mod sized_atom_kind;
mod atom_widget;
pub use atom::*; pub use atom::*;
pub use atom_ext::*; pub use atom_ext::*;
pub use atom_kind::*; pub use atom_kind::*;
pub use atom_layout::*; pub use atom_layout::*;
pub use atom_widget::*;
pub use atoms::*; pub use atoms::*;
pub use sized_atom::*; pub use sized_atom::*;
pub use sized_atom_kind::*; pub use sized_atom_kind::*;
pub use atom_widget::*;

View File

@@ -3,8 +3,7 @@ use epaint::Margin;
use crate::{ use crate::{
Atom, AtomExt as _, AtomKind, AtomLayout, AtomWidget, AtomWidgetContext, Atoms, Color32, Atom, AtomExt as _, AtomKind, AtomLayout, AtomWidget, AtomWidgetContext, Atoms, Color32,
CornerRadius, FontSelection, Frame, Image, IntoAtoms, NumExt as _, Response, Sense, Stroke, CornerRadius, FontSelection, Frame, Image, IntoAtoms, NumExt as _, Response, Sense, Stroke,
TextStyle, TextWrapMode, Vec2, WidgetInfo, WidgetText, WidgetType, TextStyle, TextWrapMode, Vec2, WidgetInfo, WidgetText, WidgetType, impl_widget_for_atom_widget,
impl_widget_for_atom_widget,
widget_style::{ButtonStyle, Classes, HasClasses, SELECTED_CLASS, WidgetState}, widget_style::{ButtonStyle, Classes, HasClasses, SELECTED_CLASS, WidgetState},
}; };