forked from reya/gpui-native-kit
fix: exclude scroll area padding from pane sizing
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use gpui::{
|
||||
Context, IntoElement, Modifiers, ParentElement as _, Render, ScrollDelta, ScrollEvent,
|
||||
ScrollHandle, SharedString, Styled as _, TestAppContext, VisualTestContext, Window, div, point,
|
||||
px,
|
||||
Context, InteractiveElement as _, IntoElement, Modifiers, ParentElement as _, Render,
|
||||
ScrollDelta, ScrollEvent, ScrollHandle, SharedString, Styled as _, TestAppContext,
|
||||
VisualTestContext, Window, div, point, px,
|
||||
};
|
||||
use gpui_native_core::scroll_area::ScrollArea;
|
||||
use gpui_native_theme::Theme;
|
||||
@@ -116,6 +116,53 @@ impl Render for GalleryShell {
|
||||
}
|
||||
}
|
||||
|
||||
/// A window-filling scroll area with `p_4`, over one full-width row.
|
||||
struct PaddedShell {
|
||||
scroll: ScrollHandle,
|
||||
}
|
||||
|
||||
impl Render for PaddedShell {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.size_full()
|
||||
.debug_selector(|| "padded-root".to_string())
|
||||
.child(
|
||||
ScrollArea::new("padded-scroll")
|
||||
.handle(self.scroll.clone())
|
||||
.size_full()
|
||||
.p_4()
|
||||
.child(
|
||||
div()
|
||||
.debug_selector(|| "padded-row".to_string())
|
||||
.h(px(20.))
|
||||
.w_full(),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn padding_insets_the_content_exactly_once() {
|
||||
let mut cx = TestAppContext::single();
|
||||
cx.update(Theme::init);
|
||||
let handle = ScrollHandle::new();
|
||||
let handle_for_view = handle.clone();
|
||||
let window = cx.add_window(move |_, _| PaddedShell {
|
||||
scroll: handle_for_view,
|
||||
});
|
||||
let mut visual = VisualTestContext::from_window(window.into(), &cx);
|
||||
visual.update(|window, cx| {
|
||||
window.draw(cx).clear(cx);
|
||||
});
|
||||
|
||||
let root = visual.debug_bounds("padded-root").expect("root rendered");
|
||||
let row = visual.debug_bounds("padded-row").expect("row rendered");
|
||||
// p_4 = 16px: the padding reaches only the wrapper, so the content is
|
||||
// inset once, not once per wrapper and scroll pane.
|
||||
assert_eq!(row.origin.x - root.origin.x, px(16.));
|
||||
assert_eq!(root.size.width - row.size.width, px(32.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_gallery_style_window_fill_scroll_area_scrolls_tall_flex_content() {
|
||||
let mut cx = TestAppContext::single();
|
||||
|
||||
Reference in New Issue
Block a user