From aaa88db52c8cd5b55ead81dc26c9638aef278709 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 9 Apr 2025 13:42:08 +0800 Subject: [PATCH] story: Add example for secondary click table row. (#780) --- crates/story/src/table_story.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/story/src/table_story.rs b/crates/story/src/table_story.rs index 1cf5a947..88f0865b 100644 --- a/crates/story/src/table_story.rs +++ b/crates/story/src/table_story.rs @@ -6,8 +6,8 @@ use std::{ use fake::{Fake, Faker}; use gpui::{ div, impl_internal_actions, prelude::FluentBuilder as _, px, AnyElement, App, AppContext, - Context, Edges, Entity, Focusable, InteractiveElement, IntoElement, ParentElement, Pixels, - Render, SharedString, Styled, Timer, Window, + ClickEvent, Context, Edges, Entity, Focusable, InteractiveElement, IntoElement, ParentElement, + Pixels, Render, SharedString, StatefulInteractiveElement, Styled, Timer, Window, }; use gpui_component::{ button::Button, @@ -376,6 +376,22 @@ impl TableDelegate for StockTableDelegate { .menu("Size XSmall", Box::new(ChangeSize(Size::XSmall))) } + fn render_tr( + &self, + row_ix: usize, + _: &mut Window, + cx: &mut Context>, + ) -> gpui::Stateful { + div() + .id(row_ix) + .on_click(cx.listener(|_, ev: &ClickEvent, _, _| { + println!( + "You have clicked row with secondary: {}", + ev.modifiers().secondary() + ) + })) + } + /// NOTE: Performance metrics /// /// last render 561 cells total: 232.745µs, avg: 414ns