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

TextArea::scale Breaks Cosmic Text Alignment #117

Open
12AT7 opened this issue Oct 15, 2024 · 3 comments
Open

TextArea::scale Breaks Cosmic Text Alignment #117

12AT7 opened this issue Oct 15, 2024 · 3 comments

Comments

@12AT7
Copy link

12AT7 commented Oct 15, 2024

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
Copy link
Author

12AT7 commented Oct 17, 2024

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
Copy link
Owner

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
Copy link
Author

12AT7 commented Oct 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants