pub trait Styling {
Show 13 methods
// Required method
fn id(&self) -> u64;
// Provided methods
fn font_size(&self, _edid: EditorId, _line: usize) -> usize { ... }
fn line_height(&self, edid: EditorId, line: usize) -> f32 { ... }
fn font_family(
&self,
_edid: EditorId,
_line: usize,
) -> Cow<'_, [FamilyOwned]> { ... }
fn weight(&self, _edid: EditorId, _line: usize) -> Weight { ... }
fn italic_style(&self, _edid: EditorId, _line: usize) -> Style { ... }
fn stretch(&self, _edid: EditorId, _line: usize) -> Stretch { ... }
fn indent_line(
&self,
_edid: EditorId,
line: usize,
_line_content: &str,
) -> usize { ... }
fn tab_width(&self, _edid: EditorId, _line: usize) -> usize { ... }
fn atomic_soft_tabs(&self, _edid: EditorId, _line: usize) -> bool { ... }
fn apply_attr_styles(
&self,
_edid: EditorId,
_style: &EditorStyle,
_line: usize,
_default: Attrs<'_>,
_attrs: &mut AttrsList,
) { ... }
fn apply_layout_styles(
&self,
_edid: EditorId,
_style: &EditorStyle,
_line: usize,
_layout_line: &mut TextLayoutLine,
) { ... }
fn paint_caret(&self, _edid: EditorId, _line: usize) -> bool { ... }
}
Expand description
There’s currently three stages of styling text:
Attrs
: This sets the default values for the text- Default font size, font family, etc.
AttrsList
: This lets you set spans of text to have different styling- Syntax highlighting, bolding specific words, etc.
Then once the text layout for the line is created from that, we have:
Layout Styles
: Where it may depend on the position of text in the line (after wrapping)- Outline boxes
TODO: We could unify the first two steps if we expose a .defaults_mut()
on AttrsList
, and
then Styling
mostly just applies whatever attributes it wants and defaults at the same time?
but that would complicate pieces of code that need the font size or line height independently.
Required Methods§
Provided Methods§
fn font_size(&self, _edid: EditorId, _line: usize) -> usize
fn line_height(&self, edid: EditorId, line: usize) -> f32
fn font_family(&self, _edid: EditorId, _line: usize) -> Cow<'_, [FamilyOwned]>
fn weight(&self, _edid: EditorId, _line: usize) -> Weight
fn italic_style(&self, _edid: EditorId, _line: usize) -> Style
fn stretch(&self, _edid: EditorId, _line: usize) -> Stretch
Sourcefn indent_line(
&self,
_edid: EditorId,
line: usize,
_line_content: &str,
) -> usize
fn indent_line( &self, _edid: EditorId, line: usize, _line_content: &str, ) -> usize
Which line the indentation line should be based off of This is used for lining it up under a scope.
fn tab_width(&self, _edid: EditorId, _line: usize) -> usize
Sourcefn atomic_soft_tabs(&self, _edid: EditorId, _line: usize) -> bool
fn atomic_soft_tabs(&self, _edid: EditorId, _line: usize) -> bool
Whether the cursor should treat leading soft tabs as if they are hard tabs
Sourcefn apply_attr_styles(
&self,
_edid: EditorId,
_style: &EditorStyle,
_line: usize,
_default: Attrs<'_>,
_attrs: &mut AttrsList,
)
fn apply_attr_styles( &self, _edid: EditorId, _style: &EditorStyle, _line: usize, _default: Attrs<'_>, _attrs: &mut AttrsList, )
Apply custom attribute styles to the line
fn apply_layout_styles( &self, _edid: EditorId, _style: &EditorStyle, _line: usize, _layout_line: &mut TextLayoutLine, )
Sourcefn paint_caret(&self, _edid: EditorId, _line: usize) -> bool
fn paint_caret(&self, _edid: EditorId, _line: usize) -> bool
Whether it should draw the cursor caret on the given line. Note that these are extra conditions on top of the typical hide cursor & the editor being active conditions This is called whenever we paint the line.