Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max window size & other size helpers #3537

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/egui/src/containers/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ impl Resize {
self
}

/// Won't expand to larger than this
pub fn max_width(mut self, max_width: f32) -> Self {
self.max_size.x = max_width;
self
}

/// Won't expand to larger than this
pub fn max_height(mut self, max_height: f32) -> Self {
self.max_size.y = max_height;
self
}

/// Can you resize it with the mouse?
///
/// Note that a window can still auto-resize.
Expand Down
24 changes: 24 additions & 0 deletions crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,30 @@ impl<'open> Window<'open> {
self
}

/// Set minimum size of the window, equivalent to calling both `min_width` and `min_height`.
pub fn min_size(mut self, min_size: impl Into<Vec2>) -> Self {
self.resize = self.resize.min_size(min_size);
self
}

/// Set maximum width of the window.
pub fn max_width(mut self, max_width: f32) -> Self {
self.resize = self.resize.max_width(max_width);
self
}

/// Set maximum height of the window.
pub fn max_height(mut self, max_height: f32) -> Self {
self.resize = self.resize.max_height(max_height);
self
}

/// Set maximum size of the window, equivalent to calling both `max_width` and `max_height`.
pub fn max_size(mut self, max_size: impl Into<Vec2>) -> Self {
self.resize = self.resize.max_size(max_size);
self
}

/// Set current position of the window.
/// If the window is movable it is up to you to keep track of where it moved to!
pub fn current_pos(mut self, current_pos: impl Into<Pos2>) -> Self {
Expand Down
Loading