Trait Styling

Source
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§

Source

fn id(&self) -> u64

The id for caching the styling.

Provided Methods§

Source

fn font_size(&self, _edid: EditorId, _line: usize) -> usize

Source

fn line_height(&self, edid: EditorId, line: usize) -> f32

Source

fn font_family(&self, _edid: EditorId, _line: usize) -> Cow<'_, [FamilyOwned]>

Source

fn weight(&self, _edid: EditorId, _line: usize) -> Weight

Source

fn italic_style(&self, _edid: EditorId, _line: usize) -> Style

Source

fn stretch(&self, _edid: EditorId, _line: usize) -> Stretch

Source

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.

Source

fn tab_width(&self, _edid: EditorId, _line: usize) -> usize

Source

fn atomic_soft_tabs(&self, _edid: EditorId, _line: usize) -> bool

Whether the cursor should treat leading soft tabs as if they are hard tabs

Source

fn apply_attr_styles( &self, _edid: EditorId, _style: &EditorStyle, _line: usize, _default: Attrs<'_>, _attrs: &mut AttrsList, )

Apply custom attribute styles to the line

Source

fn apply_layout_styles( &self, _edid: EditorId, _style: &EditorStyle, _line: usize, _layout_line: &mut TextLayoutLine, )

Source

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.

Implementors§