Skip to content

Commit e30a9c1

Browse files
committed
[window/resize] add Resize::max_width and fix bug with fixed_size
1 parent f8bc4d3 commit e30a9c1

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

egui/src/containers/area.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl Area {
6464
}
6565
}
6666

67-
/// moveable by draggin the area?
67+
/// moveable by dragging the area?
6868
pub fn movable(mut self, movable: bool) -> Self {
6969
self.movable = movable;
7070
self.interactable |= movable;
@@ -75,7 +75,7 @@ impl Area {
7575
self.movable
7676
}
7777

78-
/// If false, clicks goes stright throught to what is behind us.
78+
/// If false, clicks goes straight through to what is behind us.
7979
/// Good for tooltips etc.
8080
pub fn interactable(mut self, interactable: bool) -> Self {
8181
self.interactable = interactable;

egui/src/containers/resize.rs

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct Resize {
2525
resizable: bool,
2626

2727
pub(crate) min_size: Vec2,
28+
pub(crate) max_size: Vec2,
2829

2930
default_size: Vec2,
3031

@@ -37,6 +38,7 @@ impl Default for Resize {
3738
id: None,
3839
resizable: true,
3940
min_size: Vec2::splat(16.0),
41+
max_size: Vec2::splat(f32::INFINITY),
4042
default_size: vec2(320.0, 128.0), // TODO: preferred size of `Resize` area.
4143
with_stroke: true,
4244
}
@@ -84,6 +86,12 @@ impl Resize {
8486
self
8587
}
8688

89+
/// Won't expand to larger than this
90+
pub fn max_size(mut self, max_size: impl Into<Vec2>) -> Self {
91+
self.max_size = max_size.into();
92+
self
93+
}
94+
8795
/// Can you resize it with the mouse?
8896
/// Note that a window can still auto-resize
8997
pub fn resizable(mut self, resizable: bool) -> Self {
@@ -96,6 +104,7 @@ impl Resize {
96104
}
97105

98106
/// Not manually resizable, just takes the size of its contents.
107+
/// Text will not wrap, but will instead make your window width expand.
99108
pub fn auto_sized(self) -> Self {
100109
self.min_size(Vec2::zero())
101110
.default_size(Vec2::splat(f32::INFINITY))
@@ -106,6 +115,7 @@ impl Resize {
106115
let size = size.into();
107116
self.default_size = size;
108117
self.min_size = size;
118+
self.max_size = size;
109119
self.resizable = false;
110120
self
111121
}
@@ -140,6 +150,7 @@ impl Resize {
140150
});
141151

142152
state.desired_size = state.desired_size.max(self.min_size);
153+
state.desired_size = state.desired_size.min(self.max_size);
143154

144155
let position = ui.available().min;
145156

@@ -164,6 +175,7 @@ impl Resize {
164175
state.desired_size = requested_size;
165176
}
166177
state.desired_size = state.desired_size.max(self.min_size);
178+
state.desired_size = state.desired_size.min(self.max_size);
167179

168180
// ------------------------------
169181

egui/src/containers/window.rs

+6
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ impl<'open> Window<'open> {
117117
self
118118
}
119119

120+
/// Sets the window pos and size and prevents it from being moved and resized by dragging its edges.
121+
pub fn fixed_rect(self, rect: Rect) -> Self {
122+
self.fixed_pos(rect.min).fixed_size(rect.size())
123+
}
124+
120125
/// Can the user resize the window by dragging its edges?
121126
/// Note that even if you set this to `false` the window may still auto-resize.
122127
pub fn resizable(mut self, resizable: bool) -> Self {
@@ -132,6 +137,7 @@ impl<'open> Window<'open> {
132137

133138
/// Not resizable, just takes the size of its contents.
134139
/// Also disabled scrolling.
140+
/// Text will not wrap, but will instead make your window width expand.
135141
pub fn auto_sized(mut self) -> Self {
136142
self.resize = self.resize.auto_sized();
137143
self.scroll = None;

egui/src/demos/demo_window.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl DemoWindow {
4949
});
5050

5151
CollapsingHeader::new("Colors")
52-
.default_open(true)
52+
.default_open(false)
5353
.show(ui, |ui| {
5454
self.colors.ui(ui);
5555
});

0 commit comments

Comments
 (0)