Skip to content

Commit

Permalink
Fix and un-allow clippy::use_self lints (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys authored Dec 19, 2024
1 parent 326cb2b commit ee44114
Show file tree
Hide file tree
Showing 51 changed files with 353 additions and 367 deletions.
18 changes: 9 additions & 9 deletions masonry/src/box_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl BoxConstraints {
/// An unbounded box constraints object.
///
/// Can be satisfied by any nonnegative size.
pub const UNBOUNDED: BoxConstraints = BoxConstraints {
pub const UNBOUNDED: Self = Self {
min: Size::ZERO,
max: Size::new(f64::INFINITY, f64::INFINITY),
};
Expand All @@ -44,8 +44,8 @@ impl BoxConstraints {
/// so that the layout is aligned to integers.
///
/// [rounded away from zero]: Size::expand
pub fn new(min: Size, max: Size) -> BoxConstraints {
BoxConstraints {
pub fn new(min: Size, max: Size) -> Self {
Self {
min: min.expand(),
max: max.expand(),
}
Expand All @@ -59,9 +59,9 @@ impl BoxConstraints {
/// so that the layout is aligned to integers.
///
/// [rounded away from zero]: Size::expand
pub fn tight(size: Size) -> BoxConstraints {
pub fn tight(size: Size) -> Self {
let size = size.expand();
BoxConstraints {
Self {
min: size,
max: size,
}
Expand All @@ -70,8 +70,8 @@ impl BoxConstraints {
/// Create a "loose" version of the constraints.
///
/// Make a version with zero minimum size, but the same maximum size.
pub fn loosen(&self) -> BoxConstraints {
BoxConstraints {
pub fn loosen(&self) -> Self {
Self {
min: Size::ZERO,
max: self.max,
}
Expand Down Expand Up @@ -152,7 +152,7 @@ impl BoxConstraints {
/// so that the layout is aligned to integers.
///
/// [rounded away from zero]: Size::expand
pub fn shrink(&self, diff: impl Into<Size>) -> BoxConstraints {
pub fn shrink(&self, diff: impl Into<Size>) -> Self {
let diff = diff.into().expand();
let min = Size::new(
(self.min().width - diff.width).max(0.),
Expand All @@ -163,7 +163,7 @@ impl BoxConstraints {
(self.max().height - diff.height).max(0.),
);

BoxConstraints::new(min, max)
Self::new(min, max)
}

/// Test whether these constraints contain the given `Size`.
Expand Down
2 changes: 1 addition & 1 deletion masonry/src/debug_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct DebugLogger {

impl DebugLogger {
pub fn new(activated: bool) -> Self {
let mut new_self = DebugLogger {
let mut new_self = Self {
activated,
layout_tree: Default::default(),
widget_states: Default::default(),
Expand Down
34 changes: 17 additions & 17 deletions masonry/src/debug_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,49 +76,49 @@ pub struct Timeline {
impl Display for Value {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Value::Empty => write!(f, ""),
Value::String(string) => write!(f, "{}", string),
Value::Bool(b) => write!(f, "{}", b),
Value::Rect(rect) => write!(f, "{:?}", rect),
Value::Id(id) => write!(f, "{}", id),
Value::LogId(_) => write!(f, "<snapshot>"),
Self::Empty => write!(f, ""),
Self::String(string) => write!(f, "{}", string),
Self::Bool(b) => write!(f, "{}", b),
Self::Rect(rect) => write!(f, "{:?}", rect),
Self::Id(id) => write!(f, "{}", id),
Self::LogId(_) => write!(f, "<snapshot>"),
}
}
}

impl From<String> for Value {
fn from(value: String) -> Value {
Value::String(value)
fn from(value: String) -> Self {
Self::String(value)
}
}

impl From<bool> for Value {
fn from(value: bool) -> Value {
Value::Bool(value)
fn from(value: bool) -> Self {
Self::Bool(value)
}
}

impl From<Rect> for Value {
fn from(value: Rect) -> Value {
Value::Rect(value)
fn from(value: Rect) -> Self {
Self::Rect(value)
}
}

impl From<MyWidgetId> for Value {
fn from(value: MyWidgetId) -> Value {
Value::Id(value)
fn from(value: MyWidgetId) -> Self {
Self::Id(value)
}
}

impl From<LogId> for Value {
fn from(value: LogId) -> Value {
Value::LogId(value)
fn from(value: LogId) -> Self {
Self::LogId(value)
}
}

impl StateTree {
pub fn new(name: impl Into<String>, value: impl Into<Value>) -> Self {
StateTree {
Self {
name: name.into(),
value: value.into(),
folded_by_default: false,
Expand Down
114 changes: 57 additions & 57 deletions masonry/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ fn button_bit(button: PointerButton) -> u8 {
impl PointerButtons {
/// Create a new empty set.
#[inline]
pub fn new() -> PointerButtons {
PointerButtons(0)
pub fn new() -> Self {
Self(0)
}

/// Add the `button` to the set.
Expand Down Expand Up @@ -97,12 +97,12 @@ impl PointerButtons {

/// Returns `true` if all the `buttons` are in the set.
#[inline]
pub fn contains_all(self, buttons: PointerButtons) -> bool {
pub fn contains_all(self, buttons: Self) -> bool {
self.0 & buttons.0 == buttons.0
}

/// Adds all the `buttons` to the set.
pub fn extend(&mut self, buttons: PointerButtons) {
pub fn extend(&mut self, buttons: Self) {
self.0 |= buttons.0;
}

Expand Down Expand Up @@ -325,84 +325,84 @@ impl PointerEvent {
focus: false,
force: None,
};
PointerEvent::PointerLeave(pointer_state)
Self::PointerLeave(pointer_state)
}

pub fn pointer_state(&self) -> &PointerState {
match self {
PointerEvent::PointerDown(_, state)
| PointerEvent::PointerUp(_, state)
| PointerEvent::PointerMove(state)
| PointerEvent::PointerEnter(state)
| PointerEvent::PointerLeave(state)
| PointerEvent::MouseWheel(_, state)
| PointerEvent::HoverFile(_, state)
| PointerEvent::DropFile(_, state)
| PointerEvent::HoverFileCancel(state)
| PointerEvent::Pinch(_, state) => state,
Self::PointerDown(_, state)
| Self::PointerUp(_, state)
| Self::PointerMove(state)
| Self::PointerEnter(state)
| Self::PointerLeave(state)
| Self::MouseWheel(_, state)
| Self::HoverFile(_, state)
| Self::DropFile(_, state)
| Self::HoverFileCancel(state)
| Self::Pinch(_, state) => state,
}
}

pub fn position(&self) -> Option<LogicalPosition<f64>> {
match self {
PointerEvent::PointerLeave(_) | PointerEvent::HoverFileCancel(_) => None,
Self::PointerLeave(_) | Self::HoverFileCancel(_) => None,
_ => Some(self.pointer_state().position),
}
}

pub fn short_name(&self) -> &'static str {
match self {
PointerEvent::PointerDown(_, _) => "PointerDown",
PointerEvent::PointerUp(_, _) => "PointerUp",
PointerEvent::PointerMove(_) => "PointerMove",
PointerEvent::PointerEnter(_) => "PointerEnter",
PointerEvent::PointerLeave(_) => "PointerLeave",
PointerEvent::MouseWheel(_, _) => "MouseWheel",
PointerEvent::HoverFile(_, _) => "HoverFile",
PointerEvent::DropFile(_, _) => "DropFile",
PointerEvent::HoverFileCancel(_) => "HoverFileCancel",
PointerEvent::Pinch(_, _) => "Pinch",
Self::PointerDown(_, _) => "PointerDown",
Self::PointerUp(_, _) => "PointerUp",
Self::PointerMove(_) => "PointerMove",
Self::PointerEnter(_) => "PointerEnter",
Self::PointerLeave(_) => "PointerLeave",
Self::MouseWheel(_, _) => "MouseWheel",
Self::HoverFile(_, _) => "HoverFile",
Self::DropFile(_, _) => "DropFile",
Self::HoverFileCancel(_) => "HoverFileCancel",
Self::Pinch(_, _) => "Pinch",
}
}

pub fn is_high_density(&self) -> bool {
match self {
PointerEvent::PointerDown(_, _) => false,
PointerEvent::PointerUp(_, _) => false,
PointerEvent::PointerMove(_) => true,
PointerEvent::PointerEnter(_) => false,
PointerEvent::PointerLeave(_) => false,
PointerEvent::MouseWheel(_, _) => true,
PointerEvent::HoverFile(_, _) => true,
PointerEvent::DropFile(_, _) => false,
PointerEvent::HoverFileCancel(_) => false,
PointerEvent::Pinch(_, _) => true,
Self::PointerDown(_, _) => false,
Self::PointerUp(_, _) => false,
Self::PointerMove(_) => true,
Self::PointerEnter(_) => false,
Self::PointerLeave(_) => false,
Self::MouseWheel(_, _) => true,
Self::HoverFile(_, _) => true,
Self::DropFile(_, _) => false,
Self::HoverFileCancel(_) => false,
Self::Pinch(_, _) => true,
}
}
}

impl TextEvent {
pub fn short_name(&self) -> &'static str {
match self {
TextEvent::KeyboardKey(KeyEvent { repeat: true, .. }, _) => "KeyboardKey (repeat)",
TextEvent::KeyboardKey(_, _) => "KeyboardKey",
TextEvent::Ime(Ime::Disabled) => "Ime::Disabled",
TextEvent::Ime(Ime::Enabled) => "Ime::Enabled",
TextEvent::Ime(Ime::Commit(_)) => "Ime::Commit",
TextEvent::Ime(Ime::Preedit(s, _)) if s.is_empty() => "Ime::Preedit(\"\")",
TextEvent::Ime(Ime::Preedit(_, _)) => "Ime::Preedit",
TextEvent::ModifierChange(_) => "ModifierChange",
TextEvent::FocusChange(_) => "FocusChange",
Self::KeyboardKey(KeyEvent { repeat: true, .. }, _) => "KeyboardKey (repeat)",
Self::KeyboardKey(_, _) => "KeyboardKey",
Self::Ime(Ime::Disabled) => "Ime::Disabled",
Self::Ime(Ime::Enabled) => "Ime::Enabled",
Self::Ime(Ime::Commit(_)) => "Ime::Commit",
Self::Ime(Ime::Preedit(s, _)) if s.is_empty() => "Ime::Preedit(\"\")",
Self::Ime(Ime::Preedit(_, _)) => "Ime::Preedit",
Self::ModifierChange(_) => "ModifierChange",
Self::FocusChange(_) => "FocusChange",
}
}

pub fn is_high_density(&self) -> bool {
match self {
TextEvent::KeyboardKey(_, _) => false,
TextEvent::Ime(_) => false,
Self::KeyboardKey(_, _) => false,
Self::Ime(_) => false,
// Basically every mouse click/scroll event seems to produce a modifier change event.
TextEvent::ModifierChange(_) => true,
TextEvent::FocusChange(_) => false,
Self::ModifierChange(_) => true,
Self::FocusChange(_) => false,
}
}
}
Expand Down Expand Up @@ -451,7 +451,7 @@ impl PointerState {
// It would be a lot better if winit could just make this constructor safe.
let device_id = unsafe { DeviceId::dummy() };

PointerState {
Self {
physical_position: PhysicalPosition::new(0.0, 0.0),
position: LogicalPosition::new(0.0, 0.0),
buttons: Default::default(),
Expand All @@ -469,13 +469,13 @@ impl Update {
/// Essentially returns the enum variant name.
pub fn short_name(&self) -> &str {
match self {
Update::WidgetAdded => "WidgetAdded",
Update::DisabledChanged(_) => "DisabledChanged",
Update::StashedChanged(_) => "StashedChanged",
Update::RequestPanToChild(_) => "RequestPanToChild",
Update::HoveredChanged(_) => "HoveredChanged",
Update::FocusChanged(_) => "FocusChanged",
Update::ChildFocusChanged(_) => "ChildFocusChanged",
Self::WidgetAdded => "WidgetAdded",
Self::DisabledChanged(_) => "DisabledChanged",
Self::StashedChanged(_) => "StashedChanged",
Self::RequestPanToChild(_) => "RequestPanToChild",
Self::HoveredChanged(_) => "HoveredChanged",
Self::FocusChanged(_) => "FocusChanged",
Self::ChildFocusChanged(_) => "ChildFocusChanged",
}
}
}
12 changes: 6 additions & 6 deletions masonry/src/event_loop_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ impl From<accesskit_winit::Event> for MasonryUserEvent {
impl From<WinitMouseButton> for PointerButton {
fn from(button: WinitMouseButton) -> Self {
match button {
WinitMouseButton::Left => PointerButton::Primary,
WinitMouseButton::Right => PointerButton::Secondary,
WinitMouseButton::Middle => PointerButton::Auxiliary,
WinitMouseButton::Back => PointerButton::X1,
WinitMouseButton::Forward => PointerButton::X2,
WinitMouseButton::Left => Self::Primary,
WinitMouseButton::Right => Self::Secondary,
WinitMouseButton::Middle => Self::Auxiliary,
WinitMouseButton::Back => Self::X1,
WinitMouseButton::Forward => Self::X2,
WinitMouseButton::Other(other) => {
warn!("Got winit MouseButton::Other({other}) which is not yet fully supported.");
PointerButton::Other
Self::Other
}
}
}
Expand Down
1 change: 0 additions & 1 deletion masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
#![expect(clippy::missing_assert_message, reason = "Deferred: Noisy")]
#![expect(clippy::return_self_not_must_use, reason = "Deferred: Noisy")]
#![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")]
#![expect(clippy::use_self, reason = "Deferred: Noisy")]
// https://github.com/rust-lang/rust/pull/130025
#![allow(missing_docs, reason = "We have many as-yet undocumented items")]
#![expect(unreachable_pub, reason = "Potentially controversial code style")]
Expand Down
22 changes: 11 additions & 11 deletions masonry/src/paint_scene_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,30 @@ pub fn stroke<'b>(
#[allow(unused)]
impl UnitPoint {
/// `(0.0, 0.0)`
pub const TOP_LEFT: UnitPoint = UnitPoint::new(0.0, 0.0);
pub const TOP_LEFT: Self = Self::new(0.0, 0.0);
/// `(0.5, 0.0)`
pub const TOP: UnitPoint = UnitPoint::new(0.5, 0.0);
pub const TOP: Self = Self::new(0.5, 0.0);
/// `(1.0, 0.0)`
pub const TOP_RIGHT: UnitPoint = UnitPoint::new(1.0, 0.0);
pub const TOP_RIGHT: Self = Self::new(1.0, 0.0);
/// `(0.0, 0.5)`
pub const LEFT: UnitPoint = UnitPoint::new(0.0, 0.5);
pub const LEFT: Self = Self::new(0.0, 0.5);
/// `(0.5, 0.5)`
pub const CENTER: UnitPoint = UnitPoint::new(0.5, 0.5);
pub const CENTER: Self = Self::new(0.5, 0.5);
/// `(1.0, 0.5)`
pub const RIGHT: UnitPoint = UnitPoint::new(1.0, 0.5);
pub const RIGHT: Self = Self::new(1.0, 0.5);
/// `(0.0, 1.0)`
pub const BOTTOM_LEFT: UnitPoint = UnitPoint::new(0.0, 1.0);
pub const BOTTOM_LEFT: Self = Self::new(0.0, 1.0);
/// `(0.5, 1.0)`
pub const BOTTOM: UnitPoint = UnitPoint::new(0.5, 1.0);
pub const BOTTOM: Self = Self::new(0.5, 1.0);
/// `(1.0, 1.0)`
pub const BOTTOM_RIGHT: UnitPoint = UnitPoint::new(1.0, 1.0);
pub const BOTTOM_RIGHT: Self = Self::new(1.0, 1.0);

/// Create a new `UnitPoint`.
///
/// The `u` and `v` coordinates describe the point, with (0.0, 0.0) being
/// the top-left, and (1.0, 1.0) being the bottom-right.
pub const fn new(u: f64, v: f64) -> UnitPoint {
UnitPoint { u, v }
pub const fn new(u: f64, v: f64) -> Self {
Self { u, v }
}

/// Given a rectangle, resolve the point within the rectangle.
Expand Down
Loading

0 comments on commit ee44114

Please sign in to comment.