Rename current Path to path::Builder
This commit is contained in:
parent
64097983f1
commit
74dd79e97f
3 changed files with 50 additions and 28 deletions
|
|
@ -86,17 +86,17 @@ impl canvas::layer::Drawable for LocalTime {
|
||||||
let center = frame.center();
|
let center = frame.center();
|
||||||
let radius = frame.width().min(frame.height()) as f32 / 2.0;
|
let radius = frame.width().min(frame.height()) as f32 / 2.0;
|
||||||
|
|
||||||
let mut path = canvas::Path::new();
|
let path = canvas::Path::new(|path| {
|
||||||
|
path.arc(canvas::path::Arc {
|
||||||
path.arc(canvas::path::Arc {
|
center,
|
||||||
center,
|
radius,
|
||||||
radius,
|
start_angle: 0.0,
|
||||||
start_angle: 0.0,
|
end_angle: 360.0 * 2.0 * std::f32::consts::PI,
|
||||||
end_angle: 360.0 * 2.0 * std::f32::consts::PI,
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
frame.fill(
|
frame.fill(
|
||||||
path,
|
&path,
|
||||||
canvas::Fill::Color(Color::from_rgb8(0x12, 0x93, 0xD8)),
|
canvas::Fill::Color(Color::from_rgb8(0x12, 0x93, 0xD8)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -104,7 +104,7 @@ impl canvas::layer::Drawable for LocalTime {
|
||||||
n: u32,
|
n: u32,
|
||||||
total: u32,
|
total: u32,
|
||||||
length: f32,
|
length: f32,
|
||||||
path: &mut canvas::Path,
|
path: &mut canvas::path::Builder,
|
||||||
) {
|
) {
|
||||||
let turns = n as f32 / total as f32;
|
let turns = n as f32 / total as f32;
|
||||||
let t = 2.0 * std::f32::consts::PI * (turns - 0.25);
|
let t = 2.0 * std::f32::consts::PI * (turns - 0.25);
|
||||||
|
|
@ -115,16 +115,16 @@ impl canvas::layer::Drawable for LocalTime {
|
||||||
path.line_to(Point::new(x, y));
|
path.line_to(Point::new(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut path = canvas::Path::new();
|
let path = canvas::Path::new(|path| {
|
||||||
|
path.move_to(center);
|
||||||
|
draw_handle(self.hour, 12, 0.6 * radius, path);
|
||||||
|
|
||||||
path.move_to(center);
|
path.move_to(center);
|
||||||
draw_handle(self.hour, 12, 0.6 * radius, &mut path);
|
draw_handle(self.minute, 60, 0.9 * radius, path)
|
||||||
|
});
|
||||||
path.move_to(center);
|
|
||||||
draw_handle(self.minute, 60, 0.9 * radius, &mut path);
|
|
||||||
|
|
||||||
frame.stroke(
|
frame.stroke(
|
||||||
path,
|
&path,
|
||||||
canvas::Stroke {
|
canvas::Stroke {
|
||||||
width: 4.0,
|
width: 4.0,
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
|
|
@ -133,13 +133,13 @@ impl canvas::layer::Drawable for LocalTime {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut path = canvas::Path::new();
|
let path = canvas::Path::new(|path| {
|
||||||
|
path.move_to(center);
|
||||||
path.move_to(center);
|
draw_handle(self.second, 60, 0.9 * radius, path)
|
||||||
draw_handle(self.second, 60, 0.9 * radius, &mut path);
|
});
|
||||||
|
|
||||||
frame.stroke(
|
frame.stroke(
|
||||||
path,
|
&path,
|
||||||
canvas::Stroke {
|
canvas::Stroke {
|
||||||
width: 2.0,
|
width: 2.0,
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ impl Frame {
|
||||||
Point::new(self.width as f32 / 2.0, self.height as f32 / 2.0)
|
Point::new(self.width as f32 / 2.0, self.height as f32 / 2.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fill(&mut self, path: Path, fill: Fill) {}
|
pub fn fill(&mut self, path: &Path, fill: Fill) {}
|
||||||
|
|
||||||
pub fn stroke(&mut self, path: Path, stroke: Stroke) {}
|
pub fn stroke(&mut self, path: &Path, stroke: Stroke) {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,28 @@
|
||||||
use iced_native::{Point, Vector};
|
use iced_native::{Point, Vector};
|
||||||
|
|
||||||
#[allow(missing_debug_implementations)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Path {
|
pub struct Path {
|
||||||
raw: lyon::path::Builder,
|
raw: lyon::path::Path,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Path {
|
impl Path {
|
||||||
pub fn new() -> Path {
|
pub fn new(f: impl FnOnce(&mut Builder)) -> Self {
|
||||||
Path {
|
let mut builder = Builder::new();
|
||||||
|
|
||||||
|
f(&mut builder);
|
||||||
|
|
||||||
|
builder.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(missing_debug_implementations)]
|
||||||
|
pub struct Builder {
|
||||||
|
raw: lyon::path::Builder,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Builder {
|
||||||
|
pub fn new() -> Builder {
|
||||||
|
Builder {
|
||||||
raw: lyon::path::Path::builder(),
|
raw: lyon::path::Path::builder(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +39,7 @@ impl Path {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn arc(&mut self, arc: Arc) {
|
pub fn arc(&mut self, arc: Arc) {
|
||||||
self.ellipse(arc.into())
|
self.ellipse(arc.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -46,6 +61,13 @@ impl Path {
|
||||||
pub fn close(&mut self) {
|
pub fn close(&mut self) {
|
||||||
self.raw.close()
|
self.raw.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn build(self) -> Path {
|
||||||
|
Path {
|
||||||
|
raw: self.raw.build(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue