story: Add example for secondary click table row. (#780)

This commit is contained in:
Jason Lee 2025-04-09 13:42:08 +08:00 committed by GitHub
parent 206a1e049b
commit aaa88db52c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,8 +6,8 @@ use std::{
use fake::{Fake, Faker}; use fake::{Fake, Faker};
use gpui::{ use gpui::{
div, impl_internal_actions, prelude::FluentBuilder as _, px, AnyElement, App, AppContext, div, impl_internal_actions, prelude::FluentBuilder as _, px, AnyElement, App, AppContext,
Context, Edges, Entity, Focusable, InteractiveElement, IntoElement, ParentElement, Pixels, ClickEvent, Context, Edges, Entity, Focusable, InteractiveElement, IntoElement, ParentElement,
Render, SharedString, Styled, Timer, Window, Pixels, Render, SharedString, StatefulInteractiveElement, Styled, Timer, Window,
}; };
use gpui_component::{ use gpui_component::{
button::Button, button::Button,
@ -376,6 +376,22 @@ impl TableDelegate for StockTableDelegate {
.menu("Size XSmall", Box::new(ChangeSize(Size::XSmall))) .menu("Size XSmall", Box::new(ChangeSize(Size::XSmall)))
} }
fn render_tr(
&self,
row_ix: usize,
_: &mut Window,
cx: &mut Context<Table<Self>>,
) -> gpui::Stateful<gpui::Div> {
div()
.id(row_ix)
.on_click(cx.listener(|_, ev: &ClickEvent, _, _| {
println!(
"You have clicked row with secondary: {}",
ev.modifiers().secondary()
)
}))
}
/// NOTE: Performance metrics /// NOTE: Performance metrics
/// ///
/// last render 561 cells total: 232.745µs, avg: 414ns /// last render 561 cells total: 232.745µs, avg: 414ns