diff --git a/emigui/src/containers/resize.rs b/emigui/src/containers/resize.rs index 4de466f9..44e8218b 100644 --- a/emigui/src/containers/resize.rs +++ b/emigui/src/containers/resize.rs @@ -179,26 +179,22 @@ impl Resize { let inner_rect = Rect::from_min_size(region.cursor(), state.size); let desired_size = { - let mut contents_region = region.child_region(inner_rect); - contents_region.clip_rect = region + let mut content_clip_rect = region .clip_rect() .intersect(&inner_rect.expand(region.style().clip_rect_margin)); - // region.debug_text_at( - // inner_rect.min + last_frame_size, - // &format!("last_frame_size: {:?}", last_frame_size), - // ); - // If we pull the resize handle to shrink, we want to TRY to shink it. // After laying out the contents, we might be much bigger. // In those cases we don't want the clip_rect to be smaller, because // then we will clip the contents of the region even thought the result gets larger. This is simply ugly! - contents_region.clip_rect.max = contents_region - .clip_rect + // So we use the memory of last_frame_size to make the clip rect large enough. + content_clip_rect.max = content_clip_rect .max - .max(contents_region.clip_rect.min + last_frame_size) - .min(region.clip_rect.max); // Respect parent region + .max(content_clip_rect.min + last_frame_size) + .min(region.clip_rect().max); // Respect parent region + let mut contents_region = region.child_region(inner_rect); + contents_region.set_clip_rect(content_clip_rect); add_contents(&mut contents_region); contents_region.bounding_size() }; diff --git a/emigui/src/containers/scroll_area.rs b/emigui/src/containers/scroll_area.rs index 61561ff3..8e32d5d7 100644 --- a/emigui/src/containers/scroll_area.rs +++ b/emigui/src/containers/scroll_area.rs @@ -80,8 +80,10 @@ impl ScrollArea { outer_region.cursor() - state.offset, vec2(inner_size.x, f32::INFINITY), )); - // content_region.clip_rect = outer_region.clip_rect().intersect(&inner_rect); - content_region.clip_rect = outer_region.clip_rect(); // Nice handling of forced resizing beyon the possible + let mut content_clip_rect = outer_region.clip_rect().intersect(&inner_rect); + content_clip_rect.max.x = outer_region.clip_rect().max.x - current_scroll_bar_width; // Nice handling of forced resizing beyond the possible + content_region.set_clip_rect(content_clip_rect); + add_contents(&mut content_region); let content_size = content_region.bounding_size(); diff --git a/emigui/src/region.rs b/emigui/src/region.rs index f93f035c..ef65aa88 100644 --- a/emigui/src/region.rs +++ b/emigui/src/region.rs @@ -141,6 +141,10 @@ impl Region { self.clip_rect } + pub fn set_clip_rect(&mut self, clip_rect: Rect) { + self.clip_rect = clip_rect; + } + pub fn bottom_right(&self) -> Pos2 { // If a child doesn't fit in desired_rect, we have effectively expanded: self.desired_rect.max.max(self.child_bounds.max)