Add `Ui::take_available_space()` helper function, which sets the Ui's minimum size to the available space (#7573)
A shorthand, and more descriptive version of calling `ui.set_min_size(ui.available_size())`, and mentions this on panel's resizable functions.
This commit is contained in:
parent
18ea9ff0bd
commit
0888e3dc86
|
|
@ -144,8 +144,11 @@ impl SidePanel {
|
||||||
///
|
///
|
||||||
/// Default is `true`.
|
/// Default is `true`.
|
||||||
///
|
///
|
||||||
/// If you want your panel to be resizable you also need a widget in it that
|
/// If you want your panel to be resizable you also need to make the ui use
|
||||||
/// takes up more space as you resize it, such as:
|
/// the available space.
|
||||||
|
///
|
||||||
|
/// This can be done by using [`Ui::take_available_space`], or using a
|
||||||
|
/// widget in it that takes up more space as you resize it, such as:
|
||||||
/// * Wrapping text ([`Ui::horizontal_wrapped`]).
|
/// * Wrapping text ([`Ui::horizontal_wrapped`]).
|
||||||
/// * A [`crate::ScrollArea`].
|
/// * A [`crate::ScrollArea`].
|
||||||
/// * A [`crate::Separator`].
|
/// * A [`crate::Separator`].
|
||||||
|
|
@ -631,8 +634,11 @@ impl TopBottomPanel {
|
||||||
///
|
///
|
||||||
/// Default is `false`.
|
/// Default is `false`.
|
||||||
///
|
///
|
||||||
/// If you want your panel to be resizable you also need a widget in it that
|
/// If you want your panel to be resizable you also need to make the ui use
|
||||||
/// takes up more space as you resize it, such as:
|
/// the available space.
|
||||||
|
///
|
||||||
|
/// This can be done by using [`Ui::take_available_space`], or using a
|
||||||
|
/// widget in it that takes up more space as you resize it, such as:
|
||||||
/// * Wrapping text ([`Ui::horizontal_wrapped`]).
|
/// * Wrapping text ([`Ui::horizontal_wrapped`]).
|
||||||
/// * A [`crate::ScrollArea`].
|
/// * A [`crate::ScrollArea`].
|
||||||
/// * A [`crate::Separator`].
|
/// * A [`crate::Separator`].
|
||||||
|
|
|
||||||
|
|
@ -944,6 +944,30 @@ impl Ui {
|
||||||
self.placer.set_min_height(height);
|
self.placer.set_min_height(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Makes the ui always fill up the available space.
|
||||||
|
///
|
||||||
|
/// This can be useful to call inside a panel with `resizable == true`
|
||||||
|
/// to make sure the resized space is used.
|
||||||
|
pub fn take_available_space(&mut self) {
|
||||||
|
self.set_min_size(self.available_size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Makes the ui always fill up the available space in the x axis.
|
||||||
|
///
|
||||||
|
/// This can be useful to call inside a side panel with
|
||||||
|
/// `resizable == true` to make sure the resized space is used.
|
||||||
|
pub fn take_available_width(&mut self) {
|
||||||
|
self.set_min_width(self.available_width());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Makes the ui always fill up the available space in the y axis.
|
||||||
|
///
|
||||||
|
/// This can be useful to call inside a top bottom panel with
|
||||||
|
/// `resizable == true` to make sure the resized space is used.
|
||||||
|
pub fn take_available_height(&mut self) {
|
||||||
|
self.set_min_height(self.available_height());
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Helper: shrinks the max width to the current width,
|
/// Helper: shrinks the max width to the current width,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue