grovesNL / glyphon

🦅🦁 Fast, simple 2D text renderer for wgpu
429 stars 53 forks source link

TextArea::scale Breaks Cosmic Text Alignment #117

Open 12AT7 opened 4 days ago

12AT7 commented 4 days ago

When using alignment such as this:

    buffer.lines[0].set_align(Some(glyphon::cosmic_text::Align::Center));

With configuration like this:

     Some(glyphon::TextArea {
                buffer,
                left: bounds.location.x,
                top: bounds.location.y,
                scale: scale_factor,
                bounds: glyphon::TextBounds {
                    top: bounds.location.y as i32,
                    left: bounds.location.x as i32,
                    right: (bounds.location.x + bounds.size.width) as i32,
                    bottom: (bounds.location.y + bounds.size.height) as i32,
                },
                default_color: glyphon::Color::rgb(255, 255, 255),
                custom_glyphs: &[]
            })

the handling of scale seems to be troublesome. On my HiDPI monitor, scale is 2.67. The parameter appears to affect at least two features:

  1. Font scaling; this appears to work for me, and I do get reasonable font sizes on HiDPI
  2. Horizontal alignment; this does not work for me. I think it is positioning the text way, way to the right and off the screen. I think that Left works just because it is probably zero * big number.

Maybe this is a bug? Or maybe I am missing a parameter somewhere else?

12AT7 commented 3 days ago

I am using this workaround:

glyphon::TextArea {
                ...
                scale: 1.0,
                ...
            }

and

    let scale_factor = window.scale_factor() as f32;
    let metrics = glyphon::Metrics::new(14.0 * scale_factor, 14.0 * scale_factor);
    let mut buffer =  glyphon::Buffer::new(&mut font_system, metrics);

and this does properly scale the font, and do alignment correctly.

grovesNL commented 2 days ago

Any help debugging this would be great. scale was added here before horizontal alignment was available in cosmic-text so there's a good chance there's a bug here somewhere.

12AT7 commented 20 hours ago

OK; I will keep my eyes open on this. In some aspects of Rust, I am still a newbie. Using a debugger is one of those areas where I need to learn more. Maybe this is a good reason to try.