#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum CaretMode {
Persistent,
#[default]
Blinking,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum CaretHeight {
FontSize(f32),
TextBand,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ThemeCaret {
mode: CaretMode,
width: f32,
height: CaretHeight,
composition_line: f32,
}
impl ThemeCaret {
pub fn new(mode: CaretMode) -> Self {
Self {
mode,
..Self::default()
}
}
pub fn legacy() -> Self {
Self {
mode: CaretMode::Blinking,
width: 1.0,
height: CaretHeight::FontSize(1.0),
composition_line: 1.0,
}
}
pub fn mode(&self) -> CaretMode {
self.mode
}
pub fn set_mode(&mut self, mode: CaretMode) {
self.mode = mode;
}
pub fn with_mode(mut self, mode: CaretMode) -> Self {
self.mode = mode;
self
}
pub fn width(&self) -> f32 {
if self.width.is_finite() {
self.width.max(0.0)
} else {
1.0
}
}
pub fn set_width(&mut self, width: f32) {
self.width = width;
}
pub fn with_width(mut self, width: f32) -> Self {
self.width = width;
self
}
pub fn height(&self) -> CaretHeight {
self.height
}
pub fn set_height(&mut self, height: CaretHeight) {
self.height = height;
}
pub fn with_height(mut self, height: CaretHeight) -> Self {
self.height = height;
self
}
pub fn composition_line(&self) -> f32 {
if self.composition_line.is_finite() {
self.composition_line.max(0.0)
} else {
1.0
}
}
pub fn set_composition_line(&mut self, width: f32) {
self.composition_line = width;
}
pub fn with_composition_line(mut self, width: f32) -> Self {
self.composition_line = width;
self
}
}
impl Default for ThemeCaret {
fn default() -> Self {
Self {
mode: CaretMode::Blinking,
width: 1.5,
height: CaretHeight::FontSize(18.0 / 14.0),
composition_line: 1.5,
}
}
}