table: Improve render_tr to bind the context_menu (#347)
<img width="559" alt="image" src="https://github.com/user-attachments/assets/2aecfa35-5ee1-45cb-a3f3-2409bd09efd7">
This commit is contained in:
parent
6a5fff889e
commit
9b8240c6bc
2 changed files with 18 additions and 6 deletions
|
|
@ -10,6 +10,7 @@ use serde::Deserialize;
|
||||||
use ui::{
|
use ui::{
|
||||||
button::{Button, ButtonStyled},
|
button::{Button, ButtonStyled},
|
||||||
checkbox::Checkbox,
|
checkbox::Checkbox,
|
||||||
|
context_menu::ContextMenuExt,
|
||||||
h_flex,
|
h_flex,
|
||||||
indicator::Indicator,
|
indicator::Indicator,
|
||||||
input::{InputEvent, TextInput},
|
input::{InputEvent, TextInput},
|
||||||
|
|
@ -340,6 +341,19 @@ impl TableDelegate for StockTableDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_tr(
|
||||||
|
&self,
|
||||||
|
row_ix: usize,
|
||||||
|
_: &mut ViewContext<Table<Self>>,
|
||||||
|
) -> gpui::Stateful<gpui::Div> {
|
||||||
|
h_flex().id(("table-row", row_ix)).context_menu(|this, _| {
|
||||||
|
this.menu("Size Large", Box::new(ChangeSize(Size::Large)))
|
||||||
|
.menu("Size Medium", Box::new(ChangeSize(Size::Medium)))
|
||||||
|
.menu("Size Small", Box::new(ChangeSize(Size::Small)))
|
||||||
|
.menu("Size XSmall", Box::new(ChangeSize(Size::XSmall)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn render_td(
|
fn render_td(
|
||||||
&self,
|
&self,
|
||||||
row_ix: usize,
|
row_ix: usize,
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ use gpui::{
|
||||||
actions, canvas, div, prelude::FluentBuilder, px, uniform_list, AppContext, Bounds, Div,
|
actions, canvas, div, prelude::FluentBuilder, px, uniform_list, AppContext, Bounds, Div,
|
||||||
DragMoveEvent, Edges, Entity, EntityId, EventEmitter, FocusHandle, FocusableView,
|
DragMoveEvent, Edges, Entity, EntityId, EventEmitter, FocusHandle, FocusableView,
|
||||||
InteractiveElement, IntoElement, KeyBinding, MouseButton, ParentElement, Pixels, Point, Render,
|
InteractiveElement, IntoElement, KeyBinding, MouseButton, ParentElement, Pixels, Point, Render,
|
||||||
ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled, UniformListScrollHandle,
|
ScrollHandle, SharedString, Stateful, StatefulInteractiveElement as _, Styled,
|
||||||
ViewContext, VisualContext as _, WindowContext,
|
UniformListScrollHandle, ViewContext, VisualContext as _, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
|
|
@ -186,8 +186,8 @@ pub trait TableDelegate: Sized + 'static {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render the row at the given row and column.
|
/// Render the row at the given row and column.
|
||||||
fn render_tr(&self, row_ix: usize, cx: &mut ViewContext<Table<Self>>) -> Div {
|
fn render_tr(&self, row_ix: usize, cx: &mut ViewContext<Table<Self>>) -> Stateful<Div> {
|
||||||
h_flex()
|
h_flex().id(("table-row", row_ix))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render cell at the given row and column.
|
/// Render cell at the given row and column.
|
||||||
|
|
@ -942,7 +942,6 @@ where
|
||||||
if row_ix < rows_count {
|
if row_ix < rows_count {
|
||||||
self.delegate
|
self.delegate
|
||||||
.render_tr(row_ix, cx)
|
.render_tr(row_ix, cx)
|
||||||
.id(("table-row", row_ix))
|
|
||||||
.w_full()
|
.w_full()
|
||||||
.h(self.size.table_row_height())
|
.h(self.size.table_row_height())
|
||||||
.when(row_ix > 0, |this| {
|
.when(row_ix > 0, |this| {
|
||||||
|
|
@ -1008,7 +1007,6 @@ where
|
||||||
// Render fake rows to fill the rest table space
|
// Render fake rows to fill the rest table space
|
||||||
self.delegate
|
self.delegate
|
||||||
.render_tr(row_ix, cx)
|
.render_tr(row_ix, cx)
|
||||||
.id(("table-row-fake", row_ix))
|
|
||||||
.w_full()
|
.w_full()
|
||||||
.h_full()
|
.h_full()
|
||||||
.border_t_1()
|
.border_t_1()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue