1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 07:03:14 -04:00

Change default text alignment to Center

This commit is contained in:
Emil Ernerfeldt
2024-09-17 10:43:27 +02:00
parent f4ed394a85
commit 74b8d669c0
4 changed files with 18 additions and 3 deletions

View File

@@ -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

View File

@@ -648,7 +648,7 @@ impl WidgetText {
available_width: f32,
fallback_font: impl Into<FontSelection>,
) -> Arc<Galley> {
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());

View File

@@ -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);

View File

@@ -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,
}
}
}