[window/resize] add Resize::max_width and fix bug with fixed_size
This commit is contained in:
parent
f8bc4d38e8
commit
e30a9c1196
4 changed files with 21 additions and 3 deletions
|
@ -64,7 +64,7 @@ impl Area {
|
|||
}
|
||||
}
|
||||
|
||||
/// moveable by draggin the area?
|
||||
/// moveable by dragging the area?
|
||||
pub fn movable(mut self, movable: bool) -> Self {
|
||||
self.movable = movable;
|
||||
self.interactable |= movable;
|
||||
|
@ -75,7 +75,7 @@ impl Area {
|
|||
self.movable
|
||||
}
|
||||
|
||||
/// If false, clicks goes stright throught to what is behind us.
|
||||
/// If false, clicks goes straight through to what is behind us.
|
||||
/// Good for tooltips etc.
|
||||
pub fn interactable(mut self, interactable: bool) -> Self {
|
||||
self.interactable = interactable;
|
||||
|
|
|
@ -25,6 +25,7 @@ pub struct Resize {
|
|||
resizable: bool,
|
||||
|
||||
pub(crate) min_size: Vec2,
|
||||
pub(crate) max_size: Vec2,
|
||||
|
||||
default_size: Vec2,
|
||||
|
||||
|
@ -37,6 +38,7 @@ impl Default for Resize {
|
|||
id: None,
|
||||
resizable: true,
|
||||
min_size: Vec2::splat(16.0),
|
||||
max_size: Vec2::splat(f32::INFINITY),
|
||||
default_size: vec2(320.0, 128.0), // TODO: preferred size of `Resize` area.
|
||||
with_stroke: true,
|
||||
}
|
||||
|
@ -84,6 +86,12 @@ impl Resize {
|
|||
self
|
||||
}
|
||||
|
||||
/// Won't expand to larger than this
|
||||
pub fn max_size(mut self, max_size: impl Into<Vec2>) -> Self {
|
||||
self.max_size = max_size.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Can you resize it with the mouse?
|
||||
/// Note that a window can still auto-resize
|
||||
pub fn resizable(mut self, resizable: bool) -> Self {
|
||||
|
@ -96,6 +104,7 @@ impl Resize {
|
|||
}
|
||||
|
||||
/// Not manually resizable, just takes the size of its contents.
|
||||
/// Text will not wrap, but will instead make your window width expand.
|
||||
pub fn auto_sized(self) -> Self {
|
||||
self.min_size(Vec2::zero())
|
||||
.default_size(Vec2::splat(f32::INFINITY))
|
||||
|
@ -106,6 +115,7 @@ impl Resize {
|
|||
let size = size.into();
|
||||
self.default_size = size;
|
||||
self.min_size = size;
|
||||
self.max_size = size;
|
||||
self.resizable = false;
|
||||
self
|
||||
}
|
||||
|
@ -140,6 +150,7 @@ impl Resize {
|
|||
});
|
||||
|
||||
state.desired_size = state.desired_size.max(self.min_size);
|
||||
state.desired_size = state.desired_size.min(self.max_size);
|
||||
|
||||
let position = ui.available().min;
|
||||
|
||||
|
@ -164,6 +175,7 @@ impl Resize {
|
|||
state.desired_size = requested_size;
|
||||
}
|
||||
state.desired_size = state.desired_size.max(self.min_size);
|
||||
state.desired_size = state.desired_size.min(self.max_size);
|
||||
|
||||
// ------------------------------
|
||||
|
||||
|
|
|
@ -117,6 +117,11 @@ impl<'open> Window<'open> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the window pos and size and prevents it from being moved and resized by dragging its edges.
|
||||
pub fn fixed_rect(self, rect: Rect) -> Self {
|
||||
self.fixed_pos(rect.min).fixed_size(rect.size())
|
||||
}
|
||||
|
||||
/// Can the user resize the window by dragging its edges?
|
||||
/// Note that even if you set this to `false` the window may still auto-resize.
|
||||
pub fn resizable(mut self, resizable: bool) -> Self {
|
||||
|
@ -132,6 +137,7 @@ impl<'open> Window<'open> {
|
|||
|
||||
/// Not resizable, just takes the size of its contents.
|
||||
/// Also disabled scrolling.
|
||||
/// Text will not wrap, but will instead make your window width expand.
|
||||
pub fn auto_sized(mut self) -> Self {
|
||||
self.resize = self.resize.auto_sized();
|
||||
self.scroll = None;
|
||||
|
|
|
@ -49,7 +49,7 @@ impl DemoWindow {
|
|||
});
|
||||
|
||||
CollapsingHeader::new("Colors")
|
||||
.default_open(true)
|
||||
.default_open(false)
|
||||
.show(ui, |ui| {
|
||||
self.colors.ui(ui);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue