()
| 1304 | #[rustfmt::skip] |
| 1305 | #[test] |
| 1306 | fn test_example() { |
| 1307 | let mut ply = Ply::<()>::new_headless(Dimensions::new(1000.0, 1000.0)); |
| 1308 | |
| 1309 | let mut ui = ply.begin(); |
| 1310 | |
| 1311 | ui.set_measure_text_function(|_, _| { |
| 1312 | Dimensions::new(100.0, 24.0) |
| 1313 | }); |
| 1314 | |
| 1315 | for &(label, level) in &[("Road", 1), ("Wall", 2), ("Tower", 3)] { |
| 1316 | ui.element().width(grow!()).height(fixed!(36.0)) |
| 1317 | .layout(|l| l |
| 1318 | .direction(crate::layout::LayoutDirection::LeftToRight) |
| 1319 | .gap(12) |
| 1320 | .align(crate::align::AlignX::Left, crate::align::AlignY::CenterY) |
| 1321 | ) |
| 1322 | .children(|ui| { |
| 1323 | ui.text(label, |t| t |
| 1324 | .font_size(18) |
| 1325 | .color(0xFFFFFF) |
| 1326 | ); |
| 1327 | ui.element().width(grow!()).height(fixed!(18.0)) |
| 1328 | .corner_radius(9.0) |
| 1329 | .background_color(0x555555) |
| 1330 | .children(|ui| { |
| 1331 | ui.element() |
| 1332 | .width(fixed!(300.0 * level as f32 / 3.0)) |
| 1333 | .height(grow!()) |
| 1334 | .corner_radius(9.0) |
| 1335 | .background_color(0x45A85A) |
| 1336 | .empty(); |
| 1337 | }); |
| 1338 | }); |
| 1339 | } |
| 1340 | |
| 1341 | let items = ui.eval(); |
| 1342 | |
| 1343 | for item in &items { |
| 1344 | println!( |
| 1345 | "id: {}\nbbox: {:?}\nconfig: {:?}", |
| 1346 | item.id, item.bounding_box, item.config, |
| 1347 | ); |
| 1348 | } |
| 1349 | |
| 1350 | assert_eq!(items.len(), 9); |
| 1351 | |
| 1352 | // Road label |
| 1353 | assert_eq!(items[0].bounding_box.x, 0.0); |
| 1354 | assert_eq!(items[0].bounding_box.y, 6.0); |
| 1355 | assert_eq!(items[0].bounding_box.width, 100.0); |
| 1356 | assert_eq!(items[0].bounding_box.height, 24.0); |
| 1357 | match &items[0].config { |
| 1358 | render_commands::RenderCommandConfig::Text(text) => { |
| 1359 | assert_eq!(text.text, "Road"); |
| 1360 | assert_eq!(text.color.r, 255.0); |
| 1361 | assert_eq!(text.color.g, 255.0); |
| 1362 | assert_eq!(text.color.b, 255.0); |
| 1363 | assert_eq!(text.color.a, 255.0); |
nothing calls this directly
no test coverage detected