mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 02:48:12 +08:00
Add text last-line alignment modes for "Justify Center", "Justify Right", and "Justify All" (#4024)
* feat: Add justify proper alignments(right/left/centre/all) * chore: fmt * chore: refactor * Cleanup * Fix crash when changing selected layer's alignment from the Text tool control bar --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Keavon Chambers
parent
1c2ac19b16
commit
c0a8241f50
@@ -31,21 +31,37 @@ pub use vector_types;
|
||||
#[widget(Radio)]
|
||||
pub enum TextAlign {
|
||||
#[default]
|
||||
Left,
|
||||
Center,
|
||||
Right,
|
||||
#[label("Justify")]
|
||||
AlignLeft,
|
||||
AlignCenter,
|
||||
AlignRight,
|
||||
JustifyLeft,
|
||||
// TODO: JustifyCenter, JustifyRight, JustifyAll
|
||||
JustifyCenter,
|
||||
JustifyRight,
|
||||
JustifyAll,
|
||||
}
|
||||
|
||||
impl From<TextAlign> for parley::Alignment {
|
||||
fn from(val: TextAlign) -> Self {
|
||||
match val {
|
||||
TextAlign::Left => parley::Alignment::Left,
|
||||
TextAlign::Center => parley::Alignment::Center,
|
||||
TextAlign::Right => parley::Alignment::Right,
|
||||
TextAlign::JustifyLeft => parley::Alignment::Justify,
|
||||
TextAlign::AlignLeft => parley::Alignment::Left,
|
||||
TextAlign::AlignCenter => parley::Alignment::Center,
|
||||
TextAlign::AlignRight => parley::Alignment::Right,
|
||||
_ => parley::Alignment::Justify,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TextAlign {
|
||||
/// What `parley::Alignment` to apply as a post-correction to the last line of a paragraph, or `None` if parley's default already handles it.
|
||||
///
|
||||
/// `JustifyLeft` returns `None` because parley already left-aligns the last line of a `Justify` layout. The other justify modes need
|
||||
/// the last line shifted (`Center`/`Right`) or its inter-word spaces redistributed (`Justify` / `JustifyAll`).
|
||||
pub fn last_line_correction(self) -> Option<parley::Alignment> {
|
||||
match self {
|
||||
Self::JustifyCenter => Some(parley::Alignment::Center),
|
||||
Self::JustifyRight => Some(parley::Alignment::Right),
|
||||
Self::JustifyAll => Some(parley::Alignment::Justify),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user