diff --git a/Cargo.toml b/Cargo.toml index fb64861..e7b7c21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" bevy = {version="0.9.1", features = ["bevy_render", "bevy_core_pipeline", "bevy_asset", "bevy_sprite", "render", "bevy_winit", "png", "x11"], default-features=false } bevy_egui = "0.17.1" bevy_pancam = { version = "0.7.0", features = ["bevy_egui"] } -bevy_prototype_lyon = "0.7.1" +bevy_prototype_lyon = "0.7.2" colorgrad = "0.6.2" itertools = "0.10.5" fastrand = "1.8.0" diff --git a/src/aesthetics.rs b/src/aesthetics.rs index 9439080..da7e0ab 100644 --- a/src/aesthetics.rs +++ b/src/aesthetics.rs @@ -287,7 +287,7 @@ fn build_axes( transform.translation.y += arrow.direction.perp().y * away; transform }; - let mut axis_entry = axes + let axis_entry = axes .entry(arrow.id.clone()) .or_insert(HashMap::new()) .entry(geom.side.clone()) diff --git a/src/escher.rs b/src/escher.rs index 4c26e45..32f6090 100644 --- a/src/escher.rs +++ b/src/escher.rs @@ -448,6 +448,7 @@ pub fn load_map( let ori: Vec2 = Vec2::new(ori.x, -ori.y); let direction = my_map.main_direction(&reac); let mut products = reac.get_products(&my_map.metabolism); + let mut arrow_heads = ShapePath::new(); for (_, segment) in reac.segments.iter_mut() { if let (Some(from), Some(to)) = ( my_map.met_coords(&segment.from_node_id), @@ -480,10 +481,11 @@ pub fn load_map( if let Some((drawn, importance)) = products.get_mut(&segment.to_node_id) { if !*drawn { let offset = match importance { - MetImportance::Primary => 20.0, - MetImportance::Secondary => 12.0, + MetImportance::Primary => 22.0, + MetImportance::Secondary => 14.0, }; - draw_arrow(&mut path_builder, last_from - ori, re_to - ori, offset); + arrow_heads = + arrow_heads.add(&draw_arrow(last_from - ori, re_to - ori, offset)); *drawn = true; } } @@ -501,9 +503,11 @@ pub fn load_map( node_id, xlimits: None, }; + let mut builder = GeometryBuilder::new(); + builder = builder.add(&line); + builder = builder.add(&arrow_heads.build()); commands.spawn(( - GeometryBuilder::build_as( - &line, + builder.build( DrawMode::Stroke(StrokeMode::new(ARROW_COLOR, 10.0)), Transform::from_xyz(ori.x - center_x, ori.y + center_y, 1.), ), diff --git a/src/funcplot.rs b/src/funcplot.rs index 55ca57b..fa5ddb0 100644 --- a/src/funcplot.rs +++ b/src/funcplot.rs @@ -4,6 +4,7 @@ use bevy::prelude::{Color, Font, Handle, Text, Text2dBundle, TextStyle, Transfor use bevy_prototype_lyon::{ entity::ShapeBundle, prelude::{DrawMode, GeometryBuilder, Path, PathBuilder, StrokeMode}, + shapes, }; use colorgrad::{Color as GradColor, CustomGradient, Gradient}; @@ -365,24 +366,12 @@ pub fn build_grad( .expect("no gradient") } -fn arrow_head(from: Vec2, to: Vec2) -> (Vec2, Vec2) { - // triangle shape; hardcoded for now - const HEIGHT: f32 = 1.0; - const HALF_W: f32 = 14.0; - let u = (to - from) / (to - from).length(); - let v = Vec2::new(-u.y, u.x); - ( - (to - HEIGHT * u + HALF_W * v), - (to - HEIGHT * u - HALF_W * v), - ) -} - -pub fn draw_arrow(path: &mut PathBuilder, from: Vec2, to: Vec2, offset: f32) { +pub fn draw_arrow(from: Vec2, to: Vec2, offset: f32) -> shapes::Circle { // with an offset to avoid being hidden by metabolites let u = (to - from) / (to - from).length(); let to = to - offset * u; - let (left, right) = arrow_head(from, to); - path.move_to(right); - // path.line_to(to); - path.line_to(left); + shapes::Circle { + radius: 5.0, + center: to, + } } diff --git a/src/scale.rs b/src/scale.rs index ce93c72..e25f2b7 100644 --- a/src/scale.rs +++ b/src/scale.rs @@ -25,7 +25,7 @@ fn zoom_fonts( return; }; for (mut text, def) in text_query.iter_mut() { - for mut section in text.sections.iter_mut() { + for section in text.sections.iter_mut() { let new_font_size = lerp(proj.scale, 1., 40., def.size, def.size * 10.); // step update to enhance perfomance if (new_font_size - section.style.font_size).abs() > 1.0 {