Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 67 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rustmotion-components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lottie-native = ["dep:thorvg", "dep:dashmap"]

[dependencies]
rustmotion-core.workspace = true
skia-safe = "0.82"
skia-safe = "0.99"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
schemars = "0.8"
Expand Down
10 changes: 5 additions & 5 deletions crates/rustmotion-components/src/arrow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use skia_safe::{Canvas, PaintStyle, Path, PathMeasure, Point};
use skia_safe::{Canvas, PaintStyle, Path, PathBuilder, PathMeasure, Point};

use rustmotion_core::css::CssStyle;
use rustmotion_core::engine::animator::AnimatedProperties;
Expand Down Expand Up @@ -87,7 +87,7 @@ rustmotion_core::impl_traits!(Arrow {
impl Arrow {
/// Build the bezier path for this arrow (without arrowheads).
fn build_path(&self) -> Path {
let mut path = Path::new();
let mut path = PathBuilder::new();
path.move_to((self.x1, self.y1));

if let (Some(cp1), Some(cp2)) = (&self.cp1, &self.cp2) {
Expand All @@ -112,7 +112,7 @@ impl Arrow {
path.line_to((self.x2, self.y2));
}

path
path.detach()
}

/// Draw an arrowhead at the given position along the path.
Expand Down Expand Up @@ -146,7 +146,7 @@ impl Arrow {
let angle = tangent.y.atan2(tangent.x);
let half_angle = std::f32::consts::PI / 6.0; // 30 degrees

let mut arrow_path = Path::new();
let mut arrow_path = PathBuilder::new();
arrow_path.move_to(pos);
arrow_path.line_to((
pos.x - size * (angle - half_angle).cos(),
Expand All @@ -161,7 +161,7 @@ impl Arrow {
let mut arrow_paint = paint.clone();
arrow_paint.set_path_effect(None);
arrow_paint.set_stroke_cap(skia_safe::PaintCap::Round);
canvas.draw_path(&arrow_path, &arrow_paint);
canvas.draw_path(&arrow_path.detach(), &arrow_paint);
}

fn paint(&self, canvas: &Canvas, props: &AnimatedProperties) {
Expand Down
6 changes: 3 additions & 3 deletions crates/rustmotion-components/src/callout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustmotion_core::css::CssStyle;
use rustmotion_core::error::Result;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use skia_safe::{Canvas, PaintStyle, Path, RRect, Rect};
use skia_safe::{Canvas, PaintStyle, Path, PathBuilder, RRect, Rect};

use rustmotion_core::engine::animator::AnimatedProperties;
use rustmotion_core::engine::layout_pass::BoxLayout;
Expand Down Expand Up @@ -89,7 +89,7 @@ impl Callout {
}

fn arrow_path(&self, w: f32, h: f32) -> Path {
let mut path = Path::new();
let mut path = PathBuilder::new();
let a = self.arrow_size;
// Overlap the arrow base 1px into the bubble to eliminate anti-aliasing seam
let overlap = 1.0;
Expand Down Expand Up @@ -129,7 +129,7 @@ impl Callout {
}
}

path
path.detach()
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/rustmotion-components/src/chart/funnel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustmotion_core::error::Result;
use skia_safe::{Canvas, PaintStyle, Path};
use skia_safe::{Canvas, PaintStyle, PathBuilder};

use rustmotion_core::engine::renderer::{
draw_text_with_fallback, emoji_typeface, measure_text_with_fallback, paint_from_hex,
Expand Down Expand Up @@ -67,13 +67,13 @@ impl Chart {
paint.set_style(PaintStyle::Fill);
paint.set_anti_alias(true);

let mut path = Path::new();
let mut path = PathBuilder::new();
path.move_to((top_x, y_top));
path.line_to((top_x + top_w, y_top));
path.line_to((bot_x + bot_w, y_bot));
path.line_to((bot_x, y_bot));
path.close();
canvas.draw_path(&path, &paint);
canvas.draw_path(&path.detach(), &paint);

if self.show_labels {
if let Some(label) = &dp.label {
Expand Down Expand Up @@ -148,13 +148,13 @@ impl Chart {
paint.set_style(PaintStyle::Fill);
paint.set_anti_alias(true);

let mut path = Path::new();
let mut path = PathBuilder::new();
path.move_to((x_left, left_y));
path.line_to((x_right, right_y));
path.line_to((x_right, right_y + right_h));
path.line_to((x_left, left_y + left_h));
path.close();
canvas.draw_path(&path, &paint);
canvas.draw_path(&path.detach(), &paint);

if self.show_labels {
if let Some(label) = &dp.label {
Expand Down
29 changes: 15 additions & 14 deletions crates/rustmotion-components/src/chart/line.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustmotion_core::error::Result;
use skia_safe::{Canvas, Color, PaintStyle, Path, Point, Rect};
use skia_safe::gradient::{self, Colors, Gradient};
use skia_safe::{Canvas, Color, Color4f, PaintStyle, PathBuilder, Point, Rect};

use rustmotion_core::engine::renderer::{paint_from_hex, parse_hex_color};

Expand Down Expand Up @@ -67,8 +68,8 @@ impl Chart {
return Ok(());
}

let mut path = Path::new();
let mut fill_path = Path::new();
let mut path = PathBuilder::new();
let mut fill_path = PathBuilder::new();

for (i, dp) in self.data.iter().enumerate() {
let x = ml + (i as f32 / (n - 1) as f32) * chart_w;
Expand Down Expand Up @@ -102,14 +103,14 @@ impl Chart {
let mut fill_paint = paint_from_hex(line_color);
fill_paint.set_style(PaintStyle::Fill);
fill_paint.set_alpha_f(0.15);
canvas.draw_path(&fill_path, &fill_paint);
canvas.draw_path(&fill_path.detach(), &fill_paint);

// Line stroke
let mut line_paint = paint_from_hex(line_color);
line_paint.set_style(PaintStyle::Stroke);
line_paint.set_stroke_width(2.5);
line_paint.set_anti_alias(true);
canvas.draw_path(&path, &line_paint);
canvas.draw_path(&path.detach(), &line_paint);

// Dots
for (i, dp) in self.data.iter().enumerate() {
Expand Down Expand Up @@ -168,8 +169,8 @@ impl Chart {
})
.collect();

let mut line_path = Path::new();
let mut fill_path = Path::new();
let mut line_path = PathBuilder::new();
let mut fill_path = PathBuilder::new();

if self.smooth && pts.len() >= 3 {
// Catmull-Rom -> cubic bezier for smooth curves
Expand Down Expand Up @@ -227,12 +228,12 @@ impl Chart {
let top_color = Color::from_argb((self.fill_opacity * 255.0) as u8, r, g, b);
let bottom_color = Color::from_argb(0, r, g, b);

let shader = skia_safe::shader::Shader::linear_gradient(
let colors4f = [Color4f::from(top_color), Color4f::from(bottom_color)];
let stops = Colors::new(&colors4f, None, skia_safe::TileMode::Clamp, None);
let grad = Gradient::new(stops, gradient::Interpolation::default());
let shader = gradient::shaders::linear_gradient(
(Point::new(0.0, mt), Point::new(0.0, mt + chart_h)),
skia_safe::gradient_shader::GradientShaderColors::Colors(&[top_color, bottom_color]),
None,
skia_safe::TileMode::Clamp,
None,
&grad,
None,
);

Expand All @@ -241,15 +242,15 @@ impl Chart {
fill_paint.set_style(PaintStyle::Fill);
fill_paint.set_anti_alias(true);
fill_paint.set_shader(shader);
canvas.draw_path(&fill_path, &fill_paint);
canvas.draw_path(&fill_path.detach(), &fill_paint);
}

// Line stroke
let mut line_paint = paint_from_hex(line_color);
line_paint.set_style(PaintStyle::Stroke);
line_paint.set_stroke_width(2.5);
line_paint.set_anti_alias(true);
canvas.draw_path(&line_path, &line_paint);
canvas.draw_path(&line_path.detach(), &line_paint);

// Dots
for &(x, y) in &pts {
Expand Down
Loading
Loading