Skip to content

Commit aca71d6

Browse files
committed
feat: add set_rect_attr in rust and use it in swift
1 parent 3b3ce55 commit aca71d6

File tree

11 files changed

+42
-14
lines changed

11 files changed

+42
-14
lines changed

SoftSkiaSwift/RustXcframework.xcframework/Info.plist

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@
1010
<key>HeadersPath</key>
1111
<string>Headers</string>
1212
<key>LibraryIdentifier</key>
13-
<string>ios-arm64</string>
13+
<string>macos-arm64_x86_64</string>
1414
<key>LibraryPath</key>
1515
<string>libsoft_skia_swift.a</string>
1616
<key>SupportedArchitectures</key>
1717
<array>
1818
<string>arm64</string>
19+
<string>x86_64</string>
1920
</array>
2021
<key>SupportedPlatform</key>
21-
<string>ios</string>
22+
<string>macos</string>
2223
</dict>
2324
<dict>
2425
<key>BinaryPath</key>
2526
<string>libsoft_skia_swift.a</string>
2627
<key>HeadersPath</key>
2728
<string>Headers</string>
2829
<key>LibraryIdentifier</key>
29-
<string>macos-arm64_x86_64</string>
30+
<string>ios-arm64_x86_64-simulator</string>
3031
<key>LibraryPath</key>
3132
<string>libsoft_skia_swift.a</string>
3233
<key>SupportedArchitectures</key>
@@ -35,26 +36,25 @@
3536
<string>x86_64</string>
3637
</array>
3738
<key>SupportedPlatform</key>
38-
<string>macos</string>
39+
<string>ios</string>
40+
<key>SupportedPlatformVariant</key>
41+
<string>simulator</string>
3942
</dict>
4043
<dict>
4144
<key>BinaryPath</key>
4245
<string>libsoft_skia_swift.a</string>
4346
<key>HeadersPath</key>
4447
<string>Headers</string>
4548
<key>LibraryIdentifier</key>
46-
<string>ios-arm64_x86_64-simulator</string>
49+
<string>ios-arm64</string>
4750
<key>LibraryPath</key>
4851
<string>libsoft_skia_swift.a</string>
4952
<key>SupportedArchitectures</key>
5053
<array>
5154
<string>arm64</string>
52-
<string>x86_64</string>
5355
</array>
5456
<key>SupportedPlatform</key>
5557
<string>ios</string>
56-
<key>SupportedPlatformVariant</key>
57-
<string>simulator</string>
5858
</dict>
5959
</array>
6060
<key>CFBundlePackageType</key>

SoftSkiaSwift/RustXcframework.xcframework/ios-arm64/Headers/soft-skia-swift.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void* __swift_bridge__$Vec_SoftSkia$as_ptr(void* vec_ptr);
1515
void* __swift_bridge__$SoftSkia$new(void);
1616
void __swift_bridge__$SoftSkia$create(void* self, uintptr_t id);
1717
void __swift_bridge__$SoftSkia$set_attr(void* self, uintptr_t id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t r, uint32_t g, uint32_t b, void* shape, void* color, void* style);
18+
void __swift_bridge__$SoftSkia$set_rect_attr(void* self, uintptr_t id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, void* style, void* color);
1819
void* __swift_bridge__$SoftSkia$to_base64(void* self);
1920
void* __swift_bridge__$hello_rust(void);
2021
void* __swift_bridge__$hello_soft_skia(void);

SoftSkiaSwift/RustXcframework.xcframework/ios-arm64_x86_64-simulator/Headers/soft-skia-swift.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void* __swift_bridge__$Vec_SoftSkia$as_ptr(void* vec_ptr);
1515
void* __swift_bridge__$SoftSkia$new(void);
1616
void __swift_bridge__$SoftSkia$create(void* self, uintptr_t id);
1717
void __swift_bridge__$SoftSkia$set_attr(void* self, uintptr_t id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t r, uint32_t g, uint32_t b, void* shape, void* color, void* style);
18+
void __swift_bridge__$SoftSkia$set_rect_attr(void* self, uintptr_t id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, void* style, void* color);
1819
void* __swift_bridge__$SoftSkia$to_base64(void* self);
1920
void* __swift_bridge__$hello_rust(void);
2021
void* __swift_bridge__$hello_soft_skia(void);

SoftSkiaSwift/RustXcframework.xcframework/macos-arm64_x86_64/Headers/soft-skia-swift.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void* __swift_bridge__$Vec_SoftSkia$as_ptr(void* vec_ptr);
1515
void* __swift_bridge__$SoftSkia$new(void);
1616
void __swift_bridge__$SoftSkia$create(void* self, uintptr_t id);
1717
void __swift_bridge__$SoftSkia$set_attr(void* self, uintptr_t id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t r, uint32_t g, uint32_t b, void* shape, void* color, void* style);
18+
void __swift_bridge__$SoftSkia$set_rect_attr(void* self, uintptr_t id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, void* style, void* color);
1819
void* __swift_bridge__$SoftSkia$to_base64(void* self);
1920
void* __swift_bridge__$hello_rust(void);
2021
void* __swift_bridge__$hello_soft_skia(void);

SoftSkiaSwift/Sources/SoftSkiaSwift/soft-skia-swift.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ extension SoftSkiaRefMut {
3838
__swift_bridge__$SoftSkia$set_attr(ptr, id, x, y, width, height, r, g, b, { let rustString = shape.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = color.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = style.intoRustString(); rustString.isOwned = false; return rustString.ptr }())
3939
}
4040

