gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1068HTML 999Markdown 12TOML 83188 Definiciones

⎇ b91874d4e34ecc9054b468a338ffcae6f61a1b4a benches/generated/grid_percent_items_nested_with_padding_margin.rs Rust · 83 líneas · 3.8 KB Historia Quién tocó qué crudo

Fix percent sized tracks (#314) 06a168cb1 · Nico Burns ·

1pub fn compute() {
2    #[allow(unused_imports)]
3    use taffy::prelude::*;
4    let mut taffy = taffy::Taffy::new();
5    let node000 = taffy
6        .new_leaf(taffy::style::Style {
7            size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
8            margin: taffy::geometry::Rect {
9                left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
10                right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
11                top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
12                bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13            },
14            padding: taffy::geometry::Rect {
15                left: taffy::style::LengthPercentage::Points(3f32),
16                right: taffy::style::LengthPercentage::Points(3f32),
17                top: taffy::style::LengthPercentage::Points(3f32),
18                bottom: taffy::style::LengthPercentage::Points(3f32),
19            },
20            ..Default::default()
21        })
22        .unwrap();
23    let node00 = taffy
24        .new_with_children(
25            taffy::style::Style {
26                display: taffy::style::Display::Grid,
27                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
28                margin: taffy::geometry::Rect {
29                    left: taffy::style::LengthPercentageAuto::Points(5f32),
30                    right: taffy::style::LengthPercentageAuto::Points(5f32),
31                    top: taffy::style::LengthPercentageAuto::Points(5f32),
32                    bottom: taffy::style::LengthPercentageAuto::Points(5f32),
33                },
34                padding: taffy::geometry::Rect {
35                    left: taffy::style::LengthPercentage::Percent(0.03f32),
36                    right: taffy::style::LengthPercentage::Percent(0.03f32),
37                    top: taffy::style::LengthPercentage::Percent(0.03f32),
38                    bottom: taffy::style::LengthPercentage::Percent(0.03f32),
39                },
40                ..Default::default()
41            },
42            &[node000],
43        )
44        .unwrap();
45    let node0 = taffy
46        .new_with_children(
47            taffy::style::Style {
48                display: taffy::style::Display::Grid,
49                min_size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.6f32), height: auto() },
50                margin: taffy::geometry::Rect {
51                    left: taffy::style::LengthPercentageAuto::Points(5f32),
52                    right: taffy::style::LengthPercentageAuto::Points(5f32),
53                    top: taffy::style::LengthPercentageAuto::Points(5f32),
54                    bottom: taffy::style::LengthPercentageAuto::Points(5f32),
55                },
56                padding: taffy::geometry::Rect {
57                    left: taffy::style::LengthPercentage::Points(3f32),
58                    right: taffy::style::LengthPercentage::Points(3f32),
59                    top: taffy::style::LengthPercentage::Points(3f32),
60                    bottom: taffy::style::LengthPercentage::Points(3f32),
61                },
62                ..Default::default()
63            },
64            &[node00],
65        )
66        .unwrap();
67    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
68    let node = taffy
69        .new_with_children(
70            taffy::style::Style {
71                display: taffy::style::Display::Grid,
72                grid_template_rows: vec![flex(1f32), flex(4f32)],
73                size: taffy::geometry::Size {
74                    width: taffy::style::Dimension::Points(200f32),
75                    height: taffy::style::Dimension::Points(200f32),
76                },
77                ..Default::default()
78            },
79            &[node0, node1],
80        )
81        .unwrap();
82    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
83}