Add alignment parameter to set_text (#419)
* add alignment parameter to set_text * Fix doc comment
This commit is contained in:
parent
750e1a4dd1
commit
3c1f6c9e8a
10 changed files with 30 additions and 11 deletions
|
|
@ -271,7 +271,7 @@ impl Buffer {
|
|||
/// Will panic if `metrics.line_height` is zero.
|
||||
pub fn new(font_system: &mut FontSystem, metrics: Metrics) -> Self {
|
||||
let mut buffer = Self::new_empty(metrics);
|
||||
buffer.set_text(font_system, "", &Attrs::new(), Shaping::Advanced);
|
||||
buffer.set_text(font_system, "", &Attrs::new(), Shaping::Advanced, None);
|
||||
buffer
|
||||
}
|
||||
|
||||
|
|
@ -679,6 +679,7 @@ impl Buffer {
|
|||
text: &str,
|
||||
attrs: &Attrs,
|
||||
shaping: Shaping,
|
||||
alignment: Option<Align>,
|
||||
) {
|
||||
self.lines.clear();
|
||||
for (range, ending) in LineIter::new(text) {
|
||||
|
|
@ -697,6 +698,13 @@ impl Buffer {
|
|||
shaping,
|
||||
));
|
||||
}
|
||||
|
||||
if alignment.is_some() {
|
||||
self.lines.iter_mut().for_each(|line| {
|
||||
line.set_align(alignment);
|
||||
});
|
||||
}
|
||||
|
||||
self.scroll = Scroll::default();
|
||||
self.shape_until_scroll(font_system, false);
|
||||
}
|
||||
|
|
@ -1424,8 +1432,15 @@ impl BorrowedWithFontSystem<'_, Buffer> {
|
|||
}
|
||||
|
||||
/// Set text of buffer, using provided attributes for each line by default
|
||||
pub fn set_text(&mut self, text: &str, attrs: &Attrs, shaping: Shaping) {
|
||||
self.inner.set_text(self.font_system, text, attrs, shaping);
|
||||
pub fn set_text(
|
||||
&mut self,
|
||||
text: &str,
|
||||
attrs: &Attrs,
|
||||
shaping: Shaping,
|
||||
alignment: Option<Align>,
|
||||
) {
|
||||
self.inner
|
||||
.set_text(self.font_system, text, attrs, shaping, alignment);
|
||||
}
|
||||
|
||||
/// Set text of buffer, using an iterator of styled spans (pairs of text and attributes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue