mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 23:37:56 +03:00
feat: render an error underline on text
This commit is contained in:
parent
5e5446ef51
commit
278bed1214
@ -5,7 +5,7 @@ use crate::graphics::primitives::text as gr_text;
|
||||
use cgmath::Vector2;
|
||||
use roc_code_markup::markup::nodes::{MarkupNode, BLANK_PLACEHOLDER};
|
||||
use roc_code_markup::slow_pool::{MarkNodeId, SlowPool};
|
||||
use roc_code_markup::syntax_highlight::HighlightStyle;
|
||||
use roc_code_markup::{syntax_highlight::HighlightStyle, underline_style::UnderlineStyle};
|
||||
use winit::dpi::PhysicalSize;
|
||||
|
||||
use crate::{editor::config::Config, graphics::colors};
|
||||
@ -94,6 +94,9 @@ fn markup_to_wgpu_helper<'a>(
|
||||
txt_row_col: &mut (usize, usize),
|
||||
mark_node_pool: &'a SlowPool,
|
||||
) -> EdResult<()> {
|
||||
let char_width = code_style.glyph_dim_rect.width;
|
||||
let char_height = code_style.glyph_dim_rect.height;
|
||||
|
||||
match markup_node {
|
||||
MarkupNode::Nested {
|
||||
ast_node_id: _,
|
||||
@ -132,10 +135,15 @@ fn markup_to_wgpu_helper<'a>(
|
||||
|
||||
let full_content = markup_node.get_full_content().replace("\n", "\\n"); // any \n left here should be escaped so that it can be shown as \n
|
||||
|
||||
let glyph_text = glyph_brush::OwnedText::new(full_content)
|
||||
let glyph_text = glyph_brush::OwnedText::new(&full_content)
|
||||
.with_color(colors::to_slice(*highlight_color))
|
||||
.with_scale(code_style.font_size);
|
||||
|
||||
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,
|
||||
);
|
||||
|
||||
txt_row_col.1 += content.len();
|
||||
|
||||
for _ in 0..*newlines_at_end {
|
||||
@ -144,6 +152,19 @@ fn markup_to_wgpu_helper<'a>(
|
||||
}
|
||||
|
||||
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 {
|
||||
ast_node_id: _,
|
||||
@ -160,9 +181,6 @@ fn markup_to_wgpu_helper<'a>(
|
||||
let highlight_color =
|
||||
map_get(&code_style.ed_theme.syntax_high_map, &HighlightStyle::Blank)?;
|
||||
|
||||
let char_width = code_style.glyph_dim_rect.width;
|
||||
let char_height = code_style.glyph_dim_rect.height;
|
||||
|
||||
let blank_rect = Rect {
|
||||
top_left_coords: (
|
||||
code_style.txt_coords.x + (txt_row_col.1 as f32) * char_width,
|
||||
|
Loading…
Reference in New Issue
Block a user