use crate::components::dimensions::layout_dimensions::Axis;
use crate::components::dimensions::*;
use crate::Bounds;
#[test]
fn test_component_dimensions_basic() {
let bounds = Bounds::new(0, 0, 10, 5);
let dims = ComponentDimensions::new(bounds);
let outer = dims.outer_bounds();
assert_eq!(outer.x1, 0);
assert_eq!(outer.x2, 10);
let (cx, cy) = dims.center();
assert_eq!(cx, 5);
assert_eq!(cy, 2);
}
#[test]
fn test_scroll_dimensions_basic() {
let bounds = Bounds::new(0, 0, 10, 5);
let scroll_dims = ScrollDimensions::new(
(20, 15), (10, 5), (0.0, 0.0), bounds,
);
assert!(scroll_dims.is_scrollbar_needed(Orientation::Horizontal));
assert!(scroll_dims.is_scrollbar_needed(Orientation::Vertical));
}
#[test]
fn test_text_dimensions_basic() {
let bounds = Bounds::new(0, 0, 9, 3); let text_dims = TextDimensions::new(bounds);
let text = "This is a very long line";
let wrapped = text_dims.wrap_text(text);
assert!(wrapped.len() > 1);
for line in &wrapped {
assert!(line.chars().count() <= 10);
}
}
#[test]
fn test_mouse_dimensions_basic() {
let screen_bounds = Bounds::new(0, 0, 10, 5);
let content_bounds = Bounds::new(2, 2, 8, 3);
let mouse_dims = MouseDimensions::new(
screen_bounds,
content_bounds,
(0, 0), (20, 10), );
assert!(mouse_dims.is_within_screen_bounds(5, 3));
assert!(!mouse_dims.is_within_screen_bounds(15, 8));
assert!(mouse_dims.is_within_content_bounds(5, 2));
assert!(!mouse_dims.is_within_content_bounds(1, 1));
}
#[test]
fn test_progress_dimensions_basic() {
let bounds = Bounds::new(0, 0, 9, 2); let mut progress_dims = ProgressDimensions::new(bounds, Orientation::Horizontal);
progress_dims.set_progress(0.5); let fill_size = progress_dims.calculate_fill_size();
assert_eq!(fill_size, 5);
let fill_bounds = progress_dims.get_fill_bounds();
assert_eq!(fill_bounds.x1, 0);
assert_eq!(fill_bounds.x2, 4); }
#[test]
fn test_layout_dimensions_basic() {
let total_bounds = Bounds::new(0, 0, 100, 50);
let layout = LayoutDimensions::new(total_bounds);
let percent = LayoutDimensions::parse_percentage("50%").unwrap();
assert_eq!(percent, 0.5);
let absolute = layout.percentage_to_absolute(0.5, Axis::X);
assert_eq!(absolute, 50); }