refactor: group common render data into new type

This resolved the too-many-arguments linting error for the `draw_grapheme` function.
pull/11516/head
sunshine 3 months ago
parent 580d9d28f7
commit 545d2af71d

@ -238,17 +238,20 @@ pub fn render_text(
}; };
decorations.decorate_grapheme(renderer, &grapheme); decorations.decorate_grapheme(renderer, &grapheme);
let virt = grapheme.is_virtual(); let is_virtual = grapheme.is_virtual();
let is_selected = selection.is_some_and(|selection| { let is_selected = selection.is_some_and(|selection| {
selection selection
.iter() .iter()
.any(|range| range.contains(grapheme.char_idx)) .any(|range| range.contains(grapheme.char_idx))
}); });
let grapheme_render_data = GraphemeRenderData {
is_virtual,
is_selected,
};
let grapheme_width = renderer.draw_grapheme( let grapheme_width = renderer.draw_grapheme(
grapheme.raw, grapheme.raw,
grapheme_style, grapheme_style,
virt, grapheme_render_data,
is_selected,
&mut last_line_indent_level, &mut last_line_indent_level,
&mut is_in_indent_area, &mut is_in_indent_area,
grapheme.visual_pos, grapheme.visual_pos,
@ -280,6 +283,11 @@ pub struct GraphemeStyle {
overlay_style: Style, overlay_style: Style,
} }
pub struct GraphemeRenderData {
is_virtual: bool,
is_selected: bool,
}
impl<'a> TextRenderer<'a> { impl<'a> TextRenderer<'a> {
pub fn new( pub fn new(
surface: &'a mut Surface, surface: &'a mut Surface,
@ -365,8 +373,7 @@ impl<'a> TextRenderer<'a> {
&mut self, &mut self,
grapheme: Grapheme, grapheme: Grapheme,
grapheme_style: GraphemeStyle, grapheme_style: GraphemeStyle,
is_virtual: bool, grapheme_render_data: GraphemeRenderData,
is_selected: bool,
last_indent_level: &mut usize, last_indent_level: &mut usize,
is_in_indent_area: &mut bool, is_in_indent_area: &mut bool,
mut position: Position, mut position: Position,
@ -387,6 +394,10 @@ impl<'a> TextRenderer<'a> {
let width = grapheme.width(); let width = grapheme.width();
let GraphemeRenderData {
is_virtual,
is_selected,
} = grapheme_render_data;
let ws = &self.whitespace_entries; let ws = &self.whitespace_entries;
let tab = &ws.tab.render(is_virtual, is_selected); let tab = &ws.tab.render(is_virtual, is_selected);
let space = &ws.space.render(is_virtual, is_selected); let space = &ws.space.render(is_virtual, is_selected);

Loading…
Cancel
Save