Skip to content

Commit 3c4ef0d

Browse files
authored
feat: support v-text color props (#17)
1 parent 59a445d commit 3c4ef0d

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

soft-skia-wasm/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ pub struct WASMTextAttr {
9999
text: String,
100100
x: i32,
101101
y: i32,
102-
font_size: f32,
102+
font_size: Option<f32>,
103+
color: Option<String>
103104
}
104105

105106

@@ -293,8 +294,11 @@ impl SoftSkiaWASM {
293294
y,
294295
text,
295296
font_size,
297+
color
296298
}) => {
297-
self.0.set_shape_to_child(id, Shapes::T(Text { text, x, y, font_size}))
299+
let color = parse_color(color);
300+
let font_size = font_size.unwrap_or(16.0);
301+
self.0.set_shape_to_child(id, Shapes::T(Text { text, x, y, font_size, color }))
298302
}
299303
};
300304
}

soft-skia/src/shape.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub struct Text {
117117
pub x: i32,
118118
pub y: i32,
119119
pub font_size: f32,
120+
pub color: Option<ColorU8>,
120121
}
121122

122123
impl Shapes {
@@ -570,7 +571,11 @@ impl Shape for Text {
570571
}
571572
let mut rgba_bitmap:Vec<u8> = vec![];
572573
for i in 0..bitmap.len() {
573-
rgba_bitmap.extend([0, 0, 0, bitmap[i]].iter());
574+
if let Some(color) = self.color {
575+
rgba_bitmap.extend([color.red(), color.green(), color.blue(), bitmap[i]].iter());
576+
} else {
577+
rgba_bitmap.extend([0, 0, 0, bitmap[i]].iter());
578+
}
574579
}
575580

576581
let p = Pixmap::from_vec(rgba_bitmap, tiny_skia::IntSize::from_wh(dim.0 as u32, dim.1 as u32).unwrap()).unwrap();

vue-playground/src/code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default `<v-surface :width="360" :height="360">
2828
</template>
2929
<v-circle :cx="0" :cy="60" :r="50" :style="'fill'" />
3030
<v-circle :cx="0" :cy="60" :r="70" />
31-
<v-text :x="70" :y="0" :fontSize="100" text="Hello"></v-text>
31+
<v-text :x="70" :y="0" :fontSize="16" color="red" text="Hello"></v-text>
3232
</v-group>
3333
</v-surface>
3434
`;

vue-skia-framework/components/VText.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<v-sk-text :text="text" :x="x" :y="y" :fontSize="fontSize" />
2+
<v-sk-text :text="text" :x="x" :y="y" :fontSize="fontSize" :color="color" />
33
</template>
44

55
<script lang="ts">
@@ -22,8 +22,12 @@ export default defineComponent({
2222
},
2323
fontSize: {
2424
type: Number as PropType<number>,
25-
required: true,
25+
required: false
2626
},
27-
},
27+
color: {
28+
type: String as PropType<string>,
29+
required: false
30+
}
31+
}
2832
});
2933
</script>

vue-skia-framework/plugin/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,14 @@ const VSKNode = (name: string) => {
175175
});
176176
}
177177
if (name === "Text") {
178-
console.log(attrs.text, attrs.fontSize);
179-
180178
core.setAttrBySerde(instance._ssw_id, {
181179
attr: {
182180
T: {
183181
text: attrs.text,
184182
x: attrs.x,
185183
y: attrs.y,
186184
font_size: attrs.fontSize,
185+
color: attrs.color,
187186
},
188187
},
189188
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy