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

Use Self everywhere (#3787)

This turns on the clippy lint
[`clippy::use_self`](https://rust-lang.github.io/rust-clippy/v0.0.212/index.html#use_self)
and fixes it everywhere.
This commit is contained in:
Emil Ernerfeldt
2024-01-08 17:41:21 +01:00
committed by GitHub
parent 12ad9e7b36
commit 401de05630
72 changed files with 590 additions and 580 deletions

View File

@@ -66,9 +66,9 @@ fn shape_impl_send_sync() {
assert_send_sync::<Shape>();
}
impl From<Vec<Shape>> for Shape {
impl From<Vec<Self>> for Shape {
#[inline(always)]
fn from(shapes: Vec<Shape>) -> Self {
fn from(shapes: Vec<Self>) -> Self {
Self::Vec(shapes)
}
}
@@ -95,7 +95,7 @@ impl Shape {
/// A horizontal line.
pub fn hline(x: impl Into<Rangef>, y: f32, stroke: impl Into<Stroke>) -> Self {
let x = x.into();
Shape::LineSegment {
Self::LineSegment {
points: [pos2(x.min, y), pos2(x.max, y)],
stroke: stroke.into(),
}
@@ -104,7 +104,7 @@ impl Shape {
/// A vertical line.
pub fn vline(x: f32, y: impl Into<Rangef>, stroke: impl Into<Stroke>) -> Self {
let y = y.into();
Shape::LineSegment {
Self::LineSegment {
points: [pos2(x, y.min), pos2(x, y.max)],
stroke: stroke.into(),
}
@@ -182,7 +182,7 @@ impl Shape {
stroke: impl Into<Stroke>,
dash_length: f32,
gap_length: f32,
shapes: &mut Vec<Shape>,
shapes: &mut Vec<Self>,
) {
dashes_from_line(
points,
@@ -202,7 +202,7 @@ impl Shape {
dash_lengths: &[f32],
gap_lengths: &[f32],
dash_offset: f32,
shapes: &mut Vec<Shape>,
shapes: &mut Vec<Self>,
) {
dashes_from_line(
points,
@@ -309,7 +309,7 @@ impl Shape {
pub fn image(texture_id: TextureId, rect: Rect, uv: Rect, tint: Color32) -> Self {
let mut mesh = Mesh::with_texture(texture_id);
mesh.add_rect_with_uv(rect, uv, tint);
Shape::mesh(mesh)
Self::mesh(mesh)
}
/// The visual bounding rectangle (includes stroke widths)
@@ -346,9 +346,9 @@ impl Shape {
impl Shape {
#[inline(always)]
pub fn texture_id(&self) -> super::TextureId {
if let Shape::Mesh(mesh) = self {
if let Self::Mesh(mesh) = self {
mesh.texture_id
} else if let Shape::Rect(rect_shape) = self {
} else if let Self::Rect(rect_shape) = self {
rect_shape.fill_texture_id
} else {
super::TextureId::default()
@@ -358,45 +358,45 @@ impl Shape {
/// Move the shape by this many points, in-place.
pub fn translate(&mut self, delta: Vec2) {
match self {
Shape::Noop => {}
Shape::Vec(shapes) => {
Self::Noop => {}
Self::Vec(shapes) => {
for shape in shapes {
shape.translate(delta);
}
}
Shape::Circle(circle_shape) => {
Self::Circle(circle_shape) => {
circle_shape.center += delta;
}
Shape::LineSegment { points, .. } => {
Self::LineSegment { points, .. } => {
for p in points {
*p += delta;
}
}
Shape::Path(path_shape) => {
Self::Path(path_shape) => {
for p in &mut path_shape.points {
*p += delta;
}
}
Shape::Rect(rect_shape) => {
Self::Rect(rect_shape) => {
rect_shape.rect = rect_shape.rect.translate(delta);
}
Shape::Text(text_shape) => {
Self::Text(text_shape) => {
text_shape.pos += delta;
}
Shape::Mesh(mesh) => {
Self::Mesh(mesh) => {
mesh.translate(delta);
}
Shape::QuadraticBezier(bezier_shape) => {
Self::QuadraticBezier(bezier_shape) => {
bezier_shape.points[0] += delta;
bezier_shape.points[1] += delta;
bezier_shape.points[2] += delta;
}
Shape::CubicBezier(cubic_curve) => {
Self::CubicBezier(cubic_curve) => {
for p in &mut cubic_curve.points {
*p += delta;
}
}
Shape::Callback(shape) => {
Self::Callback(shape) => {
shape.rect = shape.rect.translate(delta);
}
}
@@ -484,7 +484,7 @@ impl PathShape {
/// Use [`Shape::line_segment`] instead if your line only connects two points.
#[inline]
pub fn line(points: Vec<Pos2>, stroke: impl Into<Stroke>) -> Self {
PathShape {
Self {
points,
closed: false,
fill: Default::default(),
@@ -495,7 +495,7 @@ impl PathShape {
/// A line that closes back to the start point again.
#[inline]
pub fn closed_line(points: Vec<Pos2>, stroke: impl Into<Stroke>) -> Self {
PathShape {
Self {
points,
closed: true,
fill: Default::default(),
@@ -512,7 +512,7 @@ impl PathShape {
fill: impl Into<Color32>,
stroke: impl Into<Stroke>,
) -> Self {
PathShape {
Self {
points,
closed: true,
fill: fill.into(),