use crate::{_impl_init, Interval, TextIndex, TextRange, TextUnit};
#[doc = crate::_tags!(text layout)]
#[doc = crate::_doc_location!("text/layout")]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum TextCohesion {
Atomic,
Breakable,
Elidable,
}
_impl_init![ConstInit: Self::Atomic => TextCohesion];
#[doc = crate::_tags!(text layout quant)]
#[doc = crate::_doc_location!("text/layout")]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct TextLayoutSpan {
pub range: TextRange,
pub units: TextUnit,
}
_impl_init![ConstInit: Self::from_prim(0, 0, 0) => TextLayoutSpan];
impl TextLayoutSpan {
pub const fn new(start: TextIndex, end: TextIndex, units: TextUnit) -> Self {
Self { range: TextRange { start, end }, units }
}
pub const fn with_range(range: TextRange, units: TextUnit) -> Self {
Self { range, units }
}
pub const fn from_prim(start: TextUnit, end: TextUnit, units: TextUnit) -> Self {
Self::new(TextIndex(start), TextIndex(end), units)
}
pub const fn start(self) -> TextIndex {
self.range.start
}
pub const fn end(self) -> TextIndex {
self.range.end
}
pub const fn interval(self) -> Interval<TextIndex> {
Interval::closed_open(self.start(), self.end())
}
}
#[doc = crate::_tags!(text layout io)]
#[doc = crate::_doc_location!("text/layout")]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct TextSymbol {
pub units: TextUnit,
pub cohesion: TextCohesion,
}
_impl_init![ConstInit: Self::new(TextUnit::INIT, TextCohesion::INIT) => TextSymbol];
impl TextSymbol {
pub const fn new(units: TextUnit, cohesion: TextCohesion) -> Self {
Self { units, cohesion }
}
}