Require default Attrs to be specified in set_rich_text
This commit is contained in:
parent
c1e40363ab
commit
ad10e7373b
2 changed files with 11 additions and 7 deletions
|
|
@ -119,7 +119,7 @@ fn main() {
|
||||||
|
|
||||||
editor
|
editor
|
||||||
.buffer_mut()
|
.buffer_mut()
|
||||||
.set_rich_text(spans.iter().copied(), Shaping::Advanced);
|
.set_rich_text(spans.iter().copied(), attrs, Shaping::Advanced);
|
||||||
|
|
||||||
let mut swash_cache = SwashCache::new();
|
let mut swash_cache = SwashCache::new();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -618,7 +618,7 @@ impl Buffer {
|
||||||
attrs: Attrs,
|
attrs: Attrs,
|
||||||
shaping: Shaping,
|
shaping: Shaping,
|
||||||
) {
|
) {
|
||||||
self.set_rich_text(font_system, [(text, attrs)], shaping);
|
self.set_rich_text(font_system, [(text, attrs)], attrs, shaping);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set text of buffer, using an iterator of styled spans (pairs of text and attributes)
|
/// Set text of buffer, using an iterator of styled spans (pairs of text and attributes)
|
||||||
|
|
@ -634,6 +634,7 @@ impl Buffer {
|
||||||
/// ("hello, ", attrs),
|
/// ("hello, ", attrs),
|
||||||
/// ("cosmic\ntext", attrs.family(Family::Monospace)),
|
/// ("cosmic\ntext", attrs.family(Family::Monospace)),
|
||||||
/// ],
|
/// ],
|
||||||
|
/// attrs,
|
||||||
/// Shaping::Advanced,
|
/// Shaping::Advanced,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
|
|
@ -641,13 +642,14 @@ impl Buffer {
|
||||||
&mut self,
|
&mut self,
|
||||||
font_system: &mut FontSystem,
|
font_system: &mut FontSystem,
|
||||||
spans: I,
|
spans: I,
|
||||||
|
default_attrs: Attrs,
|
||||||
shaping: Shaping,
|
shaping: Shaping,
|
||||||
) where
|
) where
|
||||||
I: IntoIterator<Item = (&'s str, Attrs<'r>)>,
|
I: IntoIterator<Item = (&'s str, Attrs<'r>)>,
|
||||||
{
|
{
|
||||||
self.lines.clear();
|
self.lines.clear();
|
||||||
|
|
||||||
let mut attrs_list = AttrsList::new(Attrs::new());
|
let mut attrs_list = AttrsList::new(default_attrs);
|
||||||
let mut line_string = String::new();
|
let mut line_string = String::new();
|
||||||
let mut end = 0;
|
let mut end = 0;
|
||||||
let (string, spans_data): (String, Vec<_>) = spans
|
let (string, spans_data): (String, Vec<_>) = spans
|
||||||
|
|
@ -676,7 +678,7 @@ impl Buffer {
|
||||||
// this is reached only if this text is empty
|
// this is reached only if this text is empty
|
||||||
self.lines.push(BufferLine::new(
|
self.lines.push(BufferLine::new(
|
||||||
String::new(),
|
String::new(),
|
||||||
AttrsList::new(Attrs::new()),
|
AttrsList::new(default_attrs),
|
||||||
shaping,
|
shaping,
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
|
|
@ -705,7 +707,7 @@ impl Buffer {
|
||||||
if maybe_line.is_some() {
|
if maybe_line.is_some() {
|
||||||
// finalize this line and start a new line
|
// finalize this line and start a new line
|
||||||
let prev_attrs_list =
|
let prev_attrs_list =
|
||||||
core::mem::replace(&mut attrs_list, AttrsList::new(Attrs::new()));
|
core::mem::replace(&mut attrs_list, AttrsList::new(default_attrs));
|
||||||
let prev_line_string = core::mem::take(&mut line_string);
|
let prev_line_string = core::mem::take(&mut line_string);
|
||||||
let buffer_line = BufferLine::new(prev_line_string, prev_attrs_list, shaping);
|
let buffer_line = BufferLine::new(prev_line_string, prev_attrs_list, shaping);
|
||||||
self.lines.push(buffer_line);
|
self.lines.push(buffer_line);
|
||||||
|
|
@ -941,14 +943,16 @@ impl<'a> BorrowedWithFontSystem<'a, Buffer> {
|
||||||
/// ("hello, ", attrs),
|
/// ("hello, ", attrs),
|
||||||
/// ("cosmic\ntext", attrs.family(Family::Monospace)),
|
/// ("cosmic\ntext", attrs.family(Family::Monospace)),
|
||||||
/// ],
|
/// ],
|
||||||
|
/// attrs,
|
||||||
/// Shaping::Advanced,
|
/// Shaping::Advanced,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_rich_text<'r, 's, I>(&mut self, spans: I, shaping: Shaping)
|
pub fn set_rich_text<'r, 's, I>(&mut self, spans: I, default_attrs: Attrs, shaping: Shaping)
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = (&'s str, Attrs<'r>)>,
|
I: IntoIterator<Item = (&'s str, Attrs<'r>)>,
|
||||||
{
|
{
|
||||||
self.inner.set_rich_text(self.font_system, spans, shaping);
|
self.inner
|
||||||
|
.set_rich_text(self.font_system, spans, default_attrs, shaping);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw the buffer
|
/// Draw the buffer
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue