Skip to content

Commit

Permalink
feat: support v-text color props (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
faga295 authored Sep 19, 2023
1 parent 59a445d commit 3c4ef0d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
8 changes: 6 additions & 2 deletions soft-skia-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ pub struct WASMTextAttr {
text: String,
x: i32,
y: i32,
font_size: f32,
font_size: Option<f32>,
color: Option<String>
}


Expand Down Expand Up @@ -293,8 +294,11 @@ impl SoftSkiaWASM {
y,
text,
font_size,
color
}) => {
self.0.set_shape_to_child(id, Shapes::T(Text { text, x, y, font_size}))
let color = parse_color(color);
let font_size = font_size.unwrap_or(16.0);
self.0.set_shape_to_child(id, Shapes::T(Text { text, x, y, font_size, color }))
}
};
}
Expand Down
7 changes: 6 additions & 1 deletion soft-skia/src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub struct Text {
pub x: i32,
pub y: i32,
pub font_size: f32,
pub color: Option<ColorU8>,
}

impl Shapes {
Expand Down Expand Up @@ -570,7 +571,11 @@ impl Shape for Text {
}
let mut rgba_bitmap:Vec<u8> = vec![];
for i in 0..bitmap.len() {
rgba_bitmap.extend([0, 0, 0, bitmap[i]].iter());
if let Some(color) = self.color {
rgba_bitmap.extend([color.red(), color.green(), color.blue(), bitmap[i]].iter());
} else {
rgba_bitmap.extend([0, 0, 0, bitmap[i]].iter());
}
}

let p = Pixmap::from_vec(rgba_bitmap, tiny_skia::IntSize::from_wh(dim.0 as u32, dim.1 as u32).unwrap()).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion vue-playground/src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default `<v-surface :width="360" :height="360">
</template>
<v-circle :cx="0" :cy="60" :r="50" :style="'fill'" />
<v-circle :cx="0" :cy="60" :r="70" />
<v-text :x="70" :y="0" :fontSize="100" text="Hello"></v-text>
<v-text :x="70" :y="0" :fontSize="16" color="red" text="Hello"></v-text>
</v-group>
</v-surface>
`;
10 changes: 7 additions & 3 deletions vue-skia-framework/components/VText.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<v-sk-text :text="text" :x="x" :y="y" :fontSize="fontSize" />
<v-sk-text :text="text" :x="x" :y="y" :fontSize="fontSize" :color="color" />
</template>

<script lang="ts">
Expand All @@ -22,8 +22,12 @@ export default defineComponent({
},
fontSize: {
type: Number as PropType<number>,
required: true,
required: false
},
},
color: {
type: String as PropType<string>,
required: false
}
}
});
</script>
3 changes: 1 addition & 2 deletions vue-skia-framework/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,14 @@ const VSKNode = (name: string) => {
});
}
if (name === "Text") {
console.log(attrs.text, attrs.fontSize);

core.setAttrBySerde(instance._ssw_id, {
attr: {
T: {
text: attrs.text,
x: attrs.x,
y: attrs.y,
font_size: attrs.fontSize,
color: attrs.color,
},
},
});
Expand Down

0 comments on commit 3c4ef0d

Please sign in to comment.