tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91822 Sutichaykuna

fixed swift bindings (#4)

e5287c093b82c1a0ad9723fb0e4f8a8266a423e0 · ruwaq Didier Prophete · (4 wata ñawpaq) · tayta 60c086010 · kay commitpi sach'ata qhaway

Semántico sayk'uy · 24

bindings/swift/StretchCore/src/lib.rs

bindings/swift/StretchKit/Headers/libstretch.h

4 qillqakuna · +58 −57

diff --git a/bindings/swift/StretchCore/Cargo.toml b/bindings/swift/StretchCore/Cargo.toml
index 869e1ba01..9de626e44 100644
--- a/bindings/swift/StretchCore/Cargo.toml
+++ b/bindings/swift/StretchCore/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["Emil Sjölander <emil@visly.app>"]
 edition = "2018"
 
 [dependencies]
-stretch = { version = "0.3.2", path = "../../.." }
+stretch2 = { version = "0.4.2", path = "../../.." }
 
 [lib]
 name = "stretch"
diff --git a/bindings/swift/StretchCore/src/lib.rs b/bindings/swift/StretchCore/src/lib.rs
index 9e8f42ea0..4e48f5276 100644
--- a/bindings/swift/StretchCore/src/lib.rs
+++ b/bindings/swift/StretchCore/src/lib.rs
@@ -247,7 +247,7 @@ pub unsafe extern "C" fn stretch_node_set_measure(
             *node,
             Some(stretch2::node::MeasureFunc::Boxed(Box::new(move |constraint| {
                 let size = measure(swift_ptr, constraint.width.or_else(f32::NAN), constraint.height.or_else(f32::NAN));
-                size
+                stretch2::geometry::Size { height: size.height, width: size.width }
             }))),
         )
         .unwrap();
diff --git a/bindings/swift/StretchKit/Headers/libstretch.h b/bindings/swift/StretchKit/Headers/libstretch.h
index 4a9758898..cbef93374 100644
--- a/bindings/swift/StretchKit/Headers/libstretch.h
+++ b/bindings/swift/StretchKit/Headers/libstretch.h
@@ -1,61 +1,29 @@
+#include <stdarg.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <stdbool.h>
 
-typedef struct {
-  float width;
-  float height;
-} StretchSize;
-
-typedef struct {
+typedef struct StretchStyleDimension {
   int32_t dimen_type;
   float dimen_value;
 } StretchStyleDimension;
 
-typedef struct {
-  StretchStyleDimension start;
-  StretchStyleDimension end;
-  StretchStyleDimension top;
-  StretchStyleDimension bottom;
+typedef struct StretchStyleRect {
+  struct StretchStyleDimension start;
+  struct StretchStyleDimension end;
+  struct StretchStyleDimension top;
+  struct StretchStyleDimension bottom;
 } StretchStyleRect;
 
-typedef struct {
-  StretchStyleDimension width;
-  StretchStyleDimension height;
+typedef struct StretchStyleSize {
+  struct StretchStyleDimension width;
+  struct StretchStyleDimension height;
 } StretchStyleSize;
 
-void stretch_free(void *stretch);
-
-void *stretch_init(void);
-
-void stretch_node_add_child(void *stretch, void *node, void *child);
-
-void *stretch_node_compute_layout(void *stretch,
-                                  void *node,
-                                  float width,
-                                  float height,
-                                  void *(*create_layout)(const float*));
-
-void *stretch_node_create(void *stretch, void *style);
-
-bool stretch_node_dirty(void *stretch, void *node);
-
-void stretch_node_free(void *stretch, void *node);
-
-void stretch_node_mark_dirty(void *stretch, void *node);
-
-void stretch_node_remove_child(void *stretch, void *node, void *child);
-
-void stretch_node_remove_child_at_index(void *stretch, void *node, uintptr_t index);
-
-void stretch_node_replace_child_at_index(void *stretch, void *node, uintptr_t index, void *child);
-
-void stretch_node_set_measure(void *stretch,
-                              void *node,
-                              void *swift_ptr,
-                              StretchSize (*measure)(const void*, float, float));
-
-void stretch_node_set_style(void *stretch, void *node, void *style);
+typedef struct StretchSize {
+  float width;
+  float height;
+} StretchSize;
 
 void *stretch_style_create(int32_t display,
                            int32_t position_type,
@@ -67,16 +35,49 @@ void *stretch_style_create(int32_t display,
                            int32_t align_self,
                            int32_t align_content,
                            int32_t justify_content,
-                           StretchStyleRect position,
-                           StretchStyleRect margin,
-                           StretchStyleRect padding,
-                           StretchStyleRect border,
+                           struct StretchStyleRect position,
+                           struct StretchStyleRect margin,
+                           struct StretchStyleRect padding,
+                           struct StretchStyleRect border,
                            float flex_grow,
                            float flex_shrink,
-                           StretchStyleDimension flex_basis,
-                           StretchStyleSize size,
-                           StretchStyleSize min_size,
-                           StretchStyleSize max_size,
+                           struct StretchStyleDimension flex_basis,
+                           struct StretchStyleSize size,
+                           struct StretchStyleSize min_size,
+                           struct StretchStyleSize max_size,
                            float aspect_ratio);
 
 void stretch_style_free(void *style);
+
+void *stretch_init(void);
+
+void stretch_free(void *stretch);
+
+void *stretch_node_create(void *stretch, void *style);
+
+void stretch_node_free(void *stretch, void *node);
+
+void stretch_node_set_measure(void *stretch,
+                              void *node,
+                              void *swift_ptr,
+                              struct StretchSize (*measure)(const void*, float, float));
+
+void stretch_node_set_style(void *stretch, void *node, void *style);
+
+bool stretch_node_dirty(void *stretch, void *node);
+
+void stretch_node_mark_dirty(void *stretch, void *node);
+
+void stretch_node_add_child(void *stretch, void *node, void *child);
+
+void stretch_node_replace_child_at_index(void *stretch, void *node, uintptr_t index, void *child);
+
+void stretch_node_remove_child(void *stretch, void *node, void *child);
+
+void stretch_node_remove_child_at_index(void *stretch, void *node, uintptr_t index);
+
+void *stretch_node_compute_layout(void *stretch,
+                                  void *node,
+                                  float width,
+                                  float height,
+                                  void *(*create_layout)(const float*));
diff --git a/bindings/swift/StretchKit/Libraries/libstretch.a b/bindings/swift/StretchKit/Libraries/libstretch.a
index db8bee31e..acbf40f1b 100644
Binary files a/bindings/swift/StretchKit/Libraries/libstretch.a and b/bindings/swift/StretchKit/Libraries/libstretch.a differ