#[derive(Clone, Copy, Debug, PartialEq)]
pub struct WindowDesc {
pub id: &'static str,
pub title: &'static str,
pub icon: &'static str,
pub order: i32,
pub size: [f32; 2],
pub min_size: [f32; 2],
pub maximized: bool,
pub always: bool,
}
impl WindowDesc {
#[must_use]
pub fn sizes_ok(&self) -> bool {
let positive =
|v: [f32; 2]| v[0].is_finite() && v[1].is_finite() && v[0] > 0.0 && v[1] > 0.0;
positive(self.size)
&& positive(self.min_size)
&& self.min_size[0] <= self.size[0]
&& self.min_size[1] <= self.size[1]
}
}
#[cfg(test)]
mod tests {
use super::*;
fn base() -> WindowDesc {
WindowDesc {
id: "strategy",
title: "策略交易",
icon: "🎯",
order: 50,
size: [1180.0, 620.0],
min_size: [820.0, 420.0],
maximized: false,
always: false,
}
}
#[test]
fn sizes_ok_accepts_well_formed() {
assert!(base().sizes_ok());
}
#[test]
fn sizes_ok_rejects_zero_and_inverted() {
let mut d = base();
d.size = [0.0, 100.0];
assert!(!d.sizes_ok(), "零宽必须拒");
let mut d = base();
d.min_size = [2000.0, 420.0];
assert!(!d.sizes_ok(), "min 宽 > size 宽必须拒");
let mut d = base();
d.size = [f32::NAN, 10.0];
assert!(!d.sizes_ok(), "NaN 必须拒");
}
#[test]
fn copy_semantics_are_cheap() {
let a = base();
let b = a;
assert_eq!(a, b);
}
}