diff --git a/Cargo.lock b/Cargo.lock index 0e9ba36a9..7f81531c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -512,8 +512,6 @@ dependencies = [ [[package]] name = "femtovg" version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f95b1b0a3a4dc9bb7f866b2d6efc9c5c5f5bccefc21e40be75dfc2c12cb6ef8" dependencies = [ "bitflags", "fnv", @@ -920,6 +918,7 @@ dependencies = [ "console_error_panic_hook", "femtovg", "glutin", + "helix-view", "image", "instant", "resource", @@ -1406,9 +1405,9 @@ dependencies = [ [[package]] name = "ouroboros" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71643f290d126e18ac2598876d01e1d57aed164afc78fdb6e2a0c6589a1f6662" +checksum = "9f31a3b678685b150cba82b702dcdc5e155893f63610cf388d30cd988d4ca2bf" dependencies = [ "aliasable", "ouroboros_macro", @@ -1417,9 +1416,9 @@ dependencies = [ [[package]] name = "ouroboros_macro" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9a247206016d424fe8497bc611e510887af5c261fbbf977877c4bb55ca4d82" +checksum = "084fd65d5dd8b3772edccb5ffd1e4b7eba43897ecd0f9401e330e8c542959408" dependencies = [ "Inflector", "proc-macro-error", diff --git a/flake.nix b/flake.nix index bed09202b..2daedf6e7 100644 --- a/flake.nix +++ b/flake.nix @@ -58,7 +58,7 @@ { name = "HELIX_RUNTIME"; eval = "$PWD/runtime"; } { name = "RUST_BACKTRACE"; value = "1"; } # { name = "RUSTFLAGS"; value = "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment"; } - { name = "LD_LIBRARY_PATH"; value = nixpkgs.lib.makeLibraryPath (with common.pkgs; [ wayland libxkbcommon libGL ]); } + { name = "LD_LIBRARY_PATH"; value = nixpkgs.lib.makeLibraryPath (with common.pkgs; [ wayland libxkbcommon libGL xorg.libxcb ]); } ]; }; }; diff --git a/helix-ui/Cargo.toml b/helix-ui/Cargo.toml index 333195584..04c092e5e 100644 --- a/helix-ui/Cargo.toml +++ b/helix-ui/Cargo.toml @@ -6,7 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -femtovg = "0.3.3" +helix-view = { version = "0.6", path = "../helix-view", features = ["ui"] } +femtovg = { path = "../../femtovg" } winit = { version = "0.26.1", default-features = false, features = ["wayland"] } # TODO: figure out wayland-dlopen resource = "0.5.0" image = { version = "0.24.0", default-features = false, features = ["jpeg", "png"] } diff --git a/helix-ui/src/main.rs b/helix-ui/src/main.rs index e5945dca3..7945b6c23 100644 --- a/helix-ui/src/main.rs +++ b/helix-ui/src/main.rs @@ -21,9 +21,18 @@ use femtovg::{ Solidity, }; -// mezzopiano -// — -// 03/13/2022 +// new femto-like framework: +// wgpu renderer +// kurbo, (alternative is euclid + lyon) +// vector math: glam? and drop euclid (glam is faster https://docs.rs/glam/latest/glam/) +// swash + parley for text + +// imgref, bitflags +// fnv, rgb + +// resource, image +// usvg for svg + // I'm also assuming that there's some logic bugs in the demo application, which wasn't built with this in mind; I have a much simpler application that I'm happy to show if that would be helpful (would need to extract an example). As a rough solution, I apply the following transformation on Winit's WindowEvent::ScaleFactorChanged: // /* ... in an application struct/impl ... */ @@ -48,8 +57,6 @@ use femtovg::{ // ) // } -// With this, the canvas position and scale is preserved while the window is moved across screens, but as I'd like to apply further translations and keeping track of everything is getting very hard 😅 . I'm wondering if I'm making a mistake somewhere, or if there might be some way to do this in femto. - pub fn quantize(a: f32, d: f32) -> f32 { (a / d + 0.5).trunc() * d } @@ -57,6 +64,7 @@ pub fn quantize(a: f32, d: f32) -> f32 { struct Fonts { regular: FontId, bold: FontId, + code: FontId, icons: FontId, } @@ -120,11 +128,14 @@ fn main() { // TODO: better femtovg support for variable fonts let fonts = Fonts { regular: canvas - .add_font_mem(&resource!("assets/fonts/Inter\ Variable/Inter.ttf")) + .add_font_mem(&resource!("assets/fonts/Inter Variable/Inter.ttf")) .expect("Cannot add font"), bold: canvas .add_font_mem(&resource!("assets/fonts/Inter Variable/Inter.ttf")) .expect("Cannot add font"), + code: canvas + .add_font_mem(&resource!("assets/fonts/Fira Code/FiraCode-VF.ttf")) + .expect("Cannot add font"), icons: canvas .add_font_mem(&resource!("assets/entypo.ttf")) .expect("Cannot add font"), @@ -148,6 +159,10 @@ fn main() { let mut screenshot_image_id = None; + // + + // + let start = Instant::now(); let mut prevt = start; @@ -157,6 +172,14 @@ fn main() { let mut perf = PerfGraph::new(); + { + #[cfg(not(target_arch = "wasm32"))] + let window = windowed_context.window(); + let dpi_factor = window.scale_factor(); + canvas.set_size(0, 0, dpi_factor as f32); + canvas.reset(); + } + el.run(move |event, _, control_flow| { #[cfg(not(target_arch = "wasm32"))] let window = windowed_context.window(); @@ -168,9 +191,11 @@ fn main() { Event::WindowEvent { ref event, .. } => match event { #[cfg(not(target_arch = "wasm32"))] WindowEvent::Resized(physical_size) => { - println!("resized!"); - // TODO: use DPI here? windowed_context.resize(*physical_size); + + let dpi_factor = window.scale_factor(); + canvas.set_size(0, 0, dpi_factor as f32); + canvas.reset(); } WindowEvent::CursorMoved { device_id: _, @@ -178,48 +203,48 @@ fn main() { .. } => { if dragging { - let p0 = canvas - .transform() - .inversed() - .transform_point(mousex, mousey); - let p1 = canvas - .transform() - .inversed() - .transform_point(position.x as f32, position.y as f32); - - canvas.translate(p1.0 - p0.0, p1.1 - p0.1); + // let p0 = canvas + // .transform() + // .inversed() + // .transform_point(mousex, mousey); + // let p1 = canvas + // .transform() + // .inversed() + // .transform_point(position.x as f32, position.y as f32); + + // canvas.translate(p1.0 - p0.0, p1.1 - p0.1); } mousex = position.x as f32; mousey = position.y as f32; } - WindowEvent::MouseWheel { - device_id: _, - delta, - .. - } => match delta { - winit::event::MouseScrollDelta::LineDelta(_, y) => { - let pt = canvas - .transform() - .inversed() - .transform_point(mousex, mousey); - canvas.translate(pt.0, pt.1); - canvas.scale(1.0 + (y / 10.0), 1.0 + (y / 10.0)); - canvas.translate(-pt.0, -pt.1); - } - - winit::event::MouseScrollDelta::PixelDelta(pos) => { - let y = pos.y as f32; - let pt = canvas - .transform() - .inversed() - .transform_point(mousex, mousey); - let rate = 2000.0; - canvas.translate(pt.0, pt.1); - canvas.scale(1.0 + (y / rate), 1.0 + (y / rate)); - canvas.translate(-pt.0, -pt.1); - } - }, + // WindowEvent::MouseWheel { + // device_id: _, + // delta, + // .. + // } => match delta { + // winit::event::MouseScrollDelta::LineDelta(_, y) => { + // let pt = canvas + // .transform() + // .inversed() + // .transform_point(mousex, mousey); + // canvas.translate(pt.0, pt.1); + // canvas.scale(1.0 + (y / 10.0), 1.0 + (y / 10.0)); + // canvas.translate(-pt.0, -pt.1); + // } + + // winit::event::MouseScrollDelta::PixelDelta(pos) => { + // let y = pos.y as f32; + // let pt = canvas + // .transform() + // .inversed() + // .transform_point(mousex, mousey); + // let rate = 2000.0; + // canvas.translate(pt.0, pt.1); + // canvas.scale(1.0 + (y / rate), 1.0 + (y / rate)); + // canvas.translate(-pt.0, -pt.1); + // } + // }, WindowEvent::MouseInput { button: MouseButton::Left, state, @@ -291,6 +316,8 @@ fn main() { let rel_mousex = pt.0; let rel_mousey = pt.1; + draw_code(&mut canvas, fonts.code, 25.0, 500.0); + draw_paragraph( &mut canvas, fonts.regular, @@ -421,6 +448,22 @@ fn main() { }); } +fn draw_code(canvas: &mut Canvas, font: FontId, x: f32, y: f32) { + let text = "canvas.fill_text(x, y, &text[line_range], paint)"; + + canvas.save(); + + let mut paint = Paint::color(Color::rgba(255, 255, 255, 255)); + paint.set_font_size(14.0); + paint.set_font(&[font]); + paint.set_text_align(Align::Left); + paint.set_text_baseline(Baseline::Top); + + canvas.fill_text(x, y, text, paint).unwrap(); + + canvas.restore(); +} + fn draw_paragraph( canvas: &mut Canvas, font: FontId,