Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable width for Scrollable #1749

Merged
merged 2 commits into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions native/src/widget/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ where
Renderer::Theme: StyleSheet,
{
id: Option<Id>,
width: Length,
height: Length,
vertical: Properties,
horizontal: Option<Properties>,
Expand All @@ -50,6 +51,7 @@ where
pub fn new(content: impl Into<Element<'a, Message, Renderer>>) -> Self {
Scrollable {
id: None,
width: Length::Shrink,
height: Length::Shrink,
vertical: Properties::default(),
horizontal: None,
Expand All @@ -65,6 +67,12 @@ where
self
}

/// Sets the width of the [`Scrollable`].
pub fn width(mut self, width: impl Into<Length>) -> Self {
self.width = width.into();
self
}

/// Sets the height of the [`Scrollable`].
pub fn height(mut self, height: impl Into<Length>) -> Self {
self.height = height.into();
Expand Down Expand Up @@ -173,7 +181,7 @@ where
}

fn width(&self) -> Length {
self.content.as_widget().width()
self.width
}

fn height(&self) -> Length {
Expand All @@ -188,7 +196,7 @@ where
layout(
renderer,
limits,
Widget::<Message, Renderer>::width(self),
self.width,
self.height,
self.horizontal.is_some(),
|renderer, limits| {
Expand Down Expand Up @@ -397,15 +405,7 @@ pub fn layout<Renderer>(
horizontal_enabled: bool,
layout_content: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node,
) -> layout::Node {
let limits = limits
.max_height(f32::INFINITY)
.max_width(if horizontal_enabled {
f32::INFINITY
} else {
limits.max().width
})
.width(width)
.height(height);
let limits = limits.width(width).height(height);

let child_limits = layout::Limits::new(
Size::new(limits.min().width, 0.0),
Expand Down