pub struct Canvas { /* private fields */ }Expand description
像素级自由画布(内部 tiny_skia::Pixmap,逻辑坐标 × scale)。
Implementations§
Source§impl Canvas
impl Canvas
Sourcepub fn rect(
&mut self,
x: f32,
y: f32,
w: f32,
h: f32,
radius: f32,
color: Color,
)
pub fn rect( &mut self, x: f32, y: f32, w: f32, h: f32, radius: f32, color: Color, )
实心(可圆角)矩形。
Sourcepub fn stroke_rect(
&mut self,
x: f32,
y: f32,
w: f32,
h: f32,
radius: f32,
line_w: f32,
color: Color,
)
pub fn stroke_rect( &mut self, x: f32, y: f32, w: f32, h: f32, radius: f32, line_w: f32, color: Color, )
描边(可圆角)矩形。线宽沿路径居中。
Sourcepub fn v_gradient(
&mut self,
x: f32,
y: f32,
w: f32,
h: f32,
radius: f32,
top: Color,
bottom: Color,
)
pub fn v_gradient( &mut self, x: f32, y: f32, w: f32, h: f32, radius: f32, top: Color, bottom: Color, )
竖直线性渐变的(可圆角)矩形:顶 top → 底 bottom。
Sourcepub fn line(
&mut self,
x0: f32,
y0: f32,
x1: f32,
y1: f32,
line_w: f32,
color: Color,
)
pub fn line( &mut self, x0: f32, y0: f32, x1: f32, y1: f32, line_w: f32, color: Color, )
直线段(圆头)。
Sourcepub fn arc(
&mut self,
cx: f32,
cy: f32,
r: f32,
start_deg: f32,
sweep_deg: f32,
line_w: f32,
color: Color,
)
pub fn arc( &mut self, cx: f32, cy: f32, r: f32, start_deg: f32, sweep_deg: f32, line_w: f32, color: Color, )
圆弧(圆头描边):从 start_deg 起、扫过 sweep_deg(度,0=右、顺时针为正)。用折线逼近,
适合做环形进度 / 仪表。
Sourcepub fn polygon(
&mut self,
pts: &[(f32, f32)],
fill: Option<Color>,
stroke: Option<(f32, Color)>,
)
pub fn polygon( &mut self, pts: &[(f32, f32)], fill: Option<Color>, stroke: Option<(f32, Color)>, )
多边形:pts 为逻辑坐标顶点;可填充、可描边(或都给)。
Sourcepub fn radar(&mut self, cx: f32, cy: f32, r: f32, values: &[f32], st: &Radar)
pub fn radar(&mut self, cx: f32, cy: f32, r: f32, values: &[f32], st: &Radar)
雷达图:以 (cx, cy) 为心、r 为外接半径,values(各轴 0..1)画数据多边形 + 网格。
Sourcepub fn text(
&mut self,
x: f32,
y: f32,
box_w: f32,
opts: &RenderOptions,
build: impl FnOnce(&mut ParaBuilder),
) -> Result<f32>
pub fn text( &mut self, x: f32, y: f32, box_w: f32, opts: &RenderOptions, build: impl FnOnce(&mut ParaBuilder), ) -> Result<f32>
把一段样式化段落渲成透明底小图并合成到 (x, y),占位宽 box_w(逻辑像素;段落对齐在此宽内生效)。
返回该文本盒的渲染高度(逻辑像素),便于纵向流式排版。复用整条版式管线(CJK 整形 / 抗锯齿白拿)。
Sourcepub fn text_doc(
&mut self,
x: f32,
y: f32,
box_w: f32,
opts: &RenderOptions,
doc: &Document,
) -> Result<f32>
pub fn text_doc( &mut self, x: f32, y: f32, box_w: f32, opts: &RenderOptions, doc: &Document, ) -> Result<f32>
Sourcepub fn text_mid(
&mut self,
x: f32,
cy: f32,
box_w: f32,
opts: &RenderOptions,
build: impl FnOnce(&mut ParaBuilder),
) -> Result<f32>
pub fn text_mid( &mut self, x: f32, cy: f32, box_w: f32, opts: &RenderOptions, build: impl FnOnce(&mut ParaBuilder), ) -> Result<f32>
同 text,但把文字的实际墨迹纵向居中于中线 cy(逻辑像素),x 仍是左缘。给
「标签 / 数值 / 进度条 / 圆牌同一行居中」的卡片行用——按行盒居中会偏高(行盒底部留白多),故取首末非透明
行的中点对齐 cy,文字与同心线上的形状才真正齐平,不同字号也一致。
返回墨迹右缘相对 x 的逻辑宽度(全透明返回 0):据此把下一段接着往右摆,且每段各自居中于同一 cy,
不会因不同字号共用基线而让小字下沉。
Auto Trait Implementations§
impl Freeze for Canvas
impl RefUnwindSafe for Canvas
impl Send for Canvas
impl Sync for Canvas
impl Unpin for Canvas
impl UnsafeUnpin for Canvas
impl UnwindSafe for Canvas
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more