mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
feat(editor): render Expr2::Float
This commit is contained in:
parent
ab6890ce84
commit
ceefd535de
2 changed files with 67 additions and 38 deletions
|
@ -31,7 +31,7 @@ use crate::vec_result::get_res;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use cgmath::Vector2;
|
use cgmath::Vector2;
|
||||||
use ed_model::Position;
|
use ed_model::Position;
|
||||||
use lang::{ast::Expr2, pool::Pool, scope::Scope};
|
use lang::{pool::Pool, scope::Scope};
|
||||||
use pipelines::RectResources;
|
use pipelines::RectResources;
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
use roc_module::symbol::{IdentIds, ModuleIds};
|
use roc_module::symbol::{IdentIds, ModuleIds};
|
||||||
|
@ -57,6 +57,7 @@ mod resources;
|
||||||
mod selection;
|
mod selection;
|
||||||
mod text_buffer;
|
mod text_buffer;
|
||||||
//pub mod text_buffer; // for benchmarking
|
//pub mod text_buffer; // for benchmarking
|
||||||
|
mod render;
|
||||||
mod util;
|
mod util;
|
||||||
mod vec_result;
|
mod vec_result;
|
||||||
|
|
||||||
|
@ -298,11 +299,12 @@ fn run_event_loop(file_path_opt: Option<&Path>) -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
let region = Region::new(0, 0, 0, 0);
|
let region = Region::new(0, 0, 0, 0);
|
||||||
|
|
||||||
let (ast, _) =
|
let (expr2, _) = crate::lang::expr::str_to_expr2(
|
||||||
crate::lang::expr::str_to_expr2(&arena, "1", &mut env, &mut scope, region)
|
&arena, "2.0", &mut env, &mut scope, region,
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
render_node(&size, &ast, CODE_TXT_XY.into(), &mut glyph_brush);
|
render::render_expr2(&size, &expr2, CODE_TXT_XY.into(), &mut glyph_brush);
|
||||||
}
|
}
|
||||||
|
|
||||||
match draw_all_rects(
|
match draw_all_rects(
|
||||||
|
@ -401,39 +403,6 @@ fn begin_render_pass<'a>(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_node(
|
|
||||||
size: &PhysicalSize<u32>,
|
|
||||||
ast: &Expr2,
|
|
||||||
position: Vector2<f32>,
|
|
||||||
glyph_brush: &mut GlyphBrush<()>,
|
|
||||||
) {
|
|
||||||
use Expr2::*;
|
|
||||||
|
|
||||||
let area_bounds = (size.width as f32, size.height as f32).into();
|
|
||||||
|
|
||||||
match ast {
|
|
||||||
SmallInt {
|
|
||||||
number,
|
|
||||||
..
|
|
||||||
// text,
|
|
||||||
// style, pretending always decimal for now
|
|
||||||
// var,
|
|
||||||
} => {
|
|
||||||
let code_text = Text {
|
|
||||||
position,
|
|
||||||
area_bounds,
|
|
||||||
color: CODE_COLOR.into(),
|
|
||||||
text: format!("{:?}", number),
|
|
||||||
size: CODE_FONT_SIZE,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
queue_code_text_draw(&code_text, glyph_brush);
|
|
||||||
}
|
|
||||||
rest => panic!("implement {:?} render", rest)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns bounding boxes for every glyph
|
// returns bounding boxes for every glyph
|
||||||
fn queue_editor_text(
|
fn queue_editor_text(
|
||||||
size: &PhysicalSize<u32>,
|
size: &PhysicalSize<u32>,
|
||||||
|
|
60
editor/src/render.rs
Normal file
60
editor/src/render.rs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
use cgmath::Vector2;
|
||||||
|
use wgpu_glyph::GlyphBrush;
|
||||||
|
use winit::dpi::PhysicalSize;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
graphics::{
|
||||||
|
colors::CODE_COLOR,
|
||||||
|
primitives::text::{queue_code_text_draw, Text},
|
||||||
|
style::CODE_FONT_SIZE,
|
||||||
|
},
|
||||||
|
lang::ast::Expr2,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn render_expr2(
|
||||||
|
size: &PhysicalSize<u32>,
|
||||||
|
expr2: &Expr2,
|
||||||
|
position: Vector2<f32>,
|
||||||
|
glyph_brush: &mut GlyphBrush<()>,
|
||||||
|
) {
|
||||||
|
use Expr2::*;
|
||||||
|
|
||||||
|
let area_bounds = (size.width as f32, size.height as f32).into();
|
||||||
|
|
||||||
|
match expr2 {
|
||||||
|
SmallInt {
|
||||||
|
number,
|
||||||
|
..
|
||||||
|
// text,
|
||||||
|
// style, pretending always decimal for now
|
||||||
|
// var,
|
||||||
|
} => {
|
||||||
|
let code_text = Text {
|
||||||
|
position,
|
||||||
|
area_bounds,
|
||||||
|
color: CODE_COLOR.into(),
|
||||||
|
text: format!("{:?}", number),
|
||||||
|
size: CODE_FONT_SIZE,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
queue_code_text_draw(&code_text, glyph_brush);
|
||||||
|
}
|
||||||
|
Float {
|
||||||
|
number,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
let code_text = Text {
|
||||||
|
position,
|
||||||
|
area_bounds,
|
||||||
|
color: CODE_COLOR.into(),
|
||||||
|
text: format!("{:?}", number),
|
||||||
|
size: CODE_FONT_SIZE,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
queue_code_text_draw(&code_text, glyph_brush);
|
||||||
|
}
|
||||||
|
rest => panic!("implement {:?} render", rest)
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue