Avoid negative width/height in Buffer::set_size
Negative width/height may cause unexpected effects on the layout, which we can avoid by clamping.
This commit is contained in:
parent
a5903bb3bf
commit
be9b4cb36c
1 changed files with 6 additions and 3 deletions
|
|
@ -516,9 +516,12 @@ impl<'a> Buffer<'a> {
|
||||||
|
|
||||||
/// Set the current buffer dimensions
|
/// Set the current buffer dimensions
|
||||||
pub fn set_size(&mut self, width: i32, height: i32) {
|
pub fn set_size(&mut self, width: i32, height: i32) {
|
||||||
if width != self.width || height != self.height {
|
let clamped_width = width.max(0);
|
||||||
self.width = width;
|
let clamped_height = height.max(0);
|
||||||
self.height = height;
|
|
||||||
|
if clamped_width != self.width || clamped_height != self.height {
|
||||||
|
self.width = clamped_width;
|
||||||
|
self.height = clamped_height;
|
||||||
self.relayout();
|
self.relayout();
|
||||||
self.shape_until_scroll();
|
self.shape_until_scroll();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue