feat: only render unline if attribute is there

This commit is contained in:
rvcas 2022-02-25 13:02:35 -05:00
parent 0853c0bdb7
commit 6e752645a6
No known key found for this signature in database
GPG key ID: C09B64E263F7D68C
2 changed files with 58 additions and 28 deletions

View file

@ -47,16 +47,28 @@ pub struct UnderlineEnd {
#[derive(Debug)] #[derive(Debug)]
pub enum Attribute { pub enum Attribute {
// Rust does not yet support types for enum variants so we have to do it like this // Rust does not yet support types for enum variants so we have to do it like this
Caret { caret: Caret }, Caret {
caret: Caret,
},
SelectionStart { selection_start: SelectionStart }, SelectionStart {
SelectionEnd { selection_end: SelectionEnd }, selection_start: SelectionStart,
},
SelectionEnd {
selection_end: SelectionEnd,
},
HighlightStart { highlight_start: HighlightStart }, HighlightStart {
HighlightEnd { highlight_end: HighlightEnd }, highlight_start: HighlightStart,
},
HighlightEnd {
highlight_end: HighlightEnd,
},
UnderlineStart { underline_start: UnderlineStart }, Underline {
UnderlineEnd { underline_end: UnderlineEnd }, underline_start: UnderlineStart,
underline_end: UnderlineEnd,
},
} }
#[derive(Debug, Default)] #[derive(Debug, Default)]

View file

@ -3,9 +3,15 @@ use crate::editor::{ed_error::EdResult, theme::EdTheme, util::map_get};
use crate::graphics::primitives::rect::Rect; use crate::graphics::primitives::rect::Rect;
use crate::graphics::primitives::text as gr_text; use crate::graphics::primitives::text as gr_text;
use cgmath::Vector2; use cgmath::Vector2;
use roc_code_markup::markup::nodes::{MarkupNode, BLANK_PLACEHOLDER}; use roc_code_markup::{
use roc_code_markup::slow_pool::{MarkNodeId, SlowPool}; markup::{
use roc_code_markup::{syntax_highlight::HighlightStyle, underline_style::UnderlineStyle}; attribute::Attribute,
nodes::{MarkupNode, BLANK_PLACEHOLDER},
},
slow_pool::{MarkNodeId, SlowPool},
syntax_highlight::HighlightStyle,
underline_style::UnderlineStyle,
};
use winit::dpi::PhysicalSize; use winit::dpi::PhysicalSize;
use crate::{editor::config::Config, graphics::colors}; use crate::{editor::config::Config, graphics::colors};
@ -127,7 +133,7 @@ fn markup_to_wgpu_helper<'a>(
content, content,
ast_node_id: _, ast_node_id: _,
syn_high_style, syn_high_style,
attributes: _, attributes,
parent_id_opt: _, parent_id_opt: _,
newlines_at_end, newlines_at_end,
} => { } => {
@ -139,10 +145,35 @@ fn markup_to_wgpu_helper<'a>(
.with_color(colors::to_slice(*highlight_color)) .with_color(colors::to_slice(*highlight_color))
.with_scale(code_style.font_size); .with_scale(code_style.font_size);
let top_left_coords = ( for attribute in &attributes.all {
code_style.txt_coords.x + (txt_row_col.1 as f32) * char_width, match attribute {
code_style.txt_coords.y + (txt_row_col.0 as f32) * char_height + 1.0 * char_height, Attribute::Underline {
); underline_start: _,
underline_end: _,
} => {
let top_left_coords = (
code_style.txt_coords.x + (txt_row_col.1 as f32) * char_width,
code_style.txt_coords.y
+ (txt_row_col.0 as f32) * char_height
+ 1.0 * char_height,
);
let underline_rect = Rect {
top_left_coords: top_left_coords.into(),
width: char_width * (full_content.len() as f32),
height: 5.0,
color: *code_style
.ed_theme
.underline_colors
.get(&UnderlineStyle::Error)
.unwrap(),
};
rects.push(underline_rect);
}
rest => todo!("handle Attribute: {:?}", rest),
}
}
txt_row_col.1 += content.len(); txt_row_col.1 += content.len();
@ -152,19 +183,6 @@ fn markup_to_wgpu_helper<'a>(
} }
wgpu_texts.push(glyph_text); wgpu_texts.push(glyph_text);
let underline_rect = Rect {
top_left_coords: top_left_coords.into(),
width: char_width * (full_content.len() as f32),
height: 5.0,
color: *code_style
.ed_theme
.underline_colors
.get(&UnderlineStyle::Error)
.unwrap(),
};
rects.push(underline_rect);
} }
MarkupNode::Blank { MarkupNode::Blank {
ast_node_id: _, ast_node_id: _,