zed/crates/gpui/examples/uniform_list.rs
秦宇航 94b6d06a72
Some checks are pending
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
gpui: Add example for uniform_list (#17421)
GPUI: Add example for `uniform_list`

- Added example for `uniform_list`
  - Run `cargo run --example uniform_list`  to fire up the example
-
https://github.com/user-attachments/assets/bb554fbc-c097-4ce5-8077-782dc4c5c398

Release Notes:

- N/A


https://github.com/user-attachments/assets/bb554fbc-c097-4ce5-8077-782dc4c5c398

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
2024-09-05 14:24:10 -04:00

43 lines
1.3 KiB
Rust

use gpui::*;
struct UniformListExample {}
impl Render for UniformListExample {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
div().size_full().bg(rgb(0xffffff)).child(
uniform_list(cx.view().clone(), "entries", 50, |_this, range, _cx| {
let mut items = Vec::new();
for ix in range {
let item = ix + 1;
items.push(
div()
.id(ix)
.px_2()
.cursor_pointer()
.on_click(move |_event, _cx| {
println!("clicked Item {item:?}");
})
.child(format!("Item {item}")),
);
}
items
})
.h_full(),
)
}
}
fn main() {
App::new().run(|cx: &mut AppContext| {
let bounds = Bounds::centered(None, size(px(300.0), px(300.0)), cx);
cx.open_window(
WindowOptions {
window_bounds: Some(WindowBounds::Windowed(bounds)),
..Default::default()
},
|cx| cx.new_view(|_cx| UniformListExample {}),
)
.unwrap();
});
}