-
Notifications
You must be signed in to change notification settings - Fork 76
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
Vertically centered text appears too low #14
Comments
This is desirable for most use cases when you have dynamic text because it avoids awkward jumps. I am guessing the small difference that is still left depends entirely on the font. If you want to completely center the produced glyphs, you should be able to use |
Something like this: let mut section = Section {
text: "gŽ",
color: [0.0, 0.0, 0.0, 1.0],
scale: Scale::uniform(scale as f32),
bounds: (size.width as f32, size.height as f32),
..Section::default()
};
let pixel_bounds =
glyph_brush.pixel_bounds(section).expect("Pixel bounds");
section.screen_position = (
size.width as f32 * 0.5 - pixel_bounds.min.x as f32 * 0.5,
size.height as f32 * 0.5 - pixel_bounds.min.y as f32 * 0.5,
);
section.layout = Layout::default_single_line()
.h_align(HorizontalAlign::Center)
.v_align(VerticalAlign::Center);
glyph_brush.queue(section); Produces: It doesn't seem to be entirely centered still (?). |
Also, I am sure we could implement our own |
I was also imagining a centering strategy that did not depend dynamically on the particular glyphs. Maybe it's wrong to approach this with the expectation that the baseline of the text and the top of a capital letter are perfectly equidistant from the edges; I'm not an expert in text layout. Trying out a bunch of different fonts in a text box in Google Docs, the vertical alignment seems to depend a bit on the selected typeface. Overall I think it might make sense to close this issue, since it seems like |
The built-in I am not sure if fonts provide enough information to perform the alignment you describe, but |
I created an example here that illustrates. I would expect that the base of the text and the top of a capital letter are each the same distance from the vertical border of the window, but instead I observe that the base of the text is closer to the bottom of the window than the top of the capital is to the top of the window.
The text was updated successfully, but these errors were encountered: