Warn about invalid paths in iced_tiny_skia instead of panicking
This commit is contained in:
parent
0b459c8e24
commit
04c0ba04bf
2 changed files with 14 additions and 7 deletions
|
|
@ -15,6 +15,7 @@ tiny-skia = "0.8"
|
||||||
bytemuck = "1"
|
bytemuck = "1"
|
||||||
rustc-hash = "1.1"
|
rustc-hash = "1.1"
|
||||||
kurbo = "0.9"
|
kurbo = "0.9"
|
||||||
|
log = "0.4"
|
||||||
|
|
||||||
[dependencies.iced_graphics]
|
[dependencies.iced_graphics]
|
||||||
version = "0.7"
|
version = "0.7"
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ impl Frame {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fill(&mut self, path: &Path, fill: impl Into<Fill>) {
|
pub fn fill(&mut self, path: &Path, fill: impl Into<Fill>) {
|
||||||
let path = convert_path(path);
|
let Some(path) = convert_path(path) else { return };
|
||||||
let fill = fill.into();
|
let fill = fill.into();
|
||||||
|
|
||||||
self.primitives.push(Primitive::Fill {
|
self.primitives.push(Primitive::Fill {
|
||||||
|
|
@ -56,7 +56,7 @@ impl Frame {
|
||||||
size: Size,
|
size: Size,
|
||||||
fill: impl Into<Fill>,
|
fill: impl Into<Fill>,
|
||||||
) {
|
) {
|
||||||
let path = convert_path(&Path::rectangle(top_left, size));
|
let Some(path) = convert_path(&Path::rectangle(top_left, size)) else { return };
|
||||||
let fill = fill.into();
|
let fill = fill.into();
|
||||||
|
|
||||||
self.primitives.push(Primitive::Fill {
|
self.primitives.push(Primitive::Fill {
|
||||||
|
|
@ -71,7 +71,8 @@ impl Frame {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>) {
|
pub fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>) {
|
||||||
let path = convert_path(path);
|
let Some(path) = convert_path(path) else { return };
|
||||||
|
|
||||||
let stroke = stroke.into();
|
let stroke = stroke.into();
|
||||||
let skia_stroke = into_stroke(&stroke);
|
let skia_stroke = into_stroke(&stroke);
|
||||||
|
|
||||||
|
|
@ -151,7 +152,7 @@ impl Frame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_path(path: &Path) -> tiny_skia::Path {
|
fn convert_path(path: &Path) -> Option<tiny_skia::Path> {
|
||||||
use iced_graphics::geometry::path::lyon_path;
|
use iced_graphics::geometry::path::lyon_path;
|
||||||
|
|
||||||
let mut builder = tiny_skia::PathBuilder::new();
|
let mut builder = tiny_skia::PathBuilder::new();
|
||||||
|
|
@ -205,9 +206,14 @@ fn convert_path(path: &Path) -> tiny_skia::Path {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder
|
let result = builder.finish();
|
||||||
.finish()
|
|
||||||
.expect("Convert lyon path to tiny_skia path")
|
#[cfg(debug_assertions)]
|
||||||
|
if result.is_none() {
|
||||||
|
log::warn!("Invalid path: {:?}", path.raw());
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_paint(style: Style) -> tiny_skia::Paint<'static> {
|
pub fn into_paint(style: Style) -> tiny_skia::Paint<'static> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue