Skip to content

Commit

Permalink
Fix clip rectangle of windows that don't fit the central area.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 7, 2021
1 parent 5e3c522 commit aef2375
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [

### Fixed 🐛
* Fix wrongly sized multiline `TextEdit` in justified layouts.
* Fix clip rectangle of windows that don't fit the central area.


## 0.14.2 - 2021-08-28 - Window resize fix
Expand Down
66 changes: 30 additions & 36 deletions egui/src/containers/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ pub(crate) struct Prepared {
}

impl Area {
pub fn show<R>(
self,
ctx: &CtxRef,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
let prepared = self.begin(ctx);
let mut content_ui = prepared.content_ui(ctx);
let inner = add_contents(&mut content_ui);
let response = prepared.end(ctx, content_ui);
InnerResponse { inner, response }
}

pub(crate) fn begin(self, ctx: &CtxRef) -> Prepared {
let Area {
id,
Expand Down Expand Up @@ -219,18 +231,6 @@ impl Area {
}
}

pub fn show<R>(
self,
ctx: &CtxRef,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
let prepared = self.begin(ctx);
let mut content_ui = prepared.content_ui(ctx);
let inner = add_contents(&mut content_ui);
let response = prepared.end(ctx, content_ui);
InnerResponse { inner, response }
}

pub fn show_open_close_animation(&self, ctx: &CtxRef, frame: &Frame, is_open: bool) {
// must be called first so animation managers know the latest state
let visibility_factor = ctx.animate_bool(self.id.with("close_animation"), is_open);
Expand Down Expand Up @@ -274,35 +274,29 @@ impl Prepared {
}

pub(crate) fn content_ui(&self, ctx: &CtxRef) -> Ui {
let max_rect = if ctx.available_rect().contains(self.state.pos) {
Rect::from_min_max(self.state.pos, ctx.available_rect().max)
} else {
Rect::from_min_max(
self.state.pos,
ctx.input()
.screen_rect()
.max
.max(self.state.pos + Vec2::splat(32.0)),
)
};
let bounds = self.drag_bounds.unwrap_or_else(|| {
let central_area = ctx.available_rect();

let is_within_central_area = central_area.contains_rect(self.state.rect().shrink(1.0));
if is_within_central_area {
central_area // let's try to not cover side panels
} else {
ctx.input().screen_rect()
}
});

let max_rect = Rect::from_min_max(
self.state.pos,
bounds.max.at_least(self.state.pos + Vec2::splat(32.0)),
);

let shadow_radius = ctx.style().visuals.window_shadow.extrusion; // hacky
let bounds = self.drag_bounds.unwrap_or_else(|| ctx.input().screen_rect);
let clip_rect_margin = ctx.style().visuals.clip_rect_margin.max(shadow_radius);

let mut clip_rect = max_rect
.expand(ctx.style().visuals.clip_rect_margin)
.expand(shadow_radius)
let clip_rect = Rect::from_min_max(self.state.pos, bounds.max)
.expand(clip_rect_margin)
.intersect(bounds);

// Windows are constrained to central area,
// (except in rare cases where they don't fit).
// Adjust clip rect so we don't cast shadows on side panels:
let central_area = ctx.available_rect();
let is_within_central_area = central_area.contains_rect(self.state.rect().shrink(1.0));
if is_within_central_area {
clip_rect = clip_rect.intersect(central_area);
}

let mut ui = Ui::new(
ctx.clone(),
self.layer_id,
Expand Down

0 comments on commit aef2375

Please sign in to comment.