Alignment is based on text direction by default now

This commit is contained in:
Hojjat 2023-02-23 13:45:34 -07:00
parent 27d52a12e9
commit 4e7e1cc79e
2 changed files with 11 additions and 11 deletions

View file

@ -303,7 +303,7 @@ pub struct Buffer<'a> {
/// True if a redraw is requires. Set to false after processing /// True if a redraw is requires. Set to false after processing
redraw: bool, redraw: bool,
wrap: Wrap, wrap: Wrap,
align: Align, align: Option<Align>,
} }
impl<'a> Buffer<'a> { impl<'a> Buffer<'a> {
@ -320,7 +320,7 @@ impl<'a> Buffer<'a> {
scroll: 0, scroll: 0,
redraw: false, redraw: false,
wrap: Wrap::Word, wrap: Wrap::Word,
align: Align::Justified, align: None,
}; };
buffer.set_text("", Attrs::new()); buffer.set_text("", Attrs::new());
buffer buffer
@ -523,14 +523,14 @@ impl<'a> Buffer<'a> {
} }
/// Get the current [`Align`] /// Get the current [`Align`]
pub fn align(&self) -> Align { pub fn align(&self) -> Option<Align> {
self.align self.align
} }
/// Set the current [`Wrap`] /// Set the current [`Wrap`]
pub fn set_align(&mut self, align: Align) { pub fn set_align(&mut self, align: Align) {
if align != self.align { if Some(align) != self.align {
self.align = align; self.align = Some(align);
self.relayout(); self.relayout();
self.shape_until_scroll(); self.shape_until_scroll();
} }

View file

@ -9,7 +9,7 @@ pub struct BufferLine {
text: String, text: String,
attrs_list: AttrsList, attrs_list: AttrsList,
wrap: Wrap, wrap: Wrap,
align: Align, align: Option<Align>,
shape_opt: Option<ShapeLine>, shape_opt: Option<ShapeLine>,
layout_opt: Option<Vec<LayoutLine>>, layout_opt: Option<Vec<LayoutLine>>,
} }
@ -23,7 +23,7 @@ impl BufferLine {
text: text.into(), text: text.into(),
attrs_list, attrs_list,
wrap: Wrap::Word, wrap: Wrap::Word,
align: Align::Left, align: None,
shape_opt: None, shape_opt: None,
layout_opt: None, layout_opt: None,
} }
@ -97,7 +97,7 @@ impl BufferLine {
} }
/// Get the Text alignment /// Get the Text alignment
pub fn align(&self) -> Align { pub fn align(&self) -> Option<Align> {
self.align self.align
} }
@ -106,8 +106,8 @@ impl BufferLine {
/// Will reset shape and layout if it differs from current alignment. /// Will reset shape and layout if it differs from current alignment.
/// Returns true if the line was reset /// Returns true if the line was reset
pub fn set_align(&mut self, align: Align) -> bool { pub fn set_align(&mut self, align: Align) -> bool {
if align != self.align { if Some(align) != self.align {
self.align = align; self.align = Some(align);
self.reset(); self.reset();
true true
} else { } else {
@ -186,7 +186,7 @@ impl BufferLine {
font_size: i32, font_size: i32,
width: i32, width: i32,
wrap: Wrap, wrap: Wrap,
align: Align, align: Option<Align>,
) -> &[LayoutLine] { ) -> &[LayoutLine] {
if self.layout_opt.is_none() { if self.layout_opt.is_none() {
self.wrap = wrap; self.wrap = wrap;