#yoga #rustc #layout #cargo

yoga

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

5 unstable releases

Uses old Rust 2015

0.3.1 Jan 16, 2019
0.3.0 Oct 16, 2018
0.2.0 Jun 18, 2018
0.1.1 Oct 12, 2017
0.1.0 Oct 12, 2017

#121 in GUI

Download history 12/week @ 2021-04-13 26/week @ 2021-04-20 6/week @ 2021-04-27 9/week @ 2021-05-04 4/week @ 2021-05-11 12/week @ 2021-05-18 3/week @ 2021-05-25 9/week @ 2021-06-01 13/week @ 2021-06-08 12/week @ 2021-06-15 5/week @ 2021-06-22 7/week @ 2021-06-29 7/week @ 2021-07-06 9/week @ 2021-07-13 16/week @ 2021-07-20 24/week @ 2021-07-27

54 downloads per month

MIT license

4MB
79K 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 Visual Studio Solution 724 SLoC Visual Studio Project 571 SLoC Swift 294 SLoC // 0.2% comments Python 222 SLoC // 0.1% comments Shell 178 SLoC // 0.1% comments C 139 SLoC // 0.0% comments Ruby 85 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