mod align;
mod flow_solver;
mod grid_solver;
mod row_solver;
mod size_rules;
mod size_types;
mod sizer;
mod storage;
#[allow(unused)] use crate::Layout;
use crate::dir::{Direction, Directional};
pub use align::{Align, AlignHints, AlignPair};
pub use flow_solver::{FlowSetter, FlowSolver, FlowStorage};
pub use grid_solver::{DefaultWithLen, GridCellInfo, GridDimensions, GridSetter, GridSolver};
pub use row_solver::{RowPositionSolver, RowSetter, RowSolver};
pub use size_rules::SizeRules;
pub use size_types::*;
pub use sizer::{RulesSetter, RulesSolver, SolveCache, solve_size_rules};
pub use storage::*;
#[derive(Copy, Clone, Debug)]
pub struct AxisInfo {
vertical: bool,
has_fixed: bool,
other_axis: i32,
}
impl AxisInfo {
#[inline]
pub fn new(vertical: bool, fixed: Option<i32>) -> Self {
AxisInfo {
vertical,
has_fixed: fixed.is_some(),
other_axis: fixed.unwrap_or(0),
}
}
#[inline]
pub fn is_vertical(self) -> bool {
self.vertical
}
#[inline]
pub fn is_horizontal(self) -> bool {
!self.vertical
}
#[inline]
pub fn other(&self) -> Option<i32> {
if self.has_fixed { Some(self.other_axis) } else { None }
}
pub fn map_other(&mut self, f: impl Fn(i32) -> i32) {
self.other_axis = f(self.other_axis);
}
}
impl Directional for AxisInfo {
type Flipped = Self;
type Reversed = Self;
fn flipped(mut self) -> Self::Flipped {
self.vertical = !self.vertical;
self.has_fixed = false;
self
}
#[inline]
fn reversed(self) -> Self::Reversed {
self
}
#[inline]
fn as_direction(self) -> Direction {
match self.vertical {
false => Direction::Right,
true => Direction::Down,
}
}
}
#[cfg(test)]
#[test]
fn size() {
assert_eq!(std::mem::size_of::<AxisInfo>(), 8);
}