yoga 0.5.0

Rust bindings for Facebook's Yoga, a Flexbox layout engine
Documentation
/*!
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @generated SignedSource<<b1591b6853675df15d6e600fefc23a9d>>
 * generated by gentest/gentest-driver.ts from gentest/fixtures/YGPaddingTest.html
 */

extern crate ordered_float;
extern crate yoga;
mod test_utils;

use yoga::*;

#[test]
fn test_padding_no_size() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_position_type(PositionType::Absolute);
    root.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(20_f32, root.get_layout_width());
    assert_eq!(20_f32, root.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(20_f32, root.get_layout_width());
    assert_eq!(20_f32, root.get_layout_height());
}

#[test]
fn test_padding_container_match_child() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_position_type(PositionType::Absolute);
    root.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(10_f32.into()));
    root_child0.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child0, 0);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(30_f32, root.get_layout_width());
    assert_eq!(30_f32, root.get_layout_height());

    assert_eq!(10_f32, root_child0.get_layout_left());
    assert_eq!(10_f32, root_child0.get_layout_top());
    assert_eq!(10_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(30_f32, root.get_layout_width());
    assert_eq!(30_f32, root.get_layout_height());

    assert_eq!(10_f32, root_child0.get_layout_left());
    assert_eq!(10_f32, root_child0.get_layout_top());
    assert_eq!(10_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());
}

#[test]
fn test_padding_flex_child() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_position_type(PositionType::Absolute);
    root.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(1_f32);
    root_child0.set_width(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child0, 0);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(10_f32, root_child0.get_layout_left());
    assert_eq!(10_f32, root_child0.get_layout_top());
    assert_eq!(10_f32, root_child0.get_layout_width());
    assert_eq!(80_f32, root_child0.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(80_f32, root_child0.get_layout_left());
    assert_eq!(10_f32, root_child0.get_layout_top());
    assert_eq!(10_f32, root_child0.get_layout_width());
    assert_eq!(80_f32, root_child0.get_layout_height());
}

#[test]
fn test_padding_stretch_child() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_position_type(PositionType::Absolute);
    root.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child0, 0);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(10_f32, root_child0.get_layout_left());
    assert_eq!(10_f32, root_child0.get_layout_top());
    assert_eq!(80_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(10_f32, root_child0.get_layout_left());
    assert_eq!(10_f32, root_child0.get_layout_top());
    assert_eq!(80_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());
}

#[test]
fn test_padding_center_child() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_justify_content(Justify::Center);
    root.set_align_items(Align::Center);
    root.set_position_type(PositionType::Absolute);
    root.set_padding(Edge::Start, StyleUnit::Point(10_f32.into()));
    root.set_padding(Edge::End, StyleUnit::Point(20_f32.into()));
    root.set_padding(Edge::Bottom, StyleUnit::Point(20_f32.into()));
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(10_f32.into()));
    root_child0.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child0, 0);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(40_f32, root_child0.get_layout_left());
    assert_eq!(35_f32, root_child0.get_layout_top());
    assert_eq!(10_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(50_f32, root_child0.get_layout_left());
    assert_eq!(35_f32, root_child0.get_layout_top());
    assert_eq!(10_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());
}

#[test]
fn test_child_with_padding_align_end() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_justify_content(Justify::FlexEnd);
    root.set_align_items(Align::FlexEnd);
    root.set_position_type(PositionType::Absolute);
    root.set_width(StyleUnit::Point(200_f32.into()));
    root.set_height(StyleUnit::Point(200_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_padding(Edge::Left, StyleUnit::Point(20_f32.into()));
    root_child0.set_padding(Edge::Top, StyleUnit::Point(20_f32.into()));
    root_child0.set_padding(Edge::Right, StyleUnit::Point(20_f32.into()));
    root_child0.set_padding(Edge::Bottom, StyleUnit::Point(20_f32.into()));
    root_child0.set_width(StyleUnit::Point(100_f32.into()));
    root_child0.set_height(StyleUnit::Point(100_f32.into()));
    root.insert_child(&mut root_child0, 0);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(200_f32, root.get_layout_width());
    assert_eq!(200_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(100_f32, root_child0.get_layout_top());
    assert_eq!(100_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(200_f32, root.get_layout_width());
    assert_eq!(200_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(100_f32, root_child0.get_layout_top());
    assert_eq!(100_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());
}

#[test]
fn test_physical_and_relative_edge_defined() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_position_type(PositionType::Absolute);
    root.set_padding(Edge::Left, StyleUnit::Point(20_f32.into()));
    root.set_padding(Edge::End, StyleUnit::Point(50_f32.into()));
    root.set_width(StyleUnit::Point(200_f32.into()));
    root.set_height(StyleUnit::Point(200_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Percent(100_f32.into()));
    root_child0.set_height(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(200_f32, root.get_layout_width());
    assert_eq!(200_f32, root.get_layout_height());

    assert_eq!(20_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(130_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(200_f32, root.get_layout_width());
    assert_eq!(200_f32, root.get_layout_height());

    assert_eq!(50_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(150_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());
}