当前位置: 首页 > 软件库 > 手机/移动开发 > >

stretch

授权协议 MIT License
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 池俊茂
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Stretch

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.

  • High performance
  • Cross platform
  • Small binary size
  • Support multiple layout systems
  • Multi-threaded layout
  • Language bindings for most common languages

Supported Platforms

  • Rust
  • Android
  • iOS
  • JavaScript / TypeScript

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.3.2"
// main.rs

use stretch::geometry::Size;
use stretch::style::*;

fn main() -> Result<(), stretch::Error> {
    let mut stretch = stretch::node::Stretch::new();
    
    let child = stretch.new_node(
        Style { size: Size { width: Dimension::Percent(0.5), height: Dimension::Auto }, ..Default::default() },
        vec![],
    )?;

    let node = stretch.new_node(
        Style {
            size: Size { width: Dimension::Points(100.0), height: Dimension::Points(100.0) },
            justify_content: JustifyContent::Center,
            ..Default::default()
        },
        vec![child],
    )?;

    stretch.compute_layout(node, Size::undefined())?;
    dbg!(stretch.layout(node)?);
}

Android

// Build.gradle

android {
    splits {
        abi {
            enable true
        }
    }
}

dependencies {
    implementation 'app.visly.stretch:stretch:0.3.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.3.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 { Allocator, Node, JustifyContent } from 'stretch-layout';

const allocator = new Allocator();
const node = new Node(allocator, {width: 100, height: 100, justifyContent: JustifyContent.Center});
node.addChild(new Node(allocator, {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.

  • Binary size reduction
  • Runtime performance
  • Ensure build / test environment works well on non macOS platforms
  • Alternate layout systems (grid layout perhaps?)
  • Web compatibility tests
  • RTL support
  • Platform bindings
  • API improvements
  • Documentation & Examples

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.
  • addWidget(QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()) insertStretch(int index, int stretch = 0) setStretchFactor(QWidget *widget, int stretch) 等函数都可以设置布局中,组件的不同伸缩大小。 Q

  • RemoveItem() Stretch 和 Spacing 都属于 QSpacerItem 使用removeItem 删除: for (int i = 0; i < boxLayout->count(); ++i) { QLayoutItem *layoutItem = boxLayout->itemAt(i); if(layoutItem->spacerItem())

  • https://en.wikipedia.org/wiki/Deformation_(physics)#Stretch_ratio stretch ratio 符号是 λ \lambda λ,定义见上面链接,从stretch ratio可以导出一系列应变的定义公式

  • Stretch ProcessingReasons for Using Stretch Processing The linear FM waveform is popular in radar systems because its large time-bandwidth product can provide good range resolution. However, the large

  • 随着Debian 9的普及,但由于伟大的墙的存在,那就有必要整理一下国内的镜像站点。 1.使用说明 一般情况下,修改/etc/apt/sources.list文件,将Debian的默认源地址改成新的地址即可,比如将http://deb.debian.org改成https://mirrors.xxx.com,可使用以下命令: 1 sed -i "s@http://deb.debian.org@htt

 相关资料
  • This page shows how to configure Handsontable column stretching: StretchH last column StretchH all columns StretchH none (default) StretchH last column The following example creates a table with verti

  • 我想在我的debian机器上安装Kubernetes: 查看google deb软件包档案,我只找到了“kubectl”的软件包,没有其他内容: https://packages.cloud.google.com/apt/dists/kubernetes-stretch/main/binary-amd64/Packages 与ubuntu xenial相比,很多软件包都不见了。有人能这么好,给我更

  • 如上所述,尝试安装开放蟒蛇。 通常这将是一个简单的,但它似乎不起作用。相反,opencv安装到minicon da目录 而不是全局 尝试通过应用程序在荆棘中添加失败。在蟒蛇程序中... 结果为 我也尝试过将其添加到路径(),但运气不好。

  • 我正在尝试在我的Stretch Debian上安装docker。 我遵循了指南,但当我使用“sudo apt-get更新”时,我得到: https://download.docker.com/linux/debian拉伸/稳定amd64包gnutls_handshake()失败:公钥签名验证失败。 “卷曲 -fsSL https://download.docker.com/linux/debian

  • 描述 (Description) font-stretch属性使文本字符比font.s默认字符宽度更宽或更窄。 可能的值 (Possible Values) ultra-condensed - 元素中的文本字符将极度缩小。 extra-condensed - 元素中的文本字符将显着缩小。 condensed - 元素中的文本字符将缩小,比值是半压缩的更多。 semi-condensed - 元素中