feat: text-editor can shrink to content

This commit is contained in:
Dworv YT 2024-01-29 14:41:12 -08:00 committed by Héctor Ramón Jiménez
parent 5630febf96
commit 8b492a9b44
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -139,6 +139,17 @@ where
self.style = style.into();
self
}
/// Choose whether or not to shrink the size of the editor to its contents.
pub fn shrink_to_content(mut self, shrink: bool) -> Self {
if shrink {
self.height = Length::Shrink;
} else {
self.height = Length::Fill;
}
self
}
}
/// The content of a [`TextEditor`].
@ -360,7 +371,17 @@ where
state.highlighter.borrow_mut().deref_mut(),
);
layout::Node::new(limits.max())
if self.height == Length::Fill {
layout::Node::new(limits.max())
} else {
let lines_height = self
.line_height
.to_absolute(self.text_size.unwrap_or(renderer.default_size()))
.0
* internal.editor.line_count() as f32;
let height = lines_height + self.padding.top + self.padding.bottom;
layout::Node::new(limits.max_height(height).max())
}
}
fn on_event(