[window] make scroll bars in windows opt-in
This commit is contained in:
parent
5ed949bb32
commit
03bc4ea2e2
2 changed files with 17 additions and 10 deletions
|
@ -1,17 +1,19 @@
|
||||||
|
// WARNING: the code in here is horrible. It is a behemoth that needs breaking up into simpler parts.
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{paint::*, widgets::*, *};
|
use crate::{paint::*, widgets::*, *};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// Builder for a floating window which can be dragged, closed, collapsed, resized and scrolled.
|
/// Builder for a floating window which can be dragged, closed, collapsed, resized and scrolled (off by default).
|
||||||
///
|
///
|
||||||
/// You can customize:
|
/// You can customize:
|
||||||
/// * title
|
/// * title
|
||||||
/// * default, minimum, maximum and/or fixed size
|
/// * default, minimum, maximum and/or fixed size
|
||||||
/// * if the window has a scroll area
|
/// * if the window has a scroll area (off by default)
|
||||||
/// * if the window can be collapsed (minimized) to just the title bar
|
/// * if the window can be collapsed (minimized) to just the title bar (yes, by default)
|
||||||
/// * if there should be a close button
|
/// * if there should be a close button (none by default)
|
||||||
pub struct Window<'open> {
|
pub struct Window<'open> {
|
||||||
pub title_label: Label,
|
pub title_label: Label,
|
||||||
open: Option<&'open mut bool>,
|
open: Option<&'open mut bool>,
|
||||||
|
@ -39,11 +41,7 @@ impl<'open> Window<'open> {
|
||||||
.outline(false)
|
.outline(false)
|
||||||
.min_size([96.0, 32.0])
|
.min_size([96.0, 32.0])
|
||||||
.default_size([280.0, 400.0]),
|
.default_size([280.0, 400.0]),
|
||||||
scroll: Some(
|
scroll: None,
|
||||||
ScrollArea::default()
|
|
||||||
.always_show_scroll(false)
|
|
||||||
.max_height(f32::INFINITY),
|
|
||||||
), // As large as we can be
|
|
||||||
collapsible: true,
|
collapsible: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,9 +138,16 @@ impl<'open> Window<'open> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable/disable scrolling. True by default.
|
/// Enable/disable scrolling. `false` by default.
|
||||||
pub fn scroll(mut self, scroll: bool) -> Self {
|
pub fn scroll(mut self, scroll: bool) -> Self {
|
||||||
if scroll {
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
self.scroll.is_some(),
|
self.scroll.is_some(),
|
||||||
"Window::scroll called multiple times"
|
"Window::scroll called multiple times"
|
||||||
|
|
|
@ -51,6 +51,7 @@ impl DemoApp {
|
||||||
|
|
||||||
Window::new("Demo")
|
Window::new("Demo")
|
||||||
.open(&mut open_windows.demo)
|
.open(&mut open_windows.demo)
|
||||||
|
.scroll(true)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
demo_window.ui(ui);
|
demo_window.ui(ui);
|
||||||
});
|
});
|
||||||
|
@ -63,6 +64,7 @@ impl DemoApp {
|
||||||
|
|
||||||
Window::new("Inspection")
|
Window::new("Inspection")
|
||||||
.open(&mut open_windows.inspection)
|
.open(&mut open_windows.inspection)
|
||||||
|
.scroll(true)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ctx.inspection_ui(ui);
|
ctx.inspection_ui(ui);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue