diff --git a/crates/gpui/src/element.rs b/crates/gpui/src/element.rs index d1290a5d08..a24b5eb291 100644 --- a/crates/gpui/src/element.rs +++ b/crates/gpui/src/element.rs @@ -1,6 +1,6 @@ use crate::{ - outline, util::FluentBuilder, ArenaBox, AvailableSpace, BorrowWindow, Bounds, ElementId, - LayoutId, Pixels, Point, Size, ViewContext, WindowContext, ELEMENT_ARENA, + util::FluentBuilder, ArenaBox, AvailableSpace, BorrowWindow, Bounds, ElementId, LayoutId, + Pixels, Point, Size, ViewContext, WindowContext, ELEMENT_ARENA, }; use derive_more::{Deref, DerefMut}; pub(crate) use smallvec::SmallVec; @@ -236,7 +236,6 @@ impl DrawableElement { } fn paint(mut self, cx: &mut WindowContext) -> Option { - let element_id = self.element_id(); match self.phase { ElementDrawPhase::LayoutRequested { layout_id, @@ -249,12 +248,6 @@ impl DrawableElement { } => { let bounds = cx.layout_bounds(layout_id); - if element_id == Some(ElementId::Name("info_popover".into())) - || element_id == Some(ElementId::Name("content".into())) - { - cx.paint_quad(outline(dbg!(bounds), crate::red())) - } - if let Some(mut frame_state) = frame_state { self.element .take() @@ -270,6 +263,7 @@ impl DrawableElement { .expect("if we don't have frame state, we should have element state"); cx.with_element_state(element_id, |element_state, cx| { let mut element_state = element_state.unwrap(); + self.element .take() .unwrap() diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index 238713fec4..4d0304f5ea 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -1,5 +1,5 @@ use crate::{ - outline, point, px, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, AppContext, + point, px, size, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, AppContext, BorrowAppContext, BorrowWindow, Bounds, ClickEvent, DispatchPhase, Element, ElementId, FocusHandle, IntoElement, IsZero, KeyContext, KeyDownEvent, KeyUpEvent, LayoutId, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, Point, Render, @@ -815,11 +815,7 @@ impl Element for Div { element_state: &mut Self::State, cx: &mut WindowContext, ) { - let mut child_min = point(Pixels::MAX, Pixels::MAX); - let mut child_max = Point::default(); - let content_size = if element_state.child_layout_ids.is_empty() { - bounds.size - } else if let Some(scroll_handle) = self.interactivity.scroll_handle.as_ref() { + if let Some(scroll_handle) = self.interactivity.scroll_handle.as_ref() { let mut state = scroll_handle.0.borrow_mut(); state.child_bounds = Vec::with_capacity(element_state.child_layout_ids.len()); state.bounds = bounds; @@ -827,8 +823,6 @@ impl Element for Div { for (ix, child_layout_id) in element_state.child_layout_ids.iter().enumerate() { let child_bounds = cx.layout_bounds(*child_layout_id); - child_min = child_min.min(&child_bounds.origin); - child_max = child_max.max(&child_bounds.lower_right()); state.child_bounds.push(child_bounds); if let Some(requested) = requested.as_ref() { @@ -838,31 +832,16 @@ impl Element for Div { } } } - (child_max - child_min).into() - } else { - if self.element_id() == Some(ElementId::Name("info_popover".into())) { - eprintln!("********************************************"); - dbg!(&self.interactivity().base_style.padding); - dbg!(bounds); - dbg!(cx.layout_content_size(element_state.layout_id)); - dbg!(cx.layout_scroll_size(element_state.layout_id)); - } + } - cx.layout_content_size(element_state.layout_id) - }; + let content_size = cx.layout_content_size(element_state.layout_id); - let element_id = self.element_id(); self.interactivity.paint( bounds, content_size, &mut element_state.interactive_state, - Some(element_state.layout_id), cx, |_style, scroll_offset, cx| { - if element_id == Some(ElementId::Name("info_popover".into())) { - dbg!(scroll_offset); - }; - cx.with_element_offset(scroll_offset, |cx| { for child in &mut self.children { child.paint(cx); @@ -1000,7 +979,6 @@ impl Interactivity { bounds: Bounds, content_size: Size, element_state: &mut InteractiveElementState, - this_id: Option, cx: &mut WindowContext, f: impl FnOnce(&Style, Point, &mut WindowContext), ) { @@ -1518,28 +1496,31 @@ impl Interactivity { .clone(); let line_height = cx.line_height(); - let mut scroll_max = this_id - .map(|id| cx.layout_scroll_size(id)) - .unwrap_or(content_size - bounds.size) - .max(&Size::default()); - - if self.element_id == Some(ElementId::Name("info_popover".into())) { - dbg!(this_id); - dbg!(scroll_max); - - //will this fix things? - // scroll_max = scroll_size + offset_position of child???? - - // scroll_max.height += dbg!(self - // .base_style - // .padding - // .bottom - // .map(|padding| { - // dbg!(padding) - // .to_pixels(content_size.height.into(), cx.rem_size()) - // }) - // .unwrap_or(px(0.))) - } + // TODO: Change this to be cx.layout_scroll_size() + bottom and right padding + // once we can access the layout ID easily from all elements + let scroll_max = (content_size - bounds.size + // Add the bottom padding to the scroll max, so that + // the bottom padding is visible but not clipping + // the scrollable area + + size( + self.base_style + .padding + .right + .map(|padding| { + padding + .to_pixels(bounds.size.width.into(), cx.rem_size()) + }) + .unwrap_or(px(0.)), + self.base_style + .padding + .bottom + .map(|padding| { + padding + .to_pixels(bounds.size.height.into(), cx.rem_size()) + }) + .unwrap_or(px(0.)), + )) + .max(&Size::default()); // Clamp scroll offset in case scroll max is smaller now (e.g., if children // were removed or the bounds became larger). diff --git a/crates/gpui/src/elements/img.rs b/crates/gpui/src/elements/img.rs index 8fdd390b2f..5a656db9fb 100644 --- a/crates/gpui/src/elements/img.rs +++ b/crates/gpui/src/elements/img.rs @@ -91,7 +91,6 @@ impl Element for Img { bounds, bounds.size, element_state, - None, cx, |style, _scroll_offset, cx| { let corner_radii = style.corner_radii.to_pixels(bounds.size, cx.rem_size()); diff --git a/crates/gpui/src/elements/svg.rs b/crates/gpui/src/elements/svg.rs index db65618eec..184af13878 100644 --- a/crates/gpui/src/elements/svg.rs +++ b/crates/gpui/src/elements/svg.rs @@ -1,8 +1,9 @@ +use util::ResultExt; + use crate::{ Bounds, Element, ElementId, InteractiveElement, InteractiveElementState, Interactivity, IntoElement, LayoutId, Pixels, SharedString, StyleRefinement, Styled, WindowContext, }; -use util::ResultExt; pub struct Svg { interactivity: Interactivity, @@ -44,18 +45,12 @@ impl Element for Svg { ) where Self: Sized, { - self.interactivity.paint( - bounds, - bounds.size, - element_state, - None, - cx, - |style, _, cx| { + self.interactivity + .paint(bounds, bounds.size, element_state, cx, |style, _, cx| { if let Some((path, color)) = self.path.as_ref().zip(style.text.color) { cx.paint_svg(bounds, path.clone(), color).log_err(); } - }, - ) + }) } } diff --git a/crates/gpui/src/elements/uniform_list.rs b/crates/gpui/src/elements/uniform_list.rs index 6753b8d4bb..77ef7df10c 100644 --- a/crates/gpui/src/elements/uniform_list.rs +++ b/crates/gpui/src/elements/uniform_list.rs @@ -182,7 +182,6 @@ impl Element for UniformList { bounds, content_size, &mut element_state.interactive, - None, cx, |style, mut scroll_offset, cx| { let border = style.border_widths.to_pixels(cx.rem_size()); diff --git a/crates/gpui/src/geometry.rs b/crates/gpui/src/geometry.rs index 89e47994a3..d986f26be4 100644 --- a/crates/gpui/src/geometry.rs +++ b/crates/gpui/src/geometry.rs @@ -497,6 +497,20 @@ where } } +impl Add for Size +where + T: Add + Clone + Default + Debug, +{ + type Output = Size; + + fn add(self, rhs: Self) -> Self::Output { + Size { + width: self.width + rhs.width, + height: self.height + rhs.height, + } + } +} + impl Mul for Size where T: Mul + Clone + Default + Debug, diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 9b74ad7981..42428c04f8 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -755,7 +755,7 @@ impl Element for TerminalElement { self.register_mouse_listeners(origin, layout.mode, bounds, cx); self.interactivity - .paint(bounds, bounds.size, state, None, cx, |_, _, cx| { + .paint(bounds, bounds.size, state, cx, |_, _, cx| { cx.handle_input(&self.focus, terminal_input_handler); cx.on_key_event({