1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Publish 0.14.2 (#670)

* Fix window resize bug introduced in `0.14.1`.

* tweak plot demo layout to allow more narrow window

* Release 0.14.2 - Window resize fix
This commit is contained in:
Emil Ernerfeldt
2021-08-28 12:19:35 +02:00
committed by GitHub
parent 1fbce6b2c3
commit 776770cdcd
9 changed files with 53 additions and 57 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "egui"
version = "0.14.1"
version = "0.14.2"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
description = "Simple, portable immediate mode GUI library for Rust"
edition = "2018"

View File

@@ -339,11 +339,9 @@ impl Prepared {
// Important check - don't try to move e.g. a combobox popup!
if movable {
if let Some(bounds) = drag_bounds {
state.pos = ctx.constrain_window_rect_to_area(state.rect(), bounds).min;
} else {
state.pos = ctx.constrain_window_rect(state.rect()).min;
}
state.pos = ctx
.constrain_window_rect_to_area(state.rect(), drag_bounds)
.min;
}
if (move_response.dragged() || move_response.clicked())

View File

@@ -275,7 +275,7 @@ impl<'open> Window<'open> {
&& !collapsing_header::State::is_open(ctx, collapsing_id).unwrap_or_default();
let possible = PossibleInteractions::new(&area, &resize, is_collapsed);
let area = area.movable(false); // We move it manually
let area = area.movable(false); // We move it manually, or the area will move the window when we want to resize it
let resize = resize.resizable(false); // We move it manually
let mut resize = resize.id(resize_id);
@@ -301,16 +301,14 @@ impl<'open> Window<'open> {
0.0
};
let margins = 2.0 * frame.margin + vec2(0.0, title_bar_height);
let bounds = area.drag_bounds();
interact(
window_interaction,
ctx,
margins,
area_layer_id,
area.state_mut(),
&mut area,
resize_id,
bounds,
)
})
} else {
@@ -405,7 +403,10 @@ impl<'open> Window<'open> {
content_inner
};
area.movable = possible.movable; // Tell it the truth
area.state_mut().pos = ctx
.constrain_window_rect_to_area(area.state().rect(), area.drag_bounds())
.min;
let full_response = area.end(ctx, area_content_ui);
let inner_response = InnerResponse {
@@ -505,21 +506,16 @@ fn interact(
ctx: &Context,
margins: Vec2,
area_layer_id: LayerId,
area_state: &mut area::State,
area: &mut area::Prepared,
resize_id: Id,
drag_bounds: Option<Rect>,
) -> Option<WindowInteraction> {
let new_rect = move_and_resize_window(ctx, &window_interaction)?;
let new_rect = ctx.round_rect_to_pixels(new_rect);
let new_rect = if let Some(bounds) = drag_bounds {
ctx.constrain_window_rect_to_area(new_rect, bounds)
} else {
ctx.constrain_window_rect(new_rect)
};
let new_rect = ctx.constrain_window_rect_to_area(new_rect, area.drag_bounds());
// TODO: add this to a Window state instead as a command "move here next frame"
area_state.pos = new_rect.min;
area.state_mut().pos = new_rect.min;
if window_interaction.is_resize() {
ctx.memory()

View File

@@ -509,15 +509,12 @@ impl Context {
// ---------------------------------------------------------------------
/// Constrain the position of a window/area
/// so it fits within the screen.
pub(crate) fn constrain_window_rect(&self, window: Rect) -> Rect {
self.constrain_window_rect_to_area(window, self.available_rect())
}
/// Constrain the position of a window/area so it fits within the provided boundary.
///
/// If area is `None`, will constrain to [`Self::available_rect`].
pub(crate) fn constrain_window_rect_to_area(&self, window: Rect, area: Option<Rect>) -> Rect {
let mut area = area.unwrap_or_else(|| self.available_rect());
/// Constrain the position of a window/area
/// so it fits within the provided boundary.
pub(crate) fn constrain_window_rect_to_area(&self, window: Rect, mut area: Rect) -> Rect {
if window.width() > area.width() {
// Allow overlapping side bars.
// This is important for small screens, e.g. mobiles running the web demo.