diff --git a/crates/egui/src/containers/frame.rs b/crates/egui/src/containers/frame.rs index 6ce5cbc4..e9226975 100644 --- a/crates/egui/src/containers/frame.rs +++ b/crates/egui/src/containers/frame.rs @@ -127,8 +127,8 @@ impl Frame { } #[inline] - pub fn stroke(mut self, stroke: Stroke) -> Self { - self.stroke = stroke; + pub fn stroke(mut self, stroke: impl Into) -> Self { + self.stroke = stroke.into(); self } diff --git a/crates/egui/src/containers/resize.rs b/crates/egui/src/containers/resize.rs index 78917234..7274b6c5 100644 --- a/crates/egui/src/containers/resize.rs +++ b/crates/egui/src/containers/resize.rs @@ -337,10 +337,16 @@ pub fn paint_resize_corner(ui: &Ui, response: &Response) { paint_resize_corner_with_style(ui, &response.rect, stroke, Align2::RIGHT_BOTTOM); } -pub fn paint_resize_corner_with_style(ui: &Ui, rect: &Rect, stroke: Stroke, corner: Align2) { +pub fn paint_resize_corner_with_style( + ui: &Ui, + rect: &Rect, + stroke: impl Into, + corner: Align2, +) { let painter = ui.painter(); let cp = painter.round_pos_to_pixels(corner.pos_in_rect(rect)); let mut w = 2.0; + let stroke = stroke.into(); while w <= rect.width() && w <= rect.height() { painter.line_segment( diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index afc9f48d..af72ff98 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -476,7 +476,12 @@ impl<'open> Window<'open> { } } -fn paint_resize_corner(ui: &Ui, possible: &PossibleInteractions, outer_rect: Rect, stroke: Stroke) { +fn paint_resize_corner( + ui: &Ui, + possible: &PossibleInteractions, + outer_rect: Rect, + stroke: impl Into, +) { let corner = if possible.resize_right && possible.resize_bottom { Align2::RIGHT_BOTTOM } else if possible.resize_left && possible.resize_bottom { diff --git a/crates/egui/src/painter.rs b/crates/egui/src/painter.rs index 388a1ced..a8886232 100644 --- a/crates/egui/src/painter.rs +++ b/crates/egui/src/painter.rs @@ -333,12 +333,13 @@ impl Painter { } /// Show an arrow starting at `origin` and going in the direction of `vec`, with the length `vec.length()`. - pub fn arrow(&self, origin: Pos2, vec: Vec2, stroke: Stroke) { + pub fn arrow(&self, origin: Pos2, vec: Vec2, stroke: impl Into) { use crate::emath::*; let rot = Rot2::from_angle(std::f32::consts::TAU / 10.0); let tip_length = vec.length() / 4.0; let tip = origin + vec; let dir = vec.normalized(); + let stroke = stroke.into(); self.line_segment([origin, tip], stroke); self.line_segment([tip, tip - tip_length * (rot * dir)], stroke); self.line_segment([tip, tip - tip_length * (rot.inverse() * dir)], stroke); diff --git a/crates/emath/src/vec2.rs b/crates/emath/src/vec2.rs index 0e0a9373..d4a2c330 100644 --- a/crates/emath/src/vec2.rs +++ b/crates/emath/src/vec2.rs @@ -1,4 +1,4 @@ -use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; +use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; /// A vector has a direction and length. /// A [`Vec2`] is often used to represent a size. @@ -203,7 +203,8 @@ impl Vec2 { /// ``` #[inline(always)] pub fn angled(angle: f32) -> Self { - vec2(angle.cos(), angle.sin()) + let (sin, cos) = angle.sin_cos(); + vec2(cos, sin) } #[must_use] @@ -407,6 +408,14 @@ impl MulAssign for Vec2 { } } +impl DivAssign for Vec2 { + #[inline(always)] + fn div_assign(&mut self, rhs: f32) { + self.x /= rhs; + self.y /= rhs; + } +} + impl Mul for Vec2 { type Output = Vec2; @@ -470,4 +479,20 @@ fn test_vec2() { assert_eq!(Vec2::DOWN.angle(), 0.25 * TAU); almost_eq!(Vec2::LEFT.angle(), 0.50 * TAU); assert_eq!(Vec2::UP.angle(), -0.25 * TAU); + + let mut assignment = vec2(1.0, 2.0); + assignment += vec2(3.0, 4.0); + assert_eq!(assignment, vec2(4.0, 6.0)); + + let mut assignment = vec2(4.0, 6.0); + assignment -= vec2(1.0, 2.0); + assert_eq!(assignment, vec2(3.0, 4.0)); + + let mut assignment = vec2(1.0, 2.0); + assignment *= 2.0; + assert_eq!(assignment, vec2(2.0, 4.0)); + + let mut assignment = vec2(2.0, 4.0); + assignment /= 2.0; + assert_eq!(assignment, vec2(1.0, 2.0)); } diff --git a/crates/epaint/src/mutex.rs b/crates/epaint/src/mutex.rs index 73b54ca8..2c61f038 100644 --- a/crates/epaint/src/mutex.rs +++ b/crates/epaint/src/mutex.rs @@ -387,14 +387,6 @@ mod tests { let _b = two.lock(); } - #[test] - #[should_panic] - fn lock_reentry_single_thread() { - let one = Mutex::new(()); - let _a = one.lock(); - let _a2 = one.lock(); // panics - } - #[test] fn lock_multiple_threads() { use std::sync::Arc;