gpui: Simplify uniform list API by removing entity param (#32480)

This PR also introduces `Context::processor`, a sibling of
`Context::listener` that takes a strong pointer to entity and allows for
a return result.

Release Notes:

- N/A

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Ben Kunkle 2025-06-10 13:50:57 -05:00 committed by GitHub
parent c55630889a
commit f567bb52ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 80 additions and 77 deletions

View file

@ -378,8 +378,6 @@ impl DataTable {
impl Render for DataTable {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let entity = cx.entity();
div()
.font_family(".SystemUIFont")
.bg(gpui::white())
@ -431,8 +429,10 @@ impl Render for DataTable {
.relative()
.size_full()
.child(
uniform_list(entity, "items", self.quotes.len(), {
move |this, range, _, _| {
uniform_list(
"items",
self.quotes.len(),
cx.processor(move |this, range: Range<usize>, _, _| {
this.visible_range = range.clone();
let mut items = Vec::with_capacity(range.end - range.start);
for i in range {
@ -441,8 +441,8 @@ impl Render for DataTable {
}
}
items
}
})
}),
)
.size_full()
.track_scroll(self.scroll_handle.clone()),
)

View file

@ -9,10 +9,9 @@ impl Render for UniformListExample {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
div().size_full().bg(rgb(0xffffff)).child(
uniform_list(
cx.entity().clone(),
"entries",
50,
|_this, range, _window, _cx| {
cx.processor(|_this, range, _window, _cx| {
let mut items = Vec::new();
for ix in range {
let item = ix + 1;
@ -29,7 +28,7 @@ impl Render for UniformListExample {
);
}
items
},
}),
)
.h_full(),
)