Allow for undefined buffer width and/or height, fixes #70

This commit is contained in:
Jeremy Soller 2024-06-12 09:04:04 -06:00
parent cd1cd0a337
commit 93a7df859a
15 changed files with 99 additions and 72 deletions

View file

@ -74,7 +74,7 @@ fn main() {
let mut buffer = Buffer::new(&mut font_system, font_sizes[font_size_default]);
buffer
.borrow_with(&mut font_system)
.set_size(window.width() as f32, window.height() as f32);
.set_size(Some(window.width() as f32), Some(window.height() as f32));
let mut editor = Editor::new(buffer);

View file

@ -110,8 +110,8 @@ fn main() {
editor.with_buffer_mut(|buffer| {
buffer.set_size(
width as f32 - scrollbar_width * display_scale,
height as f32,
Some(width as f32 - scrollbar_width * display_scale),
Some(height as f32),
)
});

View file

@ -102,7 +102,7 @@ fn main() {
// Set scroll to view scroll
buffer.set_scroll(*scroll);
// Set size, will relayout and shape until scroll if changed
buffer.set_size(width as f32, height as f32);
buffer.set_size(Some(width as f32), Some(height as f32));
// Shape until scroll, ensures scroll is clamped
//TODO: ability to prune with multiple views?
buffer.shape_until_scroll(true);
@ -154,10 +154,10 @@ fn main() {
scroll.vertical -= buffer.metrics().line_height;
}
Key::Named(NamedKey::PageDown) => {
scroll.vertical += buffer.size().1;
scroll.vertical += buffer.size().1.unwrap_or(0.0);
}
Key::Named(NamedKey::PageUp) => {
scroll.vertical -= buffer.size().1;
scroll.vertical -= buffer.size().1.unwrap_or(0.0);
}
_ => {}
}

View file

@ -122,8 +122,8 @@ fn main() {
let mut editor = editor.borrow_with(&mut font_system);
editor.with_buffer_mut(|buffer| {
buffer.set_size(
window.inner_size().width as f32,
window.inner_size().height as f32,
Some(window.inner_size().width as f32),
Some(window.inner_size().height as f32),
)
});
editor.with_buffer_mut(|buffer| set_buffer_text(buffer));
@ -182,7 +182,7 @@ fn main() {
pixmap.fill(bg_color);
editor.with_buffer_mut(|buffer| {
buffer.set_size(width as f32, height as f32)
buffer.set_size(Some(width as f32), Some(height as f32))
});
let mut paint = Paint::default();

View file

@ -26,8 +26,8 @@ fn main() {
// Set a size for the text buffer, in pixels
let width = 80.0;
let height = f32::MAX; // The height is unbounded
buffer.set_size(width, height);
// The height is unbounded
buffer.set_size(Some(width), None);
// Attributes indicate what font to choose
let attrs = Attrs::new();
@ -45,7 +45,6 @@ fn main() {
const TEXT_COLOR: Color = Color::rgb(0xFF, 0xFF, 0xFF);
// Set up the canvas
let width = buffer.size().0;
let height = LINE_HEIGHT * buffer.layout_runs().count() as f32;
let mut canvas = vec![vec![None; width as usize]; height as usize];