feat: buffer setter methods are now lazy
This commit is contained in:
parent
e5926aec74
commit
626f44dad8
14 changed files with 388 additions and 240 deletions
|
|
@ -149,7 +149,6 @@ impl DrawTestCfg {
|
|||
self.alignment,
|
||||
);
|
||||
}
|
||||
buffer.shape_until_scroll(true);
|
||||
|
||||
// Black
|
||||
let text_color = Color::rgb(0x00, 0x00, 0x00);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ fn empty_lines_use_span_metrics() {
|
|||
None,
|
||||
);
|
||||
buffer.set_size(Some(500.0), Some(500.0));
|
||||
buffer.shape_until_scroll(false);
|
||||
|
||||
let line_heights: Vec<f32> = buffer.layout_runs().map(|run| run.line_height).collect();
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ fn test_ligature_segmentation() {
|
|||
let mut buffer = buffer.borrow_with(&mut font_system);
|
||||
|
||||
buffer.set_text("|>", &Attrs::new(), Shaping::Advanced, None);
|
||||
buffer.shape_until_scroll(false);
|
||||
let _ = buffer.layout_runs();
|
||||
|
||||
let line = &buffer.lines[0];
|
||||
let shape = line.shape_opt().expect("ShapeLine not found");
|
||||
|
|
@ -105,7 +105,7 @@ fn test_ligature_segmentation() {
|
|||
|
||||
// Test -> (Arrow), which is a common ligature.
|
||||
buffer.set_text("->", &Attrs::new(), Shaping::Advanced, None);
|
||||
buffer.shape_until_scroll(false);
|
||||
let _ = buffer.layout_runs();
|
||||
let line = &buffer.lines[0];
|
||||
let shape = line.shape_opt().expect("ShapeLine not found");
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ fn test_ligature_segmentation() {
|
|||
|
||||
// Test !=
|
||||
buffer.set_text("!=", &Attrs::new(), Shaping::Advanced, None);
|
||||
buffer.shape_until_scroll(false);
|
||||
let _ = buffer.layout_runs();
|
||||
let line = &buffer.lines[0];
|
||||
let shape = line.shape_opt().expect("ShapeLine not found");
|
||||
// Inter has a contextual alternate for != too.
|
||||
|
|
@ -131,7 +131,7 @@ fn test_ligature_segmentation() {
|
|||
|
||||
// Test ++
|
||||
buffer.set_text("++", &Attrs::new(), Shaping::Advanced, None);
|
||||
buffer.shape_until_scroll(false);
|
||||
let _ = buffer.layout_runs();
|
||||
let line = &buffer.lines[0];
|
||||
let shape = line.shape_opt().expect("ShapeLine not found");
|
||||
// Inter does not have a ++ ligature.
|
||||
|
|
|
|||
|
|
@ -117,15 +117,10 @@ fn wrap_extra_line() {
|
|||
|
||||
let mut buffer = buffer.borrow_with(&mut font_system);
|
||||
|
||||
// Add some text!
|
||||
// Configure wrap and size, then add text
|
||||
buffer.set_wrap(Wrap::Word);
|
||||
buffer.set_text("Lorem ipsum dolor sit amet, qui minim labore adipisicing\n\nweeewoooo minim sint cillum sint consectetur cupidatat.", &Attrs::new().family(cosmic_text::Family::Name("Inter")), Shaping::Advanced, None);
|
||||
|
||||
// Set a size for the text buffer, in pixels
|
||||
buffer.set_size(Some(50.0), Some(1000.0));
|
||||
|
||||
// Perform shaping as desired
|
||||
buffer.shape_until_scroll(false);
|
||||
buffer.set_text("Lorem ipsum dolor sit amet, qui minim labore adipisicing\n\nweeewoooo minim sint cillum sint consectetur cupidatat.", &Attrs::new().family(cosmic_text::Family::Name("Inter")), Shaping::Advanced, None);
|
||||
|
||||
let empty_lines = buffer.layout_runs().filter(|x| x.line_w == 0.).count();
|
||||
let overflow_lines = buffer.layout_runs().filter(|x| x.line_w > 50.).count();
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ fn wrap_word_fallback() {
|
|||
let mut buffer = buffer.borrow_with(&mut font_system);
|
||||
|
||||
buffer.set_wrap(Wrap::WordOrGlyph);
|
||||
buffer.set_text("Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.", &Attrs::new().family(cosmic_text::Family::Name("Inter")), Shaping::Advanced, None);
|
||||
buffer.set_size(Some(50.0), Some(1000.0));
|
||||
buffer.set_text("Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.", &Attrs::new().family(cosmic_text::Family::Name("Inter")), Shaping::Advanced, None);
|
||||
|
||||
buffer.shape_until_scroll(false);
|
||||
|
||||
let measured_size = measure(&buffer);
|
||||
let measured_size = buffer
|
||||
.layout_runs()
|
||||
.fold(0.0f32, |width, run| width.max(run.line_w));
|
||||
|
||||
assert!(
|
||||
measured_size <= buffer.size().0.unwrap_or(0.0),
|
||||
|
|
@ -29,9 +29,3 @@ fn wrap_word_fallback() {
|
|||
buffer.size().0.unwrap_or(0.0)
|
||||
);
|
||||
}
|
||||
|
||||
fn measure(buffer: &Buffer) -> f32 {
|
||||
buffer
|
||||
.layout_runs()
|
||||
.fold(0.0f32, |width, run| width.max(run.line_w))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue