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

This commit is contained in:
bflatastic
2026-11-22 22:36:12 +07:00
parent 368b3c9300
commit 5ad0e5288c
3 changed files with 29 additions and 26 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ pub(super) fn show_body<T: LayerTree>(
let parent_of = |id: &T::Id| tree.parent(id);
let ctx = ui.ctx().clone();
let list_id = cx.list;
let host_place = |at: &DropAt<LayerRowKey<T::Id>>| host_drop_place(&order, &parent_of, at);
let host_place = |at: &DropAt<LayerRowKey<T::Id>>| host_drop_place(order, &parent_of, at);
let mut list = List::new(cx.words.list.clone())
.id(cx.list)
+5 -10
View File
@@ -47,15 +47,14 @@ impl<Id: Clone + 'static, C: Show, B: Fn(&Id, &LayerInfo) -> 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<LayerRowKey<Id>>) -> 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<Id> {
/// `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<Id>>,
place: &'l dyn Fn(&DropAt<LayerRowKey<Id>>) -> Option<(Id, LayerPosition)>,
) -> List<'l, LayerRowKey<Id>>
fn kinds<'l>(&'l self, list: List<'l, LayerRowKey<Id>>, place: &'l HostPlace<'l, Id>) -> List<'l, LayerRowKey<Id>>
where
Id: Clone + Eq + std::hash::Hash + Send + Sync + 'static;
}
@@ -67,11 +66,7 @@ pub(super) struct HostDrop<P, A> {
}
impl<Id, P: Send + Sync + 'static, A: Fn(&P, &Id, LayerPosition) -> bool> HostDrops<Id> for HostDrop<P, A> {
fn kinds<'l>(
&'l self,
list: List<'l, LayerRowKey<Id>>,
place: &'l dyn Fn(&DropAt<LayerRowKey<Id>>) -> Option<(Id, LayerPosition)>,
) -> List<'l, LayerRowKey<Id>>
fn kinds<'l>(&'l self, list: List<'l, LayerRowKey<Id>>, place: &'l HostPlace<'l, Id>) -> List<'l, LayerRowKey<Id>>
where
Id: Clone + Eq + std::hash::Hash + Send + Sync + 'static,
{
+23 -15
View File
@@ -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 {