pub struct CubicBezier {
pub p0: (f32, f32),
pub p1: (f32, f32),
pub p2: (f32, f32),
pub p3: (f32, f32),
}Expand description
The cubic bezier a link is drawn as.
Horizontal-biased: each control point shares its endpoint’s y and is
offset along x, which is what makes a link leave a pin sideways. These
four points are the single description of the curve — the drawn commands,
the bounding box and the hit test all read them, so a click lands on the
stroke the eye sees.
Fields§
§p0: (f32, f32)§p1: (f32, f32)§p2: (f32, f32)§p3: (f32, f32)Implementations§
Source§impl CubicBezier
impl CubicBezier
Sourcepub fn from_endpoints(
start_x: f32,
start_y: f32,
end_x: f32,
end_y: f32,
zoom: f32,
min_offset: f32,
) -> Self
pub fn from_endpoints( start_x: f32, start_y: f32, end_x: f32, end_y: f32, zoom: f32, min_offset: f32, ) -> Self
Build the curve between two pin centres.
§Arguments
start_x,start_y- Start point (pin center)end_x,end_y- End point (pin center)zoom- Current zoom level (scales the threshold and the offset)min_offset- Minimum control point offset (typically 50.0)
Sourcepub fn is_straight(&self) -> bool
pub fn is_straight(&self) -> bool
Whether the curve collapsed to the straight-line fallback.
Sourcepub fn commands_from(&self, origin: (f32, f32)) -> String
pub fn commands_from(&self, origin: (f32, f32)) -> String
SVG path commands for the curve, with coordinates relative to origin.
Pass (0.0, 0.0) for absolute coordinates; pass the origin of
bounds to get commands that fit inside that box.
Sourcepub fn bounds(&self) -> (f32, f32, f32, f32)
pub fn bounds(&self) -> (f32, f32, f32, f32)
The axis-aligned box containing the curve, as (x, y, width, height).
A cubic lies within the convex hull of its control points, so the extremes of the four bound it without subdividing. This is the centreline’s box: a stroke spills half its width past it in every direction, and whoever knows the stroke width pads for that.
Sourcepub fn to_link_path<T>(
&self,
make: impl FnOnce(String, f32, f32, f32, f32) -> T,
) -> T
pub fn to_link_path<T>( &self, make: impl FnOnce(String, f32, f32, f32, f32) -> T, ) -> T
Build a LinkPath from the curve: box-relative commands plus the box.
Takes the constructor rather than naming the type, because which
LinkPath a consumer has depends on how they compile the .slint — the
crate’s re-export when the library module comes in through cargo
metadata, their own generated copy when they pass a library path.
Sourcepub fn split_at(&self, t: f32) -> CubicBezier
pub fn split_at(&self, t: f32) -> CubicBezier
The sub-curve from t=0 to t=t, by de Casteljau subdivision.