Use image renderer for iced text widget

This commit is contained in:
Jeremy Soller 2022-10-31 12:04:33 -06:00
parent b0ec548a5e
commit d49e8881fd
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
4 changed files with 74 additions and 58 deletions

View file

@ -148,14 +148,11 @@ impl<'a> BufferLine<'a> {
/// Layout line, will cache results
pub fn layout(&mut self, font_system: &'a FontSystem<'a>, font_size: i32, width: i32) -> &[LayoutLine] {
if self.layout_opt.is_none() {
let mut layout = Vec::new();
let wrap_simple = self.wrap_simple;
let shape = self.shape(font_system);
shape.layout(
let layout = shape.layout(
font_size,
width,
&mut layout,
0,
wrap_simple
);
self.layout_opt = Some(layout);

View file

@ -480,10 +480,10 @@ impl ShapeLine {
&self,
font_size: i32,
line_width: i32,
layout_lines: &mut Vec<LayoutLine>,
mut layout_i: usize,
wrap_simple: bool,
) {
) -> Vec<LayoutLine> {
let mut layout_lines = Vec::with_capacity(1);
let mut push_line = true;
let mut glyphs = Vec::new();
@ -593,13 +593,11 @@ impl ShapeLine {
if word_wrap && !wrap_simple && !glyphs.is_empty() {
let mut glyphs_swap = Vec::new();
std::mem::swap(&mut glyphs, &mut glyphs_swap);
layout_lines.insert(
layout_i,
layout_lines.push(
LayoutLine {
glyphs: glyphs_swap,
},
);
layout_i += 1;
x = start_x;
y = 0.0;
@ -619,13 +617,11 @@ impl ShapeLine {
if glyph_wrap {
let mut glyphs_swap = Vec::new();
std::mem::swap(&mut glyphs, &mut glyphs_swap);
layout_lines.insert(
layout_i,
layout_lines.push(
LayoutLine {
glyphs: glyphs_swap,
},
);
layout_i += 1;
x = start_x;
y = 0.0;
@ -648,13 +644,11 @@ impl ShapeLine {
if wrap {
let mut glyphs_swap = Vec::new();
std::mem::swap(&mut glyphs, &mut glyphs_swap);
layout_lines.insert(
layout_i,
layout_lines.push(
LayoutLine {
glyphs: glyphs_swap,
},
);
layout_i += 1;
x = start_x;
y = 0.0;
@ -663,12 +657,13 @@ impl ShapeLine {
}
if push_line {
layout_lines.insert(
layout_i,
layout_lines.push(
LayoutLine {
glyphs,
},
);
}
layout_lines
}
}