resolved errors, but rects are invisible

This commit is contained in:
Anton-4 2021-03-13 13:41:05 +01:00
parent fdfdd80735
commit 4d3025786c
9 changed files with 66 additions and 65 deletions

View File

@ -59,13 +59,13 @@ pub fn print_err(err: &EdError) {
}
}
pub fn print_ui_err(err: &UIError) {
eprintln!("{}", format!("{}", err).truecolor(255, 0, 0));
// pub fn print_ui_err(err: &UIError) {
// eprintln!("{}", format!("{}", err).truecolor(255, 0, 0));
if let Some(backtrace) = ErrorCompat::backtrace(err) {
eprintln!("{}", color_backtrace(backtrace));
}
}
// if let Some(backtrace) = ErrorCompat::backtrace(err) {
// eprintln!("{}", color_backtrace(backtrace));
// }
// }
fn color_backtrace(backtrace: &snafu::Backtrace) -> String {
let backtrace_str = format!("{}", backtrace);

View File

@ -1,7 +1,7 @@
use super::keyboard_input;
use crate::editor::{
config::Config,
ed_error::{print_err, print_ui_err},
ed_error::{print_err},
mvc::{app_model::AppModel, app_update, ed_model},
theme::EdTheme,
};
@ -14,7 +14,6 @@ use crate::graphics::{
primitives::rect::Rect,
style::CODE_TXT_XY,
};
use crate::ui::{text::text_pos::TextPos, ui_error::UIResult};
use crate::editor::resources::strings::NOTHING_OPENED;
use super::util::slice_get;
use crate::lang::{pool::Pool};
@ -275,35 +274,26 @@ fn run_event_loop(file_path_opt: Option<&Path>) -> Result<(), Box<dyn Error>> {
let text_and_rects_res =
super::render_ast::expr2_to_wgpu(
&mut ed_model.markup_root,
ed_model,
&render_ast_arena,
&mut ed_model.module.env,
&ed_model.module.ast_root,
&size,
CODE_TXT_XY.into(),
&config,
ed_model.glyph_dim_rect_opt.unwrap() // TODO remove unwrap()
);
match text_and_rects_res {
Ok((text_section, rects)) => {
glyph_brush.queue(text_section);
match draw_all_rects(
draw_all_rects(
&rects,
&mut encoder,
&frame.view,
&gpu_device,
&rect_resources,
&ed_theme,
) {
Ok(()) => (),
Err(e) => {
print_ui_err(&e);
begin_render_pass(&mut encoder, &frame.view, &ed_theme);
}
}
)
},
Err(e) => print_err(&e)
}
@ -345,13 +335,13 @@ fn run_event_loop(file_path_opt: Option<&Path>) -> Result<(), Box<dyn Error>> {
}
fn draw_all_rects(
all_rects: &Vec<Rect>,
all_rects: &[Rect],
encoder: &mut CommandEncoder,
texture_view: &TextureView,
gpu_device: &wgpu::Device,
rect_resources: &RectResources,
ed_theme: &EdTheme,
) -> UIResult<()> {
) {
let rect_buffers = create_rect_buffers(gpu_device, encoder, all_rects);
// block necessary for borrowing encoder
@ -369,8 +359,6 @@ fn draw_all_rects(
}
begin_render_pass(encoder, texture_view, ed_theme);
Ok(())
}
fn begin_render_pass<'a>(
@ -394,40 +382,40 @@ fn begin_render_pass<'a>(
})
}
fn queue_editor_text(
size: &PhysicalSize<u32>,
editor_lines: &str,
caret_pos: TextPos,
config: &Config,
glyph_brush: &mut GlyphBrush<()>,
) {
let area_bounds = (size.width as f32, size.height as f32).into();
// fn queue_editor_text(
// size: &PhysicalSize<u32>,
// editor_lines: &str,
// caret_pos: TextPos,
// config: &Config,
// glyph_brush: &mut GlyphBrush<()>,
// ) {
// let area_bounds = (size.width as f32, size.height as f32).into();
let code_text = Text {
position: CODE_TXT_XY.into(),
area_bounds,
text: editor_lines,
size: config.code_font_size,
..Default::default()
};
// let code_text = Text {
// position: CODE_TXT_XY.into(),
// area_bounds,
// text: editor_lines,
// size: config.code_font_size,
// ..Default::default()
// };
let s = format!("Ln {}, Col {}", caret_pos.line, caret_pos.column);
let text = s.as_str();
// let s = format!("Ln {}, Col {}", caret_pos.line, caret_pos.column);
// let text = s.as_str();
let caret_pos_label = Text {
position: ((size.width as f32) - 150.0, (size.height as f32) - 40.0).into(),
area_bounds,
color: config.ed_theme.ui_theme.text,
text,
size: 25.0,
..Default::default()
};
// let caret_pos_label = Text {
// position: ((size.width as f32) - 150.0, (size.height as f32) - 40.0).into(),
// area_bounds,
// color: config.ed_theme.ui_theme.text,
// text,
// size: 25.0,
// ..Default::default()
// };
queue_text_draw(&caret_pos_label, glyph_brush);
// queue_text_draw(&caret_pos_label, glyph_brush);
// TODO convert to ast and render with render_ast::render_expr2
queue_text_draw(&code_text, glyph_brush);
}
// // TODO convert to ast and render with render_ast::render_expr2
// queue_text_draw(&code_text, glyph_brush);
// }
fn queue_no_file_text(
size: &PhysicalSize<u32>,

View File

@ -1,4 +1,4 @@
#![allow(dead_code)]
use super::syntax_highlight::HighlightStyle;
use bumpalo::Bump;
@ -25,6 +25,7 @@ pub enum MarkupNode {
}
}
#[derive(Debug)]
pub enum Attribute {
Caret {

View File

@ -1,3 +1,6 @@
#![allow(dead_code)]
use super::ed_model::EdModel;
use crate::editor::ed_error::{
print_err,

View File

@ -4,6 +4,7 @@ use crate::editor::{
util::map_get,
};
use super::markup::{MarkupNode, expr2_to_markup};
use super::mvc::ed_model::EdModel;
use crate::graphics::colors::RgbaTup;
use crate::graphics::primitives::text as gr_text;
use crate::graphics::primitives::rect::Rect;
@ -11,26 +12,26 @@ use bumpalo::Bump;
use cgmath::Vector2;
use std::collections::HashMap;
use winit::dpi::PhysicalSize;
use snafu::OptionExt;
use crate::ui::ui_error::{MissingGlyphDims};
use crate::{
editor::config::Config,
graphics::colors,
lang::{ast::Expr2, expr::Env},
};
pub fn expr2_to_wgpu<'a>(
markup_root: &'a mut MarkupNode,
ed_model: &'a mut EdModel,
arena: &'a Bump,
env: &mut Env<'a>,
expr2: &Expr2,
size: &PhysicalSize<u32>,
position: Vector2<f32>,
config: &Config,
glyph_dim_rect: Rect,
) -> EdResult<(wgpu_glyph::Section<'a>, Vec<Rect>)> {
*markup_root = expr2_to_markup(arena, env, expr2);
ed_model.markup_root = expr2_to_markup(arena, &mut ed_model.module.env, &ed_model.module.ast_root);
let glyph_dim_rect = ed_model.glyph_dim_rect_opt.context(MissingGlyphDims {})?;
build_code_graphics(markup_root, size, position, config, glyph_dim_rect)
build_code_graphics(&ed_model.markup_root, size, position, config, glyph_dim_rect)
}
pub fn build_code_graphics<'a>(
@ -109,8 +110,8 @@ fn markup_to_wgpu_helper<'a>(
let hole_rect = Rect {
top_left_coords: ((*text_row as f32) * glyph_dim_rect.height, (*text_col as f32) * glyph_dim_rect.width).into(),
width: glyph_dim_rect.width,
height: glyph_dim_rect.height,
width: glyph_dim_rect.width * 10.0,
height: glyph_dim_rect.height * 10.0,
color: colors::WHITE,
};
rects.push(hole_rect);

View File

@ -95,7 +95,7 @@ pub struct RectBuffers {
pub fn create_rect_buffers(
gpu_device: &wgpu::Device,
encoder: &mut wgpu::CommandEncoder,
rects: &Vec<Rect>,
rects: &[Rect],
) -> RectBuffers {
let nr_of_rects = rects.len() as u64;

View File

@ -1,5 +1,7 @@
// Adapted from https://github.com/cessen/ropey by Nathan Vegdahl, licensed under the MIT license
#![allow(dead_code)]
use crate::ui::text::{
caret_w_select::CaretWSelect,
lines::{Lines, MutSelectableLines, SelectableLines},

View File

@ -1,3 +1,6 @@
#![allow(dead_code)]
use super::selection::validate_selection;
use super::selection::Selection;
use super::text_pos::TextPos;

View File

@ -1,3 +1,6 @@
#![allow(dead_code)]
use super::lines::Lines;
use super::text_pos::TextPos;
use crate::ui::theme::UITheme;