Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing whitespace is not handled correctly #251

Open
wfdewith opened this issue Jan 23, 2025 · 0 comments
Open

Trailing whitespace is not handled correctly #251

wfdewith opened this issue Jan 23, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@wfdewith
Copy link
Contributor

wfdewith commented Jan 23, 2025

In my attempts to implement min_content_width and max_content_width, I ran into another issue.

I've written the following test:

#[test]
fn trailing_whitespace() {
    let mut env = testenv!();

    let text = "AAA   BBB";
    let mut builder = env.builder(text);
    let mut layout = builder.build(text);
    layout.break_all_lines(Some(45.));
    layout.align(None, Alignment::Start, false);
    println!("width = {}", layout.width());
    println!("full_width = {}", layout.full_width());
    for (i, line) in layout.lines().enumerate() {
        println!("line {}, trailing_whitespace = {}", i, line.metrics().trailing_whitespace);
    }
    env.check_layout_snapshot(&layout);
}

This prints and renders the following:

width = 43.195313
full_width = 43.195313
line 0, trailing_whitespace = 0
line 1, trailing_whitespace = 0

Image

(I added the grey block to make the actual layout width and height visible with the patch below.)

Patch

diff --git a/parley/src/tests/utils/renderer.rs b/parley/src/tests/utils/renderer.rs
index 2169eb7..a5d6736 100644
--- a/parley/src/tests/utils/renderer.rs
+++ b/parley/src/tests/utils/renderer.rs
@@ -61,6 +61,15 @@ pub(crate) fn render_layout(
 
     let mut pen = TinySkiaPen::new(img.as_mut());
 
+    draw_rect(
+        &mut pen,
+        fpadding,
+        fpadding,
+        width as f32,
+        height as f32,
+        Color::from_rgba8(220, 220, 220, 255),
+    );
+
     for rect in selection_rects {
         draw_rect(
             &mut pen,

I would expect that the full_width of this layout includes the whitespace, while the width does not. Additionally, I would expect the first line to have trailing_whitespace > 0 in its metrics.

@wfdewith wfdewith changed the title Trailing whitespace is not marked correctly Trailing whitespace is not handled correctly Jan 23, 2025
@nicoburns nicoburns added the bug Something isn't working label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants