From 5ad0e5288cb57b00695a1ee1dc337f5fa7f247b3 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sun, 22 Nov 2026 22:36:12 +0700 Subject: [PATCH] layers: clippy 1.100 clean: the row's eye and lock cells in with_toggles; host drop place and footer types named; no needless borrow --- crates/layers/src/ui/panel/body.rs | 2 +- crates/layers/src/ui/panel/context.rs | 15 ++++------- crates/layers/src/ui/panel/row.rs | 38 ++++++++++++++++----------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/crates/layers/src/ui/panel/body.rs b/crates/layers/src/ui/panel/body.rs index cc3b265e36..5dd7413c9b 100644 --- a/crates/layers/src/ui/panel/body.rs +++ b/crates/layers/src/ui/panel/body.rs @@ -65,7 +65,7 @@ pub(super) fn show_body( let parent_of = |id: &T::Id| tree.parent(id); let ctx = ui.ctx().clone(); let list_id = cx.list; - let host_place = |at: &DropAt>| host_drop_place(&order, &parent_of, at); + let host_place = |at: &DropAt>| host_drop_place(order, &parent_of, at); let mut list = List::new(cx.words.list.clone()) .id(cx.list) diff --git a/crates/layers/src/ui/panel/context.rs b/crates/layers/src/ui/panel/context.rs index 35a7913166..89687d20e7 100644 --- a/crates/layers/src/ui/panel/context.rs +++ b/crates/layers/src/ui/panel/context.rs @@ -47,15 +47,14 @@ impl C, O: FnMut(&Id, C: } } +/// Where a drop at a row or gap lands among the layers, when it lands on a place the host may take. +pub(super) type HostPlace<'l, Id> = dyn Fn(&DropAt>) -> Option<(Id, LayerPosition)> + 'l; + /// The host's payload type dragged from outside the rows (`LayersPanel::takes_drop`), with its type erased so the panel /// holds one. pub(super) trait HostDrops { /// `list` taking the payload between rows and onto them where `place` names a layer place the host accepts. - fn kinds<'l>( - &'l self, - list: List<'l, LayerRowKey>, - place: &'l dyn Fn(&DropAt>) -> Option<(Id, LayerPosition)>, - ) -> List<'l, LayerRowKey> + fn kinds<'l>(&'l self, list: List<'l, LayerRowKey>, place: &'l HostPlace<'l, Id>) -> List<'l, LayerRowKey> where Id: Clone + Eq + std::hash::Hash + Send + Sync + 'static; } @@ -67,11 +66,7 @@ pub(super) struct HostDrop { } impl bool> HostDrops for HostDrop { - fn kinds<'l>( - &'l self, - list: List<'l, LayerRowKey>, - place: &'l dyn Fn(&DropAt>) -> Option<(Id, LayerPosition)>, - ) -> List<'l, LayerRowKey> + fn kinds<'l>(&'l self, list: List<'l, LayerRowKey>, place: &'l HostPlace<'l, Id>) -> List<'l, LayerRowKey> where Id: Clone + Eq + std::hash::Hash + Send + Sync + 'static, { diff --git a/crates/layers/src/ui/panel/row.rs b/crates/layers/src/ui/panel/row.rs index 38e28c11d7..d3c7d9d007 100644 --- a/crates/layers/src/ui/panel/row.rs +++ b/crates/layers/src/ui/panel/row.rs @@ -247,6 +247,28 @@ fn paint_mask_marks(painter: &ContentPainterCx<'_>, rect: Rect, mask: &MaskInfo, } } +/// `row` with the layer's eye cell, its icon by the layer's view and filled with its label colour unless the row shows +/// a colour bar (`bar`), then its lock cell when the panel shows the lock column. +fn with_toggles<'r, T: LayerTree>(cx: &PanelContext<'_, T>, info: &LayerInfo, row: ListRow<'r>, bar: bool) -> ListRow<'r> { + let words = cx.words; + let on = match info.view { + LayerView::Preview => "eye", + LayerView::Outline => "eye_outline", + LayerView::Template => "layer_template", + }; + let face = ToggleFace::icons(IconId::new(on), IconId::new("eye_off")); + // A hidden layer's eye box stays empty, also under the pointer (the reference application, photocraft#16321). + let mut eye = ToggleCell::new(EYE, face, ToggleState::of(info.visible), named(&words.visibility, &info.name)).empty_off(); + if !bar && let Some(color) = info.label { + eye = eye.fill(DataColor::new(paint_color(color.fill()))); + } + let mut row = row.toggle(eye); + if cx.lock_column { + row = row.toggle(ToggleCell::lock(LOCK, info.locks.any()).name(named(&words.lock_cell, &info.name))); + } + row +} + fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListRow<'r> { let info = cx.tree.info(id); let words = cx.words; @@ -260,21 +282,7 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR let mut row = ListRow::new(info.name.clone()).layer(true); if !spine { - let on = match info.view { - LayerView::Preview => "eye", - LayerView::Outline => "eye_outline", - LayerView::Template => "layer_template", - }; - let face = ToggleFace::icons(IconId::new(on), IconId::new("eye_off")); - // A hidden layer's eye box stays empty, also under the pointer (the reference application, photocraft#16321). - let mut eye = ToggleCell::new(EYE, face, ToggleState::of(info.visible), named(&words.visibility, &info.name)).empty_off(); - if !bar && let Some(color) = info.label { - eye = eye.fill(DataColor::new(paint_color(color.fill()))); - } - row = row.toggle(eye); - if cx.lock_column { - row = row.toggle(ToggleCell::lock(LOCK, info.locks.any()).name(named(&words.lock_cell, &info.name))); - } + row = with_toggles(cx, &info, row, bar); } row = row.clipped(info.clipped).highlight(cx.tree.hovered().as_ref() == Some(id)).italic(info.italic).underline(info.underline); if bar {