gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1311HTML 640Markdown 11TOML 63653 Definiciones

⎇ b541e43e291182626270e360d2b99ca18babb54c README.md Markdown · 203 líneas · 7.3 KB Historia crudo

Update README.md b541e43e2 · 0xflotus ·

1# Stretch
2[![CircleCI](https://circleci.com/gh/vislyhq/stretch.svg?style=svg)](https://circleci.com/gh/vislyhq/stretch)
3[![Cargo](https://img.shields.io/crates/v/stretch.svg)](https://crates.io/crates/stretch)
4[![npm](https://img.shields.io/npm/v/stretch-layout.svg)](https://www.npmjs.com/package/stretch-layout)
5[![cocoapods](https://img.shields.io/cocoapods/v/StretchKit.svg)](https://cocoapods.org/pods/StretchKit)
6[![bintray](https://api.bintray.com/packages/visly/maven/stretch-kotlin-bindings/images/download.svg)](https://bintray.com/visly/maven/stretch-kotlin-bindings)
7
8Stretch is an implementation of Flexbox written in [Rust](https://www.rust-lang.org). The goal of stretch is to provide a solid foundation for layout across all platforms with a specific focus on mobile. Long term we want stretch to not only support flexbox but also many other layout algorithms such as grid layout. Stretch was made for and powers https://visly.app.
9
10## Goals
11Before using or contributing to stretch it is good to be aware of the core goals of the project. These are goals we are working towards, not necessarily features we currently support.
12
13- High performance
14- Cross platform
15- Small binary size
16- Support multiple layout systems
17- Multi-threaded layout
18- Language bindings for most common languages
19
20## Supported Platforms
21
22- Rust
23- Android
24- iOS
25- JavaScript / TypeScript
26
27## Usage
28Stretch is built in Rust but comes with bindings to multiple languages and platforms so you can use it in a way that feels natural to your project.
29
30### Rust
31```toml
32# Cargo.toml
33
34[dependencies]
35stretch = "0.2.2"
36```
37
38```rust
39// main.rs
40
41use stretch::style::*;
42use stretch::node::*;
43use stretch::result::*;
44
45fn main() {
46  let node = Node::new(
47      Style {
48          size: Size { width: Dimension::Points(100.0), height: Dimension::Points(100.0) },
49          justify_content: JustifyContent::Center,
50          ..Default::default()
51      },
52      vec![&Node::new(
53          Style { size: Size { width: Dimension::Percent(0.5), height: Dimension::Auto }, ..Default::default() },
54          vec![],
55      )],
56  );
57
58  let layout = node.compute_layout(Size::undefined()).unwrap();
59  dbg!(layout);
60}
61```
62
63### Android
64```groovy
65// Build.gradle
66
67android {
68    splits {
69        abi {
70            enable true
71        }
72    }
73}
74
75dependencies {
76    implementation 'app.visly.stretch:stretch:0.2.2'
77}
78```
79
80```kotlin
81// MainActivity.kt
82
83val node = Node(
84  Style(size = Size(Dimension.Points(100f), Dimension.Points(100f)), justifyContent = JustifyContent.Center), 
85  listOf(
86    Node(Style(size = Size(Dimension.Percent(0.5f), Dimension.Percent(0.5f))), listOf())
87  ))
88
89val layout = node.computeLayout(Size(null, null))
90Log.d(TAG, "width: ${layout.width}, height: ${layout.height}")
91```
92
93### iOS
94```ruby
95# Podfile
96
97pod 'StretchKit', '~> 0.2.2'
98```
99
100```swift
101// ViewController.swift
102 
103let node = Node(
104  style: Style(size: Size(width: .points(100.0), height: .points(100.0)), justifyContent: .center), 
105  children: [
106    Node(style: Style(size: Size(width: .percent(0.5), height: .percent(0.5))), children: [])
107  ])
108  
109let layout = node.computeLayout(thatFits: Size(width: nil, height: nil))
110print("width: \(layout.width), height: \(layout.height)")
111```
112
113### JavaScript
114```bash
115> npm install --save stretch-layout
116```
117
118```javascript
119// index.js
120
121import { Node, JustifyContent } from 'stretch-layout';
122
123const node = new Node({width: 100, height: 100, justifyContent: JustifyContent.Center});
124node.addChild(new Node({width: '50%', height: '50%'}));
125const layout = node.computeLayout();
126
127console.log(layout.width, layout.height);
128```
129
130## Contributing
131Contributions are very welcome. Though we ask that you open an issue or pull request early in the process (before writing code) so we can discuss solutions and additions before you start spending time on implementing them. There are some specific areas where we would be extra happy to receive contributions in.
132
133- Binary size reduction
134- Runtime performance
135- Ensure build / test environment works well on non macOS platforms
136- Alternate layout systems (grid layout perhaps?)
137- Web compatibility tests
138- RTL support
139- Platform bindings
140- API improvements
141- Documentation & Examples
142
143### Installation
144If you don't have Rust installed you have to do that first as well as install some components that we make use of to format and lint the codebase. For more on Rust see their [website](https://www.rust-lang.org).
145
146```bash
147curl https://sh.rustup.rs -sSf | sh
148rustup component add rustfmt
149rustup component add clippy
150```
151
152Once that is done you can clone the repo and do some sanity checks to make sure everything is working correctly.
153
154```bash
155git clone https://github.com/vislyhq/stretch.git
156cd stretch
157cargo test
158```
159
160If you have made any changes to the API you should also update and run tests for all the platform bindings located in `/bindings/*`.
161
162### Testing
163Stretch is tested by validating that layouts written in stretch perform the same as in Chrome. This is done by rendering an equivalent layout in HTML and then generating a Rust test case which asserts that the resulting layout is the same when run through stretch.
164
165You can run these tests without setting up a webdriver environment but if you are looking to add any test case you will need to install [chromedriver](http://chromedriver.chromium.org). If you are developing on macOS this is easy to do through brew.
166
167```bash
168brew tap homebrew/cask
169brew cask install chromedriver
170```
171
172Once you have chromedriver installed and available in `PATH` you can re-generate all tests by running `cargo run --package gentest`.
173
174To add a new test case add another HTML file to `/test_fixtures` following the current tests as a template for new tests.
175
176### Benchmarking
177Benchmarks build on the same infrastructure as testing, and actually benchmarks are automatically generated from test fixtures just like tests. Run `cargo bench` to run benchmarks locally.
178
179## Relationship to Yoga
180[Yoga](https://www.yogalayout.com) is a cross-platform implementation of Flexbox written in C. Yoga is a fantastic project but has some fundamental issues which we hope to resolve. Compared to Yoga we aim to have a stronger adherence to web standards, a flexible architecture eventually supporting multiple layout algorithms, and future performance improvements including multi-threaded layout. In addition to this we aim to use a safer language with a more modern codebase.
181
182# LICENCE
183```
184Copyright (c) 2018 Visly Inc.
185
186Permission is hereby granted, free of charge, to any person obtaining a copy
187of this software and associated documentation files (the "Software"), to deal
188in the Software without restriction, including without limitation the rights
189to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
190copies of the Software, and to permit persons to whom the Software is
191furnished to do so, subject to the following conditions:
192
193The above copyright notice and this permission notice shall be included in all
194copies or substantial portions of the Software.
195
196THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
197IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
198FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
199AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
200LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
201OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
202SOFTWARE.
203```

README.md

Stretch

CircleCI Cargo npm cocoapods bintray

Stretch is an implementation of Flexbox written in Rust. The goal of stretch is to provide a solid foundation for layout across all platforms with a specific focus on mobile. Long term we want stretch to not only support flexbox but also many other layout algorithms such as grid layout. Stretch was made for and powers https://visly.app.

Goals

Before using or contributing to stretch it is good to be aware of the core goals of the project. These are goals we are working towards, not necessarily features we currently support.

Supported Platforms

Usage

Stretch is built in Rust but comes with bindings to multiple languages and platforms so you can use it in a way that feels natural to your project.

Rust

# Cargo.toml

[dependencies]
stretch = "0.2.2"
// main.rs

use stretch::style::*;
use stretch::node::*;
use stretch::result::*;

fn main() {
  let node = Node::new(
      Style {
          size: Size { width: Dimension::Points(100.0), height: Dimension::Points(100.0) },
          justify_content: JustifyContent::Center,
          ..Default::default()
      },
      vec![&Node::new(
          Style { size: Size { width: Dimension::Percent(0.5), height: Dimension::Auto }, ..Default::default() },
          vec![],
      )],
  );

  let layout = node.compute_layout(Size::undefined()).unwrap();
  dbg!(layout);
}

Android

// Build.gradle

android {
    splits {
        abi {
            enable true
        }
    }
}

dependencies {
    implementation 'app.visly.stretch:stretch:0.2.2'
}
// MainActivity.kt

val node = Node(
  Style(size = Size(Dimension.Points(100f), Dimension.Points(100f)), justifyContent = JustifyContent.Center), 
  listOf(
    Node(Style(size = Size(Dimension.Percent(0.5f), Dimension.Percent(0.5f))), listOf())
  ))

val layout = node.computeLayout(Size(null, null))
Log.d(TAG, "width: ${layout.width}, height: ${layout.height}")

iOS

# Podfile

pod 'StretchKit', '~> 0.2.2'
// ViewController.swift
 
let node = Node(
  style: Style(size: Size(width: .points(100.0), height: .points(100.0)), justifyContent: .center), 
  children: [
    Node(style: Style(size: Size(width: .percent(0.5), height: .percent(0.5))), children: [])
  ])
  
let layout = node.computeLayout(thatFits: Size(width: nil, height: nil))
print("width: \(layout.width), height: \(layout.height)")

JavaScript

> npm install --save stretch-layout
// index.js

import { Node, JustifyContent } from 'stretch-layout';

const node = new Node({width: 100, height: 100, justifyContent: JustifyContent.Center});
node.addChild(new Node({width: '50%', height: '50%'}));
const layout = node.computeLayout();

console.log(layout.width, layout.height);

Contributing

Contributions are very welcome. Though we ask that you open an issue or pull request early in the process (before writing code) so we can discuss solutions and additions before you start spending time on implementing them. There are some specific areas where we would be extra happy to receive contributions in.

Installation

If you don't have Rust installed you have to do that first as well as install some components that we make use of to format and lint the codebase. For more on Rust see their website.

curl https://sh.rustup.rs -sSf | sh
rustup component add rustfmt
rustup component add clippy

Once that is done you can clone the repo and do some sanity checks to make sure everything is working correctly.

git clone https://github.com/vislyhq/stretch.git
cd stretch
cargo test

If you have made any changes to the API you should also update and run tests for all the platform bindings located in /bindings/*.

Testing

Stretch is tested by validating that layouts written in stretch perform the same as in Chrome. This is done by rendering an equivalent layout in HTML and then generating a Rust test case which asserts that the resulting layout is the same when run through stretch.

You can run these tests without setting up a webdriver environment but if you are looking to add any test case you will need to install chromedriver. If you are developing on macOS this is easy to do through brew.

brew tap homebrew/cask
brew cask install chromedriver

Once you have chromedriver installed and available in PATH you can re-generate all tests by running cargo run --package gentest.

To add a new test case add another HTML file to /test_fixtures following the current tests as a template for new tests.

Benchmarking

Benchmarks build on the same infrastructure as testing, and actually benchmarks are automatically generated from test fixtures just like tests. Run cargo bench to run benchmarks locally.

Relationship to Yoga

Yoga is a cross-platform implementation of Flexbox written in C. Yoga is a fantastic project but has some fundamental issues which we hope to resolve. Compared to Yoga we aim to have a stronger adherence to web standards, a flexible architecture eventually supporting multiple layout algorithms, and future performance improvements including multi-threaded layout. In addition to this we aim to use a safer language with a more modern codebase.

LICENCE

Copyright (c) 2018 Visly Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.