Open Elinvynia opened 2 years ago
I came across your issue when I ran into similar problem. Was trying to get a label to always be 3 digits wide (using leading spaces) and horizontally centered on a row.
Here's a workaround I came up with that works for me:
// self.val is f32
let val_formatted = format!("{:>3}", self.val);
let text_size = WidgetText::from(val_formatted.clone())
.into_galley(ui, None, ui.available_width(), TextStyle::Monospace)
.size();
ui.allocate_ui_with_layout(text_size, Layout::right_to_left(), |ui| {
ui.label(RichText::new(val_formatted).monospace());
});
This seems like a bug in the text layout code!
FWIW, you can use the non-breaking space encoded \u{a0}
to get these examples to work. E.g.:
const NBSP: &str = "\u{a0}";
RichText::new("{NBSP}{NBSP}")
Is your feature request related to a problem? Please describe. I'm trying to align a cursor for menu entries.
Currently, the
else
condition never renders. There has to be an actual symbol besides just regular spaces. I'd prefer not to mess with the fonts as I like the default ones.Describe the solution you'd like If there is a space character it was most likely put there deliberately and thus should be rendered by default.
Describe alternatives you've considered Using a custom font with some space-equivalent-yet-renderable character.
Additional context I've tried looking into the source code but unfortunately couldn't figure out where the
is_empty
call is made that is causing this.