diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index 3a75afb21..4693efea9 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -617,6 +617,14 @@ impl Ui { self.wrap_mode() == TextWrapMode::Wrap } + /// How to vertically align text + #[inline] + pub fn text_valign(&self) -> Align { + #![allow(clippy::unused_self)] + // We currently always center-align, because that makes emojis and text nice and centered everywhere. + Align::Center + } + /// Create a painter for a sub-region of this Ui. /// /// The clip-rect of the returned [`Painter`] will be the intersection diff --git a/crates/egui/src/widget_text.rs b/crates/egui/src/widget_text.rs index 29d59ff18..03b8cbb97 100644 --- a/crates/egui/src/widget_text.rs +++ b/crates/egui/src/widget_text.rs @@ -648,7 +648,7 @@ impl WidgetText { available_width: f32, fallback_font: impl Into, ) -> Arc { - let valign = ui.layout().vertical_align(); + let valign = ui.text_valign(); let style = ui.style(); let wrap_mode = wrap_mode.unwrap_or_else(|| ui.wrap_mode()); diff --git a/crates/egui/src/widgets/label.rs b/crates/egui/src/widgets/label.rs index 23ece9bbe..1119bc146 100644 --- a/crates/egui/src/widgets/label.rs +++ b/crates/egui/src/widgets/label.rs @@ -162,7 +162,7 @@ impl Label { return (pos, galley, response); } - let valign = ui.layout().vertical_align(); + let valign = ui.text_valign(); let mut layout_job = self .text .into_layout_job(ui.style(), FontSelection::Default, valign); diff --git a/crates/epaint/src/text/text_layout_types.rs b/crates/epaint/src/text/text_layout_types.rs index 2099e3cf6..f1f1359a8 100644 --- a/crates/epaint/src/text/text_layout_types.rs +++ b/crates/epaint/src/text/text_layout_types.rs @@ -279,6 +279,13 @@ pub struct TextFormat { /// If you use a small font and [`Align::TOP`] you /// can get the effect of raised text. + /// + /// If you use a small font and [`Align::BOTTOM`] + /// you get the effect of a subscript. + /// + /// If you use [`Align::center`], you get text that is centered + /// around a common center-line, which is nice when mixining emojis + /// and normal text in e.g. a button. pub valign: Align, // TODO(emilk): lowered } @@ -295,7 +302,7 @@ impl Default for TextFormat { italics: false, underline: Stroke::NONE, strikethrough: Stroke::NONE, - valign: Align::BOTTOM, + valign: Align::Center, } } }