diff --git a/hcie-iced-app/crates/hcie-iced-gui/Cargo.toml b/hcie-iced-app/crates/hcie-iced-gui/Cargo.toml index 65b51bd..7361398 100644 --- a/hcie-iced-app/crates/hcie-iced-gui/Cargo.toml +++ b/hcie-iced-app/crates/hcie-iced-gui/Cargo.toml @@ -3,6 +3,10 @@ name = "hcie-iced-gui" version = "0.1.0" edition = "2021" +[lib] +name = "hcie_iced_gui" +path = "src/lib.rs" + [features] default = ["tablet-evdev"] tablet-evdev = ["dep:evdev"] diff --git a/hcie-iced-app/crates/hcie-iced-gui/src/lib.rs b/hcie-iced-app/crates/hcie-iced-gui/src/lib.rs new file mode 100644 index 0000000..7fb2e91 --- /dev/null +++ b/hcie-iced-app/crates/hcie-iced-gui/src/lib.rs @@ -0,0 +1,3 @@ +//! HCIE Iced GUI library — re-exports selection types for integration tests. + +pub mod selection; diff --git a/hcie-iced-app/crates/hcie-iced-gui/tests/selection_test.rs b/hcie-iced-app/crates/hcie-iced-gui/tests/selection_test.rs new file mode 100644 index 0000000..6fa5bf8 --- /dev/null +++ b/hcie-iced-app/crates/hcie-iced-gui/tests/selection_test.rs @@ -0,0 +1,72 @@ +//! Tests for selection types: SelectionTransform, TransformHandle, CropState. + +use hcie_iced_gui::selection::{CropState, SelectionTransform, TransformHandle}; + +#[test] +fn test_selection_transform_is_empty() { + let tr = SelectionTransform { + pixels: vec![], + width: 0, + height: 0, + pos: iced::Vector::ZERO, + size: iced::Vector::ZERO, + rotation: 0.0, + }; + assert!(tr.is_empty()); +} + +#[test] +fn test_selection_transform_with_data() { + let tr = SelectionTransform { + pixels: vec![255; 100], + width: 5, + height: 5, + pos: iced::Vector::new(10.0, 20.0), + size: iced::Vector::new(5.0, 5.0), + rotation: 0.0, + }; + assert!(!tr.is_empty()); +} + +#[test] +fn test_crop_state_lifecycle() { + let mut crop = CropState::default(); + assert!(!crop.active); + assert!(crop.rect.is_none()); + + crop.start_drag(10.0, 10.0); + assert!(crop.active); + assert!(crop.is_dragging); + + crop.update_drag(100.0, 100.0); + assert!(crop.rect.is_some()); + let (x, y, w, h) = crop.rect.unwrap(); + assert_eq!(x, 10.0); + assert_eq!(y, 10.0); + assert_eq!(w, 90.0); + assert_eq!(h, 90.0); + + crop.end_drag(); + assert!(!crop.is_dragging); + + let result = crop.confirm(); + assert!(result.is_some()); + assert!(!crop.active); +} + +#[test] +fn test_crop_cancel() { + let mut crop = CropState::default(); + crop.start_drag(10.0, 10.0); + crop.update_drag(100.0, 100.0); + crop.cancel(); + assert!(!crop.active); + assert!(crop.rect.is_none()); +} + +#[test] +fn test_transform_handle_cursor_hints() { + assert_eq!(TransformHandle::Move.cursor_hint(), "move"); + assert_eq!(TransformHandle::TopLeft.cursor_hint(), "nwse-resize"); + assert_eq!(TransformHandle::Rotate.cursor_hint(), "crosshair"); +}