gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1076HTML 1008Markdown 12TOML 83208 Definitions

⎇ 7764f7d92b43ed65d8c8667c20e2a047174b2375 bindings/swift/StretchKit/Classes/Layout.swift 44 lines · 1.2 KB History raw

Basic working version of bindings 7764f7d92 · Emil Sjölander ·

1import Foundation
2
3public class Layout {
4    public let x: Float
5    public let y: Float
6    public let width: Float
7    public let height: Float
8    public let children: Array<Layout>
9    
10    internal init(x: Float, y: Float, width: Float, height: Float, children: Array<Layout>) {
11        self.x = x
12        self.y = y
13        self.width = width
14        self.height = height
15        self.children = children
16    }
17    
18    internal static func fromFloats(_ floats: UnsafePointer<Float>) -> (UnsafePointer<Float>, Layout) {
19        let x = floats.pointee;
20        var floats = floats.advanced(by: 1)
21        
22        let y = floats.pointee
23        floats = floats.advanced(by: 1)
24        
25        let width = floats.pointee
26        floats = floats.advanced(by: 1)
27        
28        let height = floats.pointee
29        floats = floats.advanced(by: 1)
30        
31        let childCount = Int(floats.pointee)
32        floats = floats.advanced(by: 1)
33        
34        var children = [Layout]()
35        
36        for _ in 0..<childCount {
37            let child = Layout.fromFloats(floats)
38            floats = child.0
39            children.append(child.1)
40        }
41        
42        return (floats, Layout(x: x, y: y, width: width, height: height, children: children))
43    }
44}