Skip to content

Commit

Permalink
Update resize.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbasic authored Jun 29, 2024
1 parent b3a4532 commit 92396b0
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions crates/egui/src/containers/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ pub struct Resize {

pub(crate) min_size: Vec2,
pub(crate) max_size: Vec2,
pub(crate) margins: Vec2,

default_size: Vec2,
pub(crate) default_size: Vec2,

with_stroke: bool,
}
Expand All @@ -52,7 +53,8 @@ impl Default for Resize {
resizable: Vec2b::TRUE,
min_size: Vec2::splat(16.0),
max_size: Vec2::splat(f32::INFINITY),
default_size: vec2(320.0, 128.0), // TODO(emilk): preferred size of [`Resize`] area.
margins: Vec2::ZERO,
default_size: Vec2::splat(16.0), // TODO(emilk): preferred size of [`Resize`] area.
with_stroke: true,
}
}
Expand Down Expand Up @@ -205,25 +207,18 @@ impl Resize {
let mut state = State::load(ui.ctx(), id).unwrap_or_else(|| {
ui.ctx().request_repaint(); // counter frame delay

let default_size = self
.default_size
.at_least(self.min_size)
.at_most(self.max_size)
.at_most(
ui.ctx().screen_rect().size() - ui.spacing().window_margin.sum(), // hack for windows
);

State {
desired_size: default_size,
last_content_size: vec2(0.0, 0.0),
desired_size: self.default_size,
last_content_size: Vec2::ZERO,
requested_size: None,
}
});

state.desired_size = state
.desired_size
.at_least(self.min_size)
.at_most(self.max_size);
.at_most(self.max_size)
.at_most(ui.ctx().screen_rect().size() - self.margins);

let mut user_requested_size = state.requested_size.take();

Expand Down Expand Up @@ -310,13 +305,14 @@ impl Resize {
// We show how large we are,
// so we must follow the contents:

state.desired_size[d] = state.desired_size[d].max(state.last_content_size[d]);
state.desired_size[d] = state.desired_size[d].at_least(state.last_content_size[d]);

// We are as large as we look
size[d] = state.desired_size[d];
} else {
// Probably a window.
size[d] = state.last_content_size[d];
state.desired_size[d] = state.last_content_size[d];
size[d] = state.desired_size[d];
}
}
ui.advance_cursor_after_rect(Rect::from_min_size(content_ui.min_rect().min, size));
Expand Down Expand Up @@ -373,8 +369,6 @@ impl Resize {
}
}

use epaint::Stroke;

pub fn paint_resize_corner(ui: &Ui, response: &Response) {
let stroke = ui.style().interact(response).fg_stroke;
paint_resize_corner_with_style(ui, &response.rect, stroke.color, Align2::RIGHT_BOTTOM);
Expand Down

0 comments on commit 92396b0

Please sign in to comment.