From 1536ee41a38f7f57fd5282697ee37462d9e11f34 Mon Sep 17 00:00:00 2001 From: lucasmerlin Date: Wed, 3 Jun 2026 11:39:34 +0200 Subject: [PATCH] Better test --- crates/egui_kittest/tests/atom_layout.rs | 52 ------------------- .../tests/snapshots/atom_layout_nesting.png | 3 -- .../tests/snapshots/atom_layout_nesting.png | 3 ++ tests/egui_tests/tests/test_atoms.rs | 50 ++++++++++++++++++ 4 files changed, 53 insertions(+), 55 deletions(-) delete mode 100644 crates/egui_kittest/tests/atom_layout.rs delete mode 100644 crates/egui_kittest/tests/snapshots/atom_layout_nesting.png create mode 100644 tests/egui_tests/tests/snapshots/atom_layout_nesting.png diff --git a/crates/egui_kittest/tests/atom_layout.rs b/crates/egui_kittest/tests/atom_layout.rs deleted file mode 100644 index 7f4a1d141..000000000 --- a/crates/egui_kittest/tests/atom_layout.rs +++ /dev/null @@ -1,52 +0,0 @@ -#![cfg(feature = "snapshot")] -#![cfg(feature = "wgpu")] - -use egui::widget_style::{Classes, WidgetState}; -use egui::{Atom, AtomExt, AtomLayout, Direction, Frame}; - -/// A root [`AtomLayout`] (in a [`Frame::canvas`]) that stacks several nested [`AtomLayout`]s -/// (each in an inactive button frame), one per [`Direction`], to exercise nesting and the -/// direction setting together. -#[test] -fn atom_layout_nesting_and_direction() { - let mut harness = egui_kittest::Harness::new_ui(|ui| { - let style = ui.style().clone(); - - // The frame of an inactive button. - let button_frame = style - .button_style(&Classes::default(), WidgetState::Inactive) - .frame; - - // A nested layout laid out along `direction`, labelled to read in that direction. - let row = |direction: Direction, atoms: [&'static str; 3]| { - Atom::layout( - AtomLayout::new((atoms[0], atoms[1], atoms[2])) - .direction(direction) - .frame(button_frame.clone()), - ) - }; - - // Each axis pair gets the same label order, so the reversed direction visibly flips it - // (e.g. `RightToLeft` reads "right to left"). - AtomLayout::new(( - // The two horizontal rows stacked into their own `TopDown` layout. - Atom::layout( - AtomLayout::new(( - row(Direction::LeftToRight, ["left", "to", "right"]).atom_grow(true), - row(Direction::RightToLeft, ["left", "to", "right"]).atom_grow(true), - )) - .direction(Direction::TopDown), - ).atom_grow(true), - row(Direction::TopDown, ["top", "to", "bottom"]), - row(Direction::BottomUp, ["top", "to", "bottom"]), - )) - .direction(Direction::LeftToRight) - .frame(Frame::canvas(&style)) - .show(ui); - }); - - harness.fit_contents(); - - #[cfg(all(feature = "snapshot", feature = "wgpu"))] - harness.snapshot("atom_layout_nesting"); -} diff --git a/crates/egui_kittest/tests/snapshots/atom_layout_nesting.png b/crates/egui_kittest/tests/snapshots/atom_layout_nesting.png deleted file mode 100644 index c22d09164..000000000 --- a/crates/egui_kittest/tests/snapshots/atom_layout_nesting.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e448998e5d18f3d5704e1280794ad5732087afab73fb591ad8025810a09f2db0 -size 6338 diff --git a/tests/egui_tests/tests/snapshots/atom_layout_nesting.png b/tests/egui_tests/tests/snapshots/atom_layout_nesting.png new file mode 100644 index 000000000..bbff7f706 --- /dev/null +++ b/tests/egui_tests/tests/snapshots/atom_layout_nesting.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e43b410ab0a06b40da5ad9c7fd105d11201d44a3afd63fd213429cc39013c0d4 +size 6964 diff --git a/tests/egui_tests/tests/test_atoms.rs b/tests/egui_tests/tests/test_atoms.rs index f7e0a4af1..6563c0d8a 100644 --- a/tests/egui_tests/tests/test_atoms.rs +++ b/tests/egui_tests/tests/test_atoms.rs @@ -120,6 +120,56 @@ fn test_button_shortcut_text() { harness.snapshot("button_shortcut"); } +/// A root [`AtomLayout`] (in a [`Frame::canvas`]) that stacks several nested [`AtomLayout`]s +/// (each in an inactive button frame), one per [`Direction`], to exercise nesting and the +/// direction setting together. +#[test] +fn test_atom_layout_nesting_and_direction() { + use egui::widget_style::{Classes, WidgetState}; + use egui::{Atom, AtomLayout, Direction, Frame}; + + let mut harness = HarnessBuilder::default().build_ui(|ui| { + let style = ui.style().clone(); + + // The frame of an inactive button. + let button_frame = style + .button_style(&Classes::default(), WidgetState::Inactive) + .frame; + + // A nested layout laid out along `direction`, labelled to read in that direction. + let row = |direction: Direction| { + Atom::layout( + AtomLayout::new(("one", "two", "three")) + .direction(direction) + .frame(button_frame.clone()), + ) + }; + + // Each axis pair gets the same label order, so the reversed direction visibly flips it + // (e.g. `RightToLeft` reads "right to left"). + AtomLayout::new(( + // The two horizontal rows stacked into their own `TopDown` layout. + Atom::layout( + AtomLayout::new(( + row(Direction::LeftToRight).atom_grow(true), + row(Direction::RightToLeft).atom_grow(true), + )) + .direction(Direction::TopDown), + ) + .atom_grow(true), + row(Direction::TopDown), + row(Direction::BottomUp), + )) + .direction(Direction::LeftToRight) + .frame(Frame::canvas(&style)) + .show(ui); + }); + + harness.fit_contents(); + + harness.snapshot("atom_layout_nesting"); +} + /// Tests the spacing between galleys. /// All of these should look the same. #[test]