mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Use impl Into<Stroke> as argument in a few more places (#3420)
* Functions that take Stroke were updated to take Into<Stroke> to make them consistent with other Into<Stroke> parameters. * Vec2 implements DivAssign<f32>, to make it consistent with already implementing MulAssign<f32> and Div<f32>. * Vec2::angled() uses sin_cos() rather than an individual sin() and cos() call for an immeasurable but hypothetical performance improvement. * Disable the lock_reentry_single_thread() mutex test. Lock()ing twice on the same thread is not guaranteed to panic. * Closes <https://github.com/emilk/egui/issues/3419>.
This commit is contained in:
@@ -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<Stroke>) -> Self {
|
||||
self.stroke = stroke.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Stroke>,
|
||||
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(
|
||||
|
||||
@@ -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<Stroke>,
|
||||
) {
|
||||
let corner = if possible.resize_right && possible.resize_bottom {
|
||||
Align2::RIGHT_BOTTOM
|
||||
} else if possible.resize_left && possible.resize_bottom {
|
||||
|
||||
@@ -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<Stroke>) {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user