add alignment option to Buffer::set_rich_text
This commit is contained in:
parent
c65f299e87
commit
0935f549ee
2 changed files with 19 additions and 7 deletions
|
|
@ -103,7 +103,7 @@ fn set_buffer_text<'a>(buffer: &mut BorrowedWithFontSystem<'a, Buffer>) {
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
buffer.set_rich_text(spans.iter().copied(), attrs, Shaping::Advanced);
|
buffer.set_rich_text(spans.iter().copied(), attrs, Shaping::Advanced, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ use core::{cmp, fmt};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Affinity, Attrs, AttrsList, BidiParagraphs, BorrowedWithFontSystem, BufferLine, Color, Cursor,
|
Affinity, Align, Attrs, AttrsList, BidiParagraphs, BorrowedWithFontSystem, BufferLine, Color,
|
||||||
FontSystem, LayoutCursor, LayoutGlyph, LayoutLine, LineEnding, LineIter, Motion, Scroll,
|
Cursor, FontSystem, LayoutCursor, LayoutGlyph, LayoutLine, LineEnding, LineIter, Motion,
|
||||||
ShapeBuffer, ShapeLine, Shaping, Wrap,
|
Scroll, ShapeBuffer, ShapeLine, Shaping, Wrap,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A line of visible text for rendering
|
/// A line of visible text for rendering
|
||||||
|
|
@ -714,6 +714,7 @@ impl Buffer {
|
||||||
/// ],
|
/// ],
|
||||||
/// attrs,
|
/// attrs,
|
||||||
/// Shaping::Advanced,
|
/// Shaping::Advanced,
|
||||||
|
/// None,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_rich_text<'r, 's, I>(
|
pub fn set_rich_text<'r, 's, I>(
|
||||||
|
|
@ -722,6 +723,7 @@ impl Buffer {
|
||||||
spans: I,
|
spans: I,
|
||||||
default_attrs: Attrs,
|
default_attrs: Attrs,
|
||||||
shaping: Shaping,
|
shaping: Shaping,
|
||||||
|
alignment: Option<Align>,
|
||||||
) where
|
) where
|
||||||
I: IntoIterator<Item = (&'s str, Attrs<'r>)>,
|
I: IntoIterator<Item = (&'s str, Attrs<'r>)>,
|
||||||
{
|
{
|
||||||
|
|
@ -842,6 +844,10 @@ impl Buffer {
|
||||||
// Discard excess lines now that we have reused as much of the existing allocations as possible.
|
// Discard excess lines now that we have reused as much of the existing allocations as possible.
|
||||||
self.lines.truncate(line_count);
|
self.lines.truncate(line_count);
|
||||||
|
|
||||||
|
self.lines.iter_mut().for_each(|line| {
|
||||||
|
line.set_align(alignment);
|
||||||
|
});
|
||||||
|
|
||||||
self.scroll = Scroll::default();
|
self.scroll = Scroll::default();
|
||||||
|
|
||||||
self.shape_until_scroll(font_system, false);
|
self.shape_until_scroll(font_system, false);
|
||||||
|
|
@ -1440,14 +1446,20 @@ impl<'a> BorrowedWithFontSystem<'a, Buffer> {
|
||||||
/// ],
|
/// ],
|
||||||
/// attrs,
|
/// attrs,
|
||||||
/// Shaping::Advanced,
|
/// Shaping::Advanced,
|
||||||
|
/// None,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_rich_text<'r, 's, I>(&mut self, spans: I, default_attrs: Attrs, shaping: Shaping)
|
pub fn set_rich_text<'r, 's, I>(
|
||||||
where
|
&mut self,
|
||||||
|
spans: I,
|
||||||
|
default_attrs: Attrs,
|
||||||
|
shaping: Shaping,
|
||||||
|
alignment: Option<Align>,
|
||||||
|
) where
|
||||||
I: IntoIterator<Item = (&'s str, Attrs<'r>)>,
|
I: IntoIterator<Item = (&'s str, Attrs<'r>)>,
|
||||||
{
|
{
|
||||||
self.inner
|
self.inner
|
||||||
.set_rich_text(self.font_system, spans, default_attrs, shaping);
|
.set_rich_text(self.font_system, spans, default_attrs, shaping, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply a [`Motion`] to a [`Cursor`]
|
/// Apply a [`Motion`] to a [`Cursor`]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue