mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40: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:
@@ -57,8 +57,8 @@ impl From<HPlacement> for Placement {
|
||||
#[inline]
|
||||
fn from(placement: HPlacement) -> Self {
|
||||
match placement {
|
||||
HPlacement::Left => Placement::LeftBottom,
|
||||
HPlacement::Right => Placement::RightTop,
|
||||
HPlacement::Left => Self::LeftBottom,
|
||||
HPlacement::Right => Self::RightTop,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,8 +67,8 @@ impl From<VPlacement> for Placement {
|
||||
#[inline]
|
||||
fn from(placement: VPlacement) -> Self {
|
||||
match placement {
|
||||
VPlacement::Top => Placement::RightTop,
|
||||
VPlacement::Bottom => Placement::LeftBottom,
|
||||
VPlacement::Top => Self::RightTop,
|
||||
VPlacement::Bottom => Self::LeftBottom,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ impl Bar {
|
||||
/// - `value`: Height of the bar (if vertical).
|
||||
///
|
||||
/// By default the bar is vertical and its base is at zero.
|
||||
pub fn new(argument: f64, height: f64) -> Bar {
|
||||
Bar {
|
||||
pub fn new(argument: f64, height: f64) -> Self {
|
||||
Self {
|
||||
argument,
|
||||
value: height,
|
||||
orientation: Orientation::default(),
|
||||
|
||||
@@ -184,7 +184,7 @@ impl HLine {
|
||||
|
||||
impl PlotItem for HLine {
|
||||
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
let HLine {
|
||||
let Self {
|
||||
y,
|
||||
stroke,
|
||||
highlight,
|
||||
@@ -306,7 +306,7 @@ impl VLine {
|
||||
|
||||
impl PlotItem for VLine {
|
||||
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
|
||||
let VLine {
|
||||
let Self {
|
||||
x,
|
||||
stroke,
|
||||
highlight,
|
||||
@@ -1350,8 +1350,8 @@ pub struct BarChart {
|
||||
|
||||
impl BarChart {
|
||||
/// Create a bar chart. It defaults to vertically oriented elements.
|
||||
pub fn new(bars: Vec<Bar>) -> BarChart {
|
||||
BarChart {
|
||||
pub fn new(bars: Vec<Bar>) -> Self {
|
||||
Self {
|
||||
bars,
|
||||
default_color: Color32::TRANSPARENT,
|
||||
name: String::new(),
|
||||
@@ -1427,7 +1427,7 @@ impl BarChart {
|
||||
/// Add a custom way to format an element.
|
||||
/// Can be used to display a set number of decimals or custom labels.
|
||||
#[inline]
|
||||
pub fn element_formatter(mut self, formatter: Box<dyn Fn(&Bar, &BarChart) -> String>) -> Self {
|
||||
pub fn element_formatter(mut self, formatter: Box<dyn Fn(&Bar, &Self) -> String>) -> Self {
|
||||
self.element_formatter = Some(formatter);
|
||||
self
|
||||
}
|
||||
@@ -1436,7 +1436,7 @@ impl BarChart {
|
||||
/// Positive values are stacked on top of other positive values.
|
||||
/// Negative values are stacked below other negative values.
|
||||
#[inline]
|
||||
pub fn stack_on(mut self, others: &[&BarChart]) -> Self {
|
||||
pub fn stack_on(mut self, others: &[&Self]) -> Self {
|
||||
for (index, bar) in self.bars.iter_mut().enumerate() {
|
||||
let new_base_offset = if bar.value.is_sign_positive() {
|
||||
others
|
||||
@@ -1599,10 +1599,8 @@ impl BoxPlot {
|
||||
|
||||
/// Add a custom way to format an element.
|
||||
/// Can be used to display a set number of decimals or custom labels.
|
||||
pub fn element_formatter(
|
||||
mut self,
|
||||
formatter: Box<dyn Fn(&BoxElem, &BoxPlot) -> String>,
|
||||
) -> Self {
|
||||
#[inline]
|
||||
pub fn element_formatter(mut self, formatter: Box<dyn Fn(&BoxElem, &Self) -> String>) -> Self {
|
||||
self.element_formatter = Some(formatter);
|
||||
self
|
||||
}
|
||||
@@ -1786,11 +1784,11 @@ pub(super) fn rulers_at_value(
|
||||
cursors.push(Cursor::Horizontal { y: value.y });
|
||||
}
|
||||
|
||||
let mut prefix = String::new();
|
||||
|
||||
if !name.is_empty() {
|
||||
prefix = format!("{name}\n");
|
||||
}
|
||||
let prefix = if name.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!("{name}\n")
|
||||
};
|
||||
|
||||
let text = {
|
||||
let scale = plot.transform.dvalue_dpos();
|
||||
|
||||
@@ -90,13 +90,13 @@ impl LineStyle {
|
||||
}
|
||||
_ => {
|
||||
match self {
|
||||
LineStyle::Solid => {
|
||||
Self::Solid => {
|
||||
if highlight {
|
||||
stroke.width *= 2.0;
|
||||
}
|
||||
shapes.push(Shape::line(line, stroke));
|
||||
}
|
||||
LineStyle::Dotted { spacing } => {
|
||||
Self::Dotted { spacing } => {
|
||||
// Take the stroke width for the radius even though it's not "correct", otherwise
|
||||
// the dots would become too small.
|
||||
let mut radius = stroke.width;
|
||||
@@ -105,7 +105,7 @@ impl LineStyle {
|
||||
}
|
||||
shapes.extend(Shape::dotted_line(&line, stroke.color, *spacing, radius));
|
||||
}
|
||||
LineStyle::Dashed { length } => {
|
||||
Self::Dashed { length } => {
|
||||
if highlight {
|
||||
stroke.width *= 2.0;
|
||||
}
|
||||
@@ -126,9 +126,9 @@ impl LineStyle {
|
||||
impl ToString for LineStyle {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
LineStyle::Solid => "Solid".into(),
|
||||
LineStyle::Dotted { spacing } => format!("Dotted{spacing}Px"),
|
||||
LineStyle::Dashed { length } => format!("Dashed{length}Px"),
|
||||
Self::Solid => "Solid".into(),
|
||||
Self::Dotted { spacing } => format!("Dotted{spacing}Px"),
|
||||
Self::Dashed { length } => format!("Dashed{length}Px"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,8 +190,8 @@ impl PlotPoints {
|
||||
|
||||
pub fn points(&self) -> &[PlotPoint] {
|
||||
match self {
|
||||
PlotPoints::Owned(points) => points.as_slice(),
|
||||
PlotPoints::Generator(_) => &[],
|
||||
Self::Owned(points) => points.as_slice(),
|
||||
Self::Generator(_) => &[],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,8 +268,8 @@ impl PlotPoints {
|
||||
/// Returns true if there are no data points available and there is no function to generate any.
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
match self {
|
||||
PlotPoints::Owned(points) => points.is_empty(),
|
||||
PlotPoints::Generator(_) => false,
|
||||
Self::Owned(points) => points.is_empty(),
|
||||
Self::Generator(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,14 +305,14 @@ impl PlotPoints {
|
||||
|
||||
pub(super) fn bounds(&self) -> PlotBounds {
|
||||
match self {
|
||||
PlotPoints::Owned(points) => {
|
||||
Self::Owned(points) => {
|
||||
let mut bounds = PlotBounds::NOTHING;
|
||||
for point in points {
|
||||
bounds.extend_with(point);
|
||||
}
|
||||
bounds
|
||||
}
|
||||
PlotPoints::Generator(generator) => generator.estimate_bounds(),
|
||||
Self::Generator(generator) => generator.estimate_bounds(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,7 +336,7 @@ pub enum MarkerShape {
|
||||
|
||||
impl MarkerShape {
|
||||
/// Get a vector containing all marker shapes.
|
||||
pub fn all() -> impl ExactSizeIterator<Item = MarkerShape> {
|
||||
pub fn all() -> impl ExactSizeIterator<Item = Self> {
|
||||
[
|
||||
Self::Circle,
|
||||
Self::Diamond,
|
||||
|
||||
@@ -14,12 +14,12 @@ pub enum Corner {
|
||||
}
|
||||
|
||||
impl Corner {
|
||||
pub fn all() -> impl Iterator<Item = Corner> {
|
||||
pub fn all() -> impl Iterator<Item = Self> {
|
||||
[
|
||||
Corner::LeftTop,
|
||||
Corner::RightTop,
|
||||
Corner::LeftBottom,
|
||||
Corner::RightBottom,
|
||||
Self::LeftTop,
|
||||
Self::RightTop,
|
||||
Self::LeftBottom,
|
||||
Self::RightBottom,
|
||||
]
|
||||
.iter()
|
||||
.copied()
|
||||
|
||||
@@ -108,27 +108,27 @@ impl PlotBounds {
|
||||
self.max[1] += pad;
|
||||
}
|
||||
|
||||
pub(crate) fn merge_x(&mut self, other: &PlotBounds) {
|
||||
pub(crate) fn merge_x(&mut self, other: &Self) {
|
||||
self.min[0] = self.min[0].min(other.min[0]);
|
||||
self.max[0] = self.max[0].max(other.max[0]);
|
||||
}
|
||||
|
||||
pub(crate) fn merge_y(&mut self, other: &PlotBounds) {
|
||||
pub(crate) fn merge_y(&mut self, other: &Self) {
|
||||
self.min[1] = self.min[1].min(other.min[1]);
|
||||
self.max[1] = self.max[1].max(other.max[1]);
|
||||
}
|
||||
|
||||
pub(crate) fn set_x(&mut self, other: &PlotBounds) {
|
||||
pub(crate) fn set_x(&mut self, other: &Self) {
|
||||
self.min[0] = other.min[0];
|
||||
self.max[0] = other.max[0];
|
||||
}
|
||||
|
||||
pub(crate) fn set_y(&mut self, other: &PlotBounds) {
|
||||
pub(crate) fn set_y(&mut self, other: &Self) {
|
||||
self.min[1] = other.min[1];
|
||||
self.max[1] = other.max[1];
|
||||
}
|
||||
|
||||
pub(crate) fn merge(&mut self, other: &PlotBounds) {
|
||||
pub(crate) fn merge(&mut self, other: &Self) {
|
||||
self.min[0] = self.min[0].min(other.min[0]);
|
||||
self.min[1] = self.min[1].min(other.min[1]);
|
||||
self.max[0] = self.max[0].max(other.max[0]);
|
||||
|
||||
Reference in New Issue
Block a user