#layout #yoga

yoga

Rust bindings for Facebook’s Yoga, a Flexbox layout engine

3 unstable releases

0.2.0 Jun 18, 2018
0.1.1 Oct 12, 2017
0.1.0 Oct 12, 2017

#25 in Rendering engine

Download history 2/week @ 2018-09-13 1/week @ 2018-09-20 8/week @ 2018-09-27 7/week @ 2018-10-04 1/week @ 2018-10-11 74/week @ 2018-10-18 2/week @ 2018-10-25 9/week @ 2018-11-01 31/week @ 2018-11-08 11/week @ 2018-11-15 5/week @ 2018-11-22 15/week @ 2018-11-29 7/week @ 2018-12-06

19 downloads per month

MIT license

4MB
78K SLoC

C++ 22K SLoC // 0.0% comments JavaScript 19K SLoC // 0.0% comments C# 17K SLoC // 0.0% comments Java 16K SLoC // 0.0% comments Rust 1.5K SLoC // 0.0% comments Objective C 1K SLoC // 0.0% comments Swift 294 SLoC // 0.2% comments Python 229 SLoC // 0.0% comments Shell 178 SLoC // 0.1% comments C 139 SLoC // 0.0% comments Ruby 81 SLoC // 0.0% comments Prolog 9 SLoC Batch 2 SLoC

Yoga-rs

Build Status

A Rust wrapper for Facebook's Yoga layout library.

Dependencies

  • cargo
  • rustc

Build

$ cargo build --release

Run Example

$ cargo run --release --example layout

Example Code

#[macro_use]
extern crate yoga;

use yoga::prelude::*;
use yoga::Node;
use yoga::StyleUnit::{Auto, UndefinedValue};

fn main() {
	let mut node = Node::new();

	let mut child = Node::new();
	let mut other_child = Node::new();

	node.insert_child(&mut child, 0);
	node.insert_child(&mut other_child, 1);

	style!(node,
		Margin(10 pt),
		MarginLeft(Auto),
		PaddingHorizontal(4 pt),
		Left(16 %),
		Bottom(UndefinedValue)
	);

	let child_styles = make_styles!(
		Width(32 pt),
		Height(32 pt),
		FlexGrow(1.0),
		Margin(Auto)
	);

	child.apply_styles(&child_styles);
	other_child.apply_styles(&child_styles);

	node.calculate_layout(512.0, 512.0, yoga::Direction::LTR);

	println!("Layout is {:#?}", child.get_layout());
}

Testing

The unit tests are automatically generated based on upstream fixtures and should not be edited manually.

$ cargo test

To generate the test cases: Download the ChromeDriver binary and put it somewhere in your $PATH. Linux/MacOS example:

$ cp chromedriver /usr/local/bin

Install the required Ruby gem.

$ sudo gem install watir

Generate the tests.

$ ruby gentest/gentest.rb

Dependencies

  • build build.rs
  • build bindgen 0.37
  • build cc 1.0