project panel: Fix rendering of groups of dragged project panel entries (#20686)

This PR introduces a new parameter for `on_drag` in gpui, which is an
offset from the element origin to the mouse event origin.

Release Notes:

- Fixed rendering of dragged project panel entries
This commit is contained in:
Piotr Osiewicz 2024-11-14 19:29:18 +01:00 committed by GitHub
parent 43999c47e1
commit 56c93be4de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 30 additions and 17 deletions

View file

@ -240,6 +240,7 @@ struct DraggedProjectEntryView {
selection: SelectedEntry,
details: EntryDetails,
width: Pixels,
click_offset: Point<Pixels>,
selections: Arc<BTreeSet<SelectedEntry>>,
}
@ -2681,10 +2682,11 @@ impl ProjectPanel {
},
))
})
.on_drag(dragged_selection, move |selection, cx| {
.on_drag(dragged_selection, move |selection, click_offset, cx| {
cx.new_view(|_| DraggedProjectEntryView {
details: details.clone(),
width,
click_offset,
selection: selection.active_selection,
selections: selection.marked_selections.clone(),
})
@ -3559,15 +3561,21 @@ impl Render for DraggedProjectEntryView {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let settings = ProjectPanelSettings::get_global(cx);
let ui_font = ThemeSettings::get_global(cx).ui_font.clone();
h_flex().font(ui_font).map(|this| {
if self.selections.contains(&self.selection) {
this.flex_shrink()
.p_1()
.items_end()
.rounded_md()
.child(self.selections.len().to_string())
if self.selections.len() > 1 && self.selections.contains(&self.selection) {
this.flex_none()
.w(self.width)
.child(div().w(self.click_offset.x))
.child(
div()
.p_1()
.rounded_xl()
.bg(cx.theme().colors().background)
.child(Label::new(format!("{} entries", self.selections.len()))),
)
} else {
this.bg(cx.theme().colors().background).w(self.width).child(
this.w(self.width).bg(cx.theme().colors().background).child(
ListItem::new(self.selection.entry_id.to_proto() as usize)
.indent_level(self.details.depth)
.indent_step_size(px(settings.indent_size))