🎉 Suport for show-content in render wasm

This commit is contained in:
Alejandro Alonso 2024-12-09 15:19:14 +01:00
parent 0eedc036be
commit e1d9efea7f
5 changed files with 47 additions and 23 deletions

View file

@ -111,7 +111,15 @@ pub extern "C" fn set_shape_selrect(left: f32, top: f32, right: f32, bottom: f32
}
#[no_mangle]
pub extern "C" fn set_shape_rotation(rotation: f32) {
pub unsafe extern "C" fn set_shape_clip_content(clip_content: bool) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.clip_content = clip_content;
}
}
#[no_mangle]
pub unsafe extern "C" fn set_shape_rotation(rotation: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.rotation = rotation;

View file

@ -413,6 +413,13 @@ impl RenderState {
if !id.is_nil() {
self.render_single_shape(shape);
if shape.clip_content {
self.drawing_surface.canvas().clip_rect(
shape.selrect,
skia::ClipOp::Intersect,
true,
);
}
}
// draw all the children shapes

View file

@ -51,6 +51,7 @@ pub struct Shape {
pub selrect: math::Rect,
pub transform: Matrix,
pub rotation: f32,
pub clip_content: bool,
fills: Vec<Fill>,
pub blend_mode: BlendMode,
pub opacity: f32,
@ -66,6 +67,7 @@ impl Shape {
selrect: math::Rect::new_empty(),
transform: Matrix::identity(),
rotation: 0.,
clip_content: true,
fills: vec![],
blend_mode: BlendMode::default(),
opacity: 1.,