mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-11 22:50:08 +00:00
added rest of baseline alignment options
This commit is contained in:
@@ -282,7 +282,7 @@ pub struct FormattedText {
|
||||
/// [`VerticalAlignment::Bottom`] is used, this way the baseline is anchored to the bottom of the
|
||||
/// line. [`VerticalAlignment::Center`] can be used to center glyphs relative to the line bounds.
|
||||
#[visit(optional)]
|
||||
vertical_baseline_alignment: InheritableVariable<VerticalAlignment>,
|
||||
baseline_alignment: InheritableVariable<VerticalAlignment>,
|
||||
#[reflect(hidden)]
|
||||
brush: InheritableVariable<Brush>,
|
||||
#[visit(skip)]
|
||||
@@ -1132,10 +1132,10 @@ impl FormattedText {
|
||||
let mut y: f32 = cursor_y_start.floor();
|
||||
for line in lines.iter_mut() {
|
||||
let mut x = line.x_offset.floor();
|
||||
// TODO. Add the rest of alignments.
|
||||
let base_line = match *self.vertical_baseline_alignment {
|
||||
let base_line = match *self.baseline_alignment {
|
||||
VerticalAlignment::Center => y + line.height * 0.5,
|
||||
_ => y + line.height,
|
||||
VerticalAlignment::Top => y,
|
||||
VerticalAlignment::Stretch | VerticalAlignment::Bottom => y + line.height,
|
||||
};
|
||||
if let Some(mask) = *self.mask_char {
|
||||
let mut prev = None;
|
||||
@@ -1185,10 +1185,12 @@ impl FormattedText {
|
||||
_ => {
|
||||
// Then the glyph.
|
||||
let mut y1 = base_line;
|
||||
// TODO. Add the rest of alignments.
|
||||
match *self.vertical_baseline_alignment {
|
||||
match *self.baseline_alignment {
|
||||
VerticalAlignment::Center => y1 -= metrics.ascender() * 0.5,
|
||||
_ => y1 -= metrics.ascender(),
|
||||
VerticalAlignment::Top => (),
|
||||
VerticalAlignment::Bottom | VerticalAlignment::Stretch => {
|
||||
y1 -= metrics.ascender()
|
||||
}
|
||||
}
|
||||
let scale = self.super_sampling_scale;
|
||||
let (glyph, advance) =
|
||||
@@ -1234,7 +1236,7 @@ pub struct FormattedTextBuilder {
|
||||
constraint: Vector2<f32>,
|
||||
text: Vec<char>,
|
||||
vertical_alignment: VerticalAlignment,
|
||||
vertical_baseline_alignment: VerticalAlignment,
|
||||
baseline_alignment: VerticalAlignment,
|
||||
horizontal_alignment: HorizontalAlignment,
|
||||
wrap: WrapMode,
|
||||
mask_char: Option<char>,
|
||||
@@ -1261,7 +1263,7 @@ impl FormattedTextBuilder {
|
||||
text: Vec::default(),
|
||||
horizontal_alignment: HorizontalAlignment::Left,
|
||||
vertical_alignment: VerticalAlignment::Top,
|
||||
vertical_baseline_alignment: VerticalAlignment::Bottom,
|
||||
baseline_alignment: VerticalAlignment::Bottom,
|
||||
brush: Brush::Solid(Color::WHITE),
|
||||
constraint: Vector2::new(128.0, 128.0),
|
||||
wrap: WrapMode::NoWrap,
|
||||
@@ -1285,11 +1287,8 @@ impl FormattedTextBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_vertical_baseline_alignment(
|
||||
mut self,
|
||||
vertical_baseline_alignment: VerticalAlignment,
|
||||
) -> Self {
|
||||
self.vertical_baseline_alignment = vertical_baseline_alignment;
|
||||
pub fn with_baseline_alignment(mut self, baseline_alignment: VerticalAlignment) -> Self {
|
||||
self.baseline_alignment = baseline_alignment;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -1417,7 +1416,7 @@ impl FormattedTextBuilder {
|
||||
glyphs: Vec::new(),
|
||||
vertical_alignment: self.vertical_alignment.into(),
|
||||
horizontal_alignment: self.horizontal_alignment.into(),
|
||||
vertical_baseline_alignment: self.vertical_baseline_alignment.into(),
|
||||
baseline_alignment: self.baseline_alignment.into(),
|
||||
brush: self.brush.into(),
|
||||
constraint: self.constraint,
|
||||
wrap: self.wrap.into(),
|
||||
|
||||
@@ -563,7 +563,7 @@ pub struct TextBuilder {
|
||||
text: Option<String>,
|
||||
font: Option<FontResource>,
|
||||
vertical_text_alignment: VerticalAlignment,
|
||||
vertical_baseline_alignment: VerticalAlignment,
|
||||
baseline_alignment: VerticalAlignment,
|
||||
horizontal_text_alignment: HorizontalAlignment,
|
||||
wrap: WrapMode,
|
||||
shadow: bool,
|
||||
@@ -584,7 +584,7 @@ impl TextBuilder {
|
||||
text: None,
|
||||
font: None,
|
||||
vertical_text_alignment: VerticalAlignment::Top,
|
||||
vertical_baseline_alignment: VerticalAlignment::Bottom,
|
||||
baseline_alignment: VerticalAlignment::Bottom,
|
||||
horizontal_text_alignment: HorizontalAlignment::Left,
|
||||
wrap: WrapMode::NoWrap,
|
||||
shadow: false,
|
||||
@@ -629,11 +629,10 @@ impl TextBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_vertical_baseline_alignment(
|
||||
mut self,
|
||||
vertical_baseline_alignment: VerticalAlignment,
|
||||
) -> Self {
|
||||
self.vertical_baseline_alignment = vertical_baseline_alignment;
|
||||
/// Sets the desired baseline alignment. Baseline alignment defines how the glyphs will be aligned
|
||||
/// in each line of the text.
|
||||
pub fn with_baseline_alignment(mut self, baseline_alignment: VerticalAlignment) -> Self {
|
||||
self.baseline_alignment = baseline_alignment;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -732,7 +731,7 @@ impl TextBuilder {
|
||||
.with_shadow_dilation(self.shadow_dilation)
|
||||
.with_shadow_offset(self.shadow_offset)
|
||||
.with_trim_text(self.trim_text)
|
||||
.with_vertical_baseline_alignment(self.vertical_baseline_alignment)
|
||||
.with_baseline_alignment(self.baseline_alignment)
|
||||
.with_font_size(
|
||||
self.font_size
|
||||
.unwrap_or_else(|| ctx.style.property(Style::FONT_SIZE)),
|
||||
|
||||
@@ -1572,7 +1572,7 @@ pub struct TextBoxBuilder<'a> {
|
||||
selection_brush: Brush,
|
||||
filter: Option<TextBoxFilter>,
|
||||
vertical_alignment: VerticalAlignment,
|
||||
vertical_baseline_alignment: VerticalAlignment,
|
||||
baseline_alignment: VerticalAlignment,
|
||||
horizontal_alignment: HorizontalAlignment,
|
||||
wrap: WrapMode,
|
||||
commit_mode: TextCommitMode,
|
||||
@@ -1602,7 +1602,7 @@ impl<'a> TextBoxBuilder<'a> {
|
||||
selection_brush: Brush::Solid(Color::opaque(80, 118, 178)),
|
||||
filter: None,
|
||||
vertical_alignment: VerticalAlignment::Top,
|
||||
vertical_baseline_alignment: VerticalAlignment::Bottom,
|
||||
baseline_alignment: VerticalAlignment::Bottom,
|
||||
horizontal_alignment: HorizontalAlignment::Left,
|
||||
wrap: WrapMode::NoWrap,
|
||||
commit_mode: TextCommitMode::LostFocusPlusEnter,
|
||||
@@ -1669,11 +1669,10 @@ impl<'a> TextBoxBuilder<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_vertical_baseline_alignment(
|
||||
mut self,
|
||||
vertical_baseline_alignment: VerticalAlignment,
|
||||
) -> Self {
|
||||
self.vertical_baseline_alignment = vertical_baseline_alignment;
|
||||
/// Sets the desired baseline alignment. Baseline alignment defines how the glyphs will be aligned
|
||||
/// in each line of the text.
|
||||
pub fn with_baseline_alignment(mut self, baseline_alignment: VerticalAlignment) -> Self {
|
||||
self.baseline_alignment = baseline_alignment;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -1817,7 +1816,7 @@ impl<'a> TextBoxBuilder<'a> {
|
||||
.with_shadow_offset(self.shadow_offset)
|
||||
.with_padding(self.padding)
|
||||
.with_trim_text(self.trim_text)
|
||||
.with_vertical_baseline_alignment(self.vertical_baseline_alignment)
|
||||
.with_baseline_alignment(self.baseline_alignment)
|
||||
.with_font_size(
|
||||
self.font_size
|
||||
.unwrap_or_else(|| ctx.style.property(Style::FONT_SIZE)),
|
||||
|
||||
Reference in New Issue
Block a user