use {
crate::*,
};
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct OrderedItemStyle {
pub index_style: CompoundStyle,
pub index_suffix: StyledChar,
}
impl Default for OrderedItemStyle {
fn default() -> Self {
Self {
index_style: CompoundStyle::default(),
index_suffix: StyledChar::from_fg_char(gray(12), '.'),
}
}
}
impl OrderedItemStyle {
pub fn no_style() -> Self {
Self {
index_style: CompoundStyle::default(),
index_suffix: StyledChar::nude('.'),
}
}
pub fn blend_with<C: Into<coolor::Color> + Copy>(&mut self, color: C, weight: f32) {
self.index_style.blend_with(color, weight);
self.index_suffix.blend_with(color, weight);
}
}
pub fn ordered_item_indent(
level: u8,
index: u32,
) -> usize {
index_width(index) + 2 + level as usize }
fn index_width(index: u32) -> usize {
if index < 10 {
1
} else if index < 100 {
2
} else if index < 1_000 {
3
} else if index < 10_000 {
4
} else if index < 100_000 {
5
} else if index < 1_000_000 {
6
} else if index < 10_000_000 {
7
} else if index < 100_000_000 {
8
} else if index < 1_000_000_000 {
9
} else {
10
}
}
#[test]
fn test_index_width() {
assert_eq!(index_width(0), 1);
assert_eq!(index_width(1), 1);
assert_eq!(index_width(9), 1);
assert_eq!(index_width(10), 2);
assert_eq!(index_width(99), 2);
assert_eq!(index_width(100), 3);
}