iced_core/text/
highlighter.rs1use crate::Color;
3
4use std::ops::Range;
5
6pub trait Highlighter: 'static {
12 type Settings: PartialEq + Clone;
14
15 type Highlight;
17
18 type Iterator<'a>: Iterator<Item = (Range<usize>, Self::Highlight)>
20 where
21 Self: 'a;
22
23 fn new(settings: &Self::Settings) -> Self;
25
26 fn update(&mut self, new_settings: &Self::Settings);
28
29 fn change_line(&mut self, line: usize);
31
32 fn highlight_line(&mut self, line: &str) -> Self::Iterator<'_>;
37
38 fn current_line(&self) -> usize;
43}
44
45#[derive(Debug, Clone, Copy)]
47pub struct PlainText;
48
49impl Highlighter for PlainText {
50 type Settings = ();
51 type Highlight = ();
52
53 type Iterator<'a> = std::iter::Empty<(Range<usize>, Self::Highlight)>;
54
55 fn new(_settings: &Self::Settings) -> Self {
56 Self
57 }
58
59 fn update(&mut self, _new_settings: &Self::Settings) {}
60
61 fn change_line(&mut self, _line: usize) {}
62
63 fn highlight_line(&mut self, _line: &str) -> Self::Iterator<'_> {
64 std::iter::empty()
65 }
66
67 fn current_line(&self) -> usize {
68 usize::MAX
69 }
70}
71
72#[derive(Debug, Clone, Copy, PartialEq)]
74pub struct Format<Font> {
75 pub color: Option<Color>,
77 pub font: Option<Font>,
79}
80
81impl<Font> Default for Format<Font> {
82 fn default() -> Self {
83 Self {
84 color: None,
85 font: None,
86 }
87 }
88}