chore: reduce component overhead (#3)

Reviewed-on: reya/gpui-native-kit#3
This commit is contained in:
2026-11-09 10:09:56 +00:00
parent 6815585528
commit 1c091db699
44 changed files with 1376 additions and 1241 deletions
+98 -2
View File
@@ -38,7 +38,7 @@ impl Render for UniformShell {
.h_full()
.w_full(),
)
.child(Scrollbar::vertical(self.handle.clone())),
.child(Scrollbar::vertical("rows", self.handle.clone())),
)
}
}
@@ -64,7 +64,7 @@ impl Render for ListShell {
.h_full()
.w_full(),
)
.child(Scrollbar::vertical(self.state.clone())),
.child(Scrollbar::vertical("rows", self.state.clone())),
)
}
}
@@ -271,3 +271,99 @@ fn dragging_the_thumb_drives_a_list_state_and_reports_the_drag() {
"the drag ends with the mouse"
);
}
struct TwoShell {
left: UniformListScrollHandle,
right: UniformListScrollHandle,
}
impl Render for TwoShell {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div()
.size_full()
.flex()
.flex_row()
.child(
div()
.relative()
.h(px(VIEWPORT_HEIGHT))
.w(px(300.))
.child(
uniform_list("left-rows", ROWS, |range, _, _| {
range
.map(|ix| div().h(px(ROW_HEIGHT)).child(format!("row {ix}")))
.collect()
})
.track_scroll(&self.left)
.h_full()
.w_full(),
)
.child(Scrollbar::vertical("left", self.left.clone())),
)
.child(
div()
.relative()
.h(px(VIEWPORT_HEIGHT))
.w(px(300.))
.child(
uniform_list("right-rows", ROWS, |range, _, _| {
range
.map(|ix| div().h(px(ROW_HEIGHT)).child(format!("row {ix}")))
.collect()
})
.track_scroll(&self.right)
.h_full()
.w_full(),
)
.child(Scrollbar::vertical("right", self.right.clone())),
)
}
}
fn two_shell() -> (
TestAppContext,
VisualTestContext,
UniformListScrollHandle,
UniformListScrollHandle,
) {
let mut cx = TestAppContext::single();
cx.update(init);
let (left, right) = (
UniformListScrollHandle::new(),
UniformListScrollHandle::new(),
);
let (left_for_view, right_for_view) = (left.clone(), right.clone());
let window = cx.add_window(move |_, _| TwoShell {
left: left_for_view,
right: right_for_view,
});
let mut visual = VisualTestContext::from_window(window.into(), &cx);
visual.update(|window, cx| {
window.draw(cx).clear(cx);
});
(cx, visual, left, right)
}
/// Dragging one scrollbar's thumb must never move a sibling scrollbar: the
/// drag state is keyed per scrollbar id, not shared across instances.
#[test]
fn sibling_scrollbars_drag_independently() {
let (cx, mut visual, left, right) = two_shell();
let metrics = Metrics::measure(&cx, &left);
assert!(metrics.max_offset > px(0.));
press(&mut visual, metrics.thumb_center());
drag_to(&mut visual, metrics.full_drag_target());
release(&mut visual, metrics.full_drag_target());
let offset = left.offset().y;
assert!(
(offset.abs() - metrics.max_offset).abs() < px(0.5),
"the left drag reaches the end, got {offset}"
);
assert_eq!(
right.offset().y,
px(0.),
"the left drag leaked into the right scrollbar"
);
}