41+
public func set_rect_attr<GenericIntoRustString: IntoRustString>(_ id: UInt, _ x: UInt32, _ y: UInt32, _ width: UInt32, _ height: UInt32, _ style: GenericIntoRustString, _ color: GenericIntoRustString) {
42+
__swift_bridge__$SoftSkia$set_rect_attr(ptr, id, x, y, width, height, { let rustString = style.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = color.intoRustString(); rustString.isOwned = false; return rustString.ptr }())
43+
}
44+
4145
public func to_base64() -> RustString {
4246
RustString(ptr: __swift_bridge__$SoftSkia$to_base64(ptr))
4347
}

SwiftUISkia/Sources/SwiftUISkia/Rect.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ public struct Rect<Content: View>: View {
66
var y: UInt32
77
var width: UInt32
88
var height: UInt32
9-
var color: String
109
var style: String
10+
var color: String
1111
let content: Content
1212
@EnvironmentObject var ffi: FFI;
1313

14-
public init(x: UInt32, y: UInt32, width: UInt32, height: UInt32, color: String, style: String, @ViewBuilder builder: () -> Content) {
14+
public init(x: UInt32, y: UInt32, width: UInt32, height: UInt32, style: String, color: String, @ViewBuilder builder: () -> Content) {
1515
self.x = x
1616
self.y = y
1717
self.width = width
1818
self.height = height
19-
self.color = color
2019
self.style = style
20+
self.color = color
2121
self.content = builder()
2222
}
2323

@@ -27,7 +27,7 @@ public struct Rect<Content: View>: View {
2727
}.onAppear{
2828
let id = AutoIncrementID.id();
2929
self.ffi.soft.create(UInt(id))
30-
self.ffi.soft.set_attr(UInt(id), self.x, self.y, self.width, self.height, 0, 0, 0, "rect", self.color, self.style)
30+
self.ffi.soft.set_rect_attr(UInt(id), self.x, self.y, self.width, self.height, self.style, self.color)
3131
self.ffi.willChange();
3232
}
3333
}

examples/first-example/first-example/ContentView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import SwiftUISkia
1111
struct ContentView: View {
1212
var body: some View {
1313
SwiftUISkia.Surface(width: 400, height: 400) {
14-
SwiftUISkia.Rect(x: 10, y: 10, width: 100, height: 100, color: "#ff3333", style: "fill") {}
15-
SwiftUISkia.Rect(x: 210, y: 110, width: 100, height: 100, color: "cyan", style: "stroke") {}
14+
SwiftUISkia.Rect(x: 10, y: 10, width: 100, height: 100, style: "fill", color: "#ff3333") {}
15+
SwiftUISkia.Rect(x: 210, y: 110, width: 100, height: 100, style: "stroke", color: "cyan") {}
1616
}
1717
}
1818
}

generated/soft-skia-swift/soft-skia-swift.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void* __swift_bridge__$Vec_SoftSkia$as_ptr(void* vec_ptr);
1515
void* __swift_bridge__$SoftSkia$new(void);
1616
void __swift_bridge__$SoftSkia$create(void* self, uintptr_t id);
1717
void __swift_bridge__$SoftSkia$set_attr(void* self, uintptr_t id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t r, uint32_t g, uint32_t b, void* shape, void* color, void* style);
18+
void __swift_bridge__$SoftSkia$set_rect_attr(void* self, uintptr_t id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, void* style, void* color);
1819
void* __swift_bridge__$SoftSkia$to_base64(void* self);
1920
void* __swift_bridge__$hello_rust(void);
2021
void* __swift_bridge__$hello_soft_skia(void);

generated/soft-skia-swift/soft-skia-swift.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ extension SoftSkiaRefMut {
3737
__swift_bridge__$SoftSkia$set_attr(ptr, id, x, y, width, height, r, g, b, { let rustString = shape.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = color.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = style.intoRustString(); rustString.isOwned = false; return rustString.ptr }())
3838
}
3939

40+
public func set_rect_attr<GenericIntoRustString: IntoRustString>(_ id: UInt, _ x: UInt32, _ y: UInt32, _ width: UInt32, _ height: UInt32, _ style: GenericIntoRustString, _ color: GenericIntoRustString) {
41+
__swift_bridge__$SoftSkia$set_rect_attr(ptr, id, x, y, width, height, { let rustString = style.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = color.intoRustString(); rustString.isOwned = false; return rustString.ptr }())
42+
}
43+
4044
public func to_base64() -> RustString {
4145
RustString(ptr: __swift_bridge__$SoftSkia$to_base64(ptr))
4246
}

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ mod ffi {
2222
fn create(&mut self, id: usize) -> ();
2323
// fn add(parent_id: usize, child_id: usize) -> ();
2424
fn set_attr(&mut self, id: usize, x: u32, y: u32, width: u32, height: u32, r: u32, g: u32, b: u32, shape: String, color: String, style: String);
25+
26+
fn set_rect_attr(&mut self, id: usize, x: u32, y: u32, width: u32, height: u32, style: String, color: String);
27+
2528
fn to_base64(&mut self) -> String;
2629

2730
fn hello_rust() -> String;
@@ -89,6 +92,19 @@ impl SoftSkia {
8992
}
9093
}
9194

95+
pub fn set_rect_attr(&mut self, id: usize, x: u32, y: u32, width: u32, height: u32, style: String, color: String) {
96+
let color = parse_color(Some(color));
97+
let style = parse_style(Some(style));
98+
self.instance.set_shape_to_child(id, Shapes::R(Rect {
99+
x,
100+
y,
101+
width,
102+
height,
103+
color,
104+
style,
105+
}))
106+
}
107+
92108
pub fn to_base64(&mut self) -> String {
93109
to_base64(&mut self.instance.tree)
94110
}

0 commit comments

Comments
 (0)