| Crates.io | taitank-rs |
| lib.rs | taitank-rs |
| version | 0.1.2 |
| created_at | 2025-11-16 10:57:17.63335+00 |
| updated_at | 2025-12-07 08:58:46.109779+00 |
| description | A cross-platform Flexbox layout engine in Rust |
| homepage | https://github.com/rustq/taitank-rs |
| repository | https://github.com/rustq/taitank-rs |
| max_upload_size | |
| id | 1935392 |
| size | 257,937 |
Taitank Rust 是 Taitank 的 Rust 实现版本,一个跨平台的轻量级 Flexbox 布局引擎。
在 Cargo.toml 中添加依赖:
[dependencies]
taitank-rs = "0.1.2"
或者从 Git 仓库使用:
[dependencies]
taitank-rs = { git = "https://github.com/rustq/taitank-rs.git" }
use taitank::*;
// 创建根节点
let root = node_create();
set_width(&root, 500.0);
set_height(&root, 300.0);
set_flex_direction(&root, FlexDirection::Row);
set_padding(&root, CSSDirection::All, 20.0);
// 创建子节点
let child1 = node_create();
set_width(&child1, 100.0);
set_height(&child1, 100.0);
set_margin(&child1, CSSDirection::Right, 10.0);
insert_child(&root, child1.clone(), 0);
// 创建使用 flex 的子节点
let child2 = node_create();
set_flex(&child2, 1.0); // flex: 1 自动填充剩余空间
set_height(&child2, 100.0);
insert_child(&root, child2.clone(), 0);
// 执行布局计算
do_layout(&root, VALUE_UNDEFINED, VALUE_UNDEFINED, TaitankDirection::Ltr, None);
// 获取布局结果
println!("Root: {}x{}", get_width(&root), get_height(&root));
println!("Child1: {}x{} at ({}, {})",
get_width(&child1), get_height(&child1),
get_left(&child1), get_top(&child1));
println!("Child2: {}x{} at ({}, {})",
get_width(&child2), get_height(&child2),
get_left(&child2), get_top(&child2));
项目包含多个示例,展示不同的使用场景:
# 运行基本示例
cargo run --example basic
# 运行复杂布局示例
cargo run --example complex
# 运行绝对定位示例
cargo run --example absolute_position
查看 examples/ 目录获取更多示例代码。
运行所有测试:
cargo test
运行特定测试:
cargo test align_self_test
运行测试并显示输出:
cargo test -- --nocapture
使用 Criterion 进行性能基准测试:
cargo bench --bench benchmark
基准测试包括:
性能报告会生成在 target/criterion/ 目录下,包含详细的性能分析。
生成并查看 API 文档:
cargo doc --open
在线文档:https://docs.rs/taitank-rs
直接作为 Rust 库使用,支持以下平台:
taitank-rust/
├── src/ # 源代码
│ ├── api.rs # 公共 API
│ ├── node.rs # 节点核心实现
│ ├── style.rs # 样式管理
│ ├── flex.rs # Flexbox 类型和枚举
│ ├── flexline.rs # FlexLine 实现
│ ├── cache.rs # 布局缓存
│ ├── config.rs # 配置管理
│ ├── util.rs # 工具函数
│ └── lib.rs # 库入口
├── tests/ # 单元测试(30+ 测试文件)
├── examples/ # 示例代码
│ ├── basic.rs # 基本使用示例
│ ├── complex.rs # 复杂布局示例
│ └── absolute_position.rs # 绝对定位示例
├── benches/ # 性能基准测试
│ └── benchmark.rs # Criterion 基准测试
├── .cargo/ # Cargo 配置
│ └── config.toml # 交叉编译配置
├── .github/ # GitHub 配置
│ └── workflows/ # CI/CD 工作流
├── build.sh # 构建脚本
├── Cargo.toml # 项目配置
├── README.md # 本文件
├── PLATFORMS.md # 平台构建指南
└── INTEGRATION.md # 集成指南
set_width() / get_width() - 宽度set_height() / get_height() - 高度set_min_width() / set_min_height() - 最小尺寸set_max_width() / set_max_height() - 最大尺寸set_flex() - flex 简写set_flex_grow() - flex-growset_flex_shrink() - flex-shrinkset_flex_basis() - flex-basisset_flex_direction() - flex-directionset_flex_wrap() - flex-wrapset_justify_content() - justify-contentset_align_items() - align-itemsset_align_content() - align-contentset_align_self() - align-selfset_margin() / get_margin() - 外边距set_padding() / get_padding() - 内边距set_border() / get_border() - 边框set_margin_auto() - 自动边距set_position_type() - position (relative/absolute)set_position() - 位置设置set_display() - display (flex/none)set_overflow() - overflowset_direction() - 布局方向 (LTR/RTL)set_node_type() - 节点类型 (Default/Text)print_node() - 打印节点树结构reset() - 重置节点状态mark_dirty() / is_dirty() - 脏标记管理Rc<RefCell<>> 进行引用计数,自动管理内存Result 类型进行错误处理Option<T> 替代 C++ 的可选参数欢迎贡献代码!请确保:
cargo fmt 确保代码格式正确cargo clippy 确保没有警告cargo test 确保所有测试通过git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)本项目采用 MIT 许可证。详见 LICENSE 文件。