Force user to explicitly select a max height for a ScrollArea
This commit is contained in:
parent
5df9bfd514
commit
3d3b93da8b
3 changed files with 12 additions and 17 deletions
|
@ -33,22 +33,21 @@ pub struct ScrollArea {
|
|||
always_show_scroll: bool,
|
||||
}
|
||||
|
||||
impl Default for ScrollArea {
|
||||
fn default() -> Self {
|
||||
impl ScrollArea {
|
||||
/// Will make the area be as high as it is allowed to be (i.e. fill the ui it is in)
|
||||
pub fn auto_sized() -> Self {
|
||||
Self::from_max_height(f32::INFINITY)
|
||||
}
|
||||
|
||||
/// Use `f32::INFINITY` if you want the scroll area to expand to fit the surrounding Ui
|
||||
pub fn from_max_height(max_height: f32) -> Self {
|
||||
Self {
|
||||
max_height: 200.0,
|
||||
max_height,
|
||||
always_show_scroll: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ScrollArea {
|
||||
pub fn max_height(mut self, max_height: f32) -> Self {
|
||||
self.max_height = max_height;
|
||||
self
|
||||
}
|
||||
|
||||
/// If `false` (defualt), the scroll bar will be hidden when not needed/
|
||||
/// If `false` (default), the scroll bar will be hidden when not needed/
|
||||
/// If `true`, the scroll bar will always be displayed even if not needed.
|
||||
pub fn always_show_scroll(mut self, always_show_scroll: bool) -> Self {
|
||||
self.always_show_scroll = always_show_scroll;
|
||||
|
|
|
@ -142,11 +142,7 @@ impl<'open> Window<'open> {
|
|||
pub fn scroll(mut self, scroll: bool) -> Self {
|
||||
if scroll {
|
||||
if self.scroll.is_none() {
|
||||
self.scroll = Some(
|
||||
ScrollArea::default()
|
||||
.always_show_scroll(false)
|
||||
.max_height(f32::INFINITY), // As large as we can be
|
||||
);
|
||||
self.scroll = Some(ScrollArea::auto_sized());
|
||||
}
|
||||
debug_assert!(
|
||||
self.scroll.is_some(),
|
||||
|
|
|
@ -360,7 +360,7 @@ impl DemoWindow {
|
|||
CollapsingHeader::new("Scroll area")
|
||||
.default_open(false)
|
||||
.show(ui, |ui| {
|
||||
ScrollArea::default().show(ui, |ui| {
|
||||
ScrollArea::from_max_height(200.0).show(ui, |ui| {
|
||||
ui.label(LOREM_IPSUM_LONG);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue