From aa62fa2ce992949d20ddbe8683ed2be0d922a568 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 18 Jul 2024 13:22:53 +0200 Subject: Adapt `scrollable` sizing strategy to contents --- examples/markdown/src/main.rs | 11 ++++------- widget/src/scrollable.rs | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/examples/markdown/src/main.rs b/examples/markdown/src/main.rs index 384645fa..1e3769ff 100644 --- a/examples/markdown/src/main.rs +++ b/examples/markdown/src/main.rs @@ -60,13 +60,10 @@ impl Markdown { let preview = markdown(&self.items); - row![ - editor, - scrollable(preview).spacing(10).width(Fill).height(Fill) - ] - .spacing(10) - .padding(10) - .into() + row![editor, scrollable(preview).spacing(10).height(Fill)] + .spacing(10) + .padding(10) + .into() } fn theme(&self) -> Theme { diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index b1082203..6dd593cb 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -62,19 +62,27 @@ where .validate() } - fn validate(self) -> Self { + fn validate(mut self) -> Self { + let size_hint = self.content.as_widget().size_hint(); + debug_assert!( - self.direction.vertical().is_none() - || !self.content.as_widget().size_hint().height.is_fill(), + self.direction.vertical().is_none() || !size_hint.height.is_fill(), "scrollable content must not fill its vertical scrolling axis" ); debug_assert!( - self.direction.horizontal().is_none() - || !self.content.as_widget().size_hint().width.is_fill(), + self.direction.horizontal().is_none() || !size_hint.width.is_fill(), "scrollable content must not fill its horizontal scrolling axis" ); + if self.direction.horizontal().is_none() { + self.width = self.width.enclose(size_hint.width); + } + + if self.direction.vertical().is_none() { + self.height = self.height.enclose(size_hint.height); + } + self } -- cgit