mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Layers panel: a hidden layer's eye box stays empty under the pointer (photocraft#16321)
A list toggle cell drew its off icon under the pointer, so hiding a layer showed a crossed-out eye in its box until the pointer left. The reference application leaves a hidden layer's box empty in every state. ToggleCell gains `empty_off()`, which never draws the off icon, and the Layers panel's layer and sub-row eye cells use it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6e5490edc3
commit
7843e29364
@@ -249,7 +249,8 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR
|
||||
let contents = cx.options.thumbnail_contents;
|
||||
let active = cx.selection.active.as_ref() == Some(id);
|
||||
|
||||
let mut eye = ToggleCell::eye(EYE, info.visible).name(named(&words.visibility, &info.name));
|
||||
// A hidden layer's eye box stays empty, also under the pointer (the reference application, photocraft#16321).
|
||||
let mut eye = ToggleCell::eye(EYE, info.visible).empty_off().name(named(&words.visibility, &info.name));
|
||||
if let Some(color) = info.label {
|
||||
eye = eye.fill(DataColor::new(paint_color(color.fill())));
|
||||
}
|
||||
@@ -369,7 +370,7 @@ fn sub_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id, group: Sub
|
||||
row = row.ink(RowInk::Dimmed);
|
||||
}
|
||||
if sub.eye_shown {
|
||||
row = row.toggle(ToggleCell::eye(EYE, sub.on).name(named(&words.visibility, &sub.label)));
|
||||
row = row.toggle(ToggleCell::eye(EYE, sub.on).empty_off().name(named(&words.visibility, &sub.label)));
|
||||
}
|
||||
let size = cx.options.thumbnail_size;
|
||||
let header_mask = group == SubRowGroup::SmartFilters && index.is_none() && sub.mask && size != ThumbSize::None;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
pub(crate) mod blend_rows;
|
||||
pub(crate) mod comps;
|
||||
pub(crate) mod panel_drag_menu;
|
||||
pub(crate) mod panel_eye;
|
||||
pub(crate) mod panel_filter;
|
||||
pub(crate) mod panel_input;
|
||||
pub(crate) mod panel_memo;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
//! `LayersPanel` eye boxes: a hidden layer's box stays empty, also under the pointer (photocraft#16321).
|
||||
|
||||
use craft_layers::ui::mock::FakeLayers;
|
||||
use craft_layers::ui::panel::LayersPanel;
|
||||
use craft_layers::ui::tree::{LayerInfo, LayerKind};
|
||||
use craft_ui::contract::Tracked;
|
||||
use craft_ui::testing::{Fixture, pointer, trial};
|
||||
use egui::{Rect, Vec2};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// A visible layer over a hidden one.
|
||||
fn rig() -> Fixture {
|
||||
let mut tree = FakeLayers::default();
|
||||
tree.add(None, LayerInfo::new("Shown", LayerKind::Pixel), false);
|
||||
let mut hidden = LayerInfo::new("Hidden", LayerKind::Pixel);
|
||||
hidden.visible = false;
|
||||
tree.add(None, hidden, false);
|
||||
let tree = Rc::new(RefCell::new(Tracked::new(tree)));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let tree = tree.borrow();
|
||||
let _ = LayersPanel::new(&tree).show(ui);
|
||||
});
|
||||
fixture.room(Vec2::new(420.0, 560.0));
|
||||
fixture.settle();
|
||||
fixture
|
||||
}
|
||||
|
||||
/// How many shapes the frame paints wholly inside the eye box `cell`: its icon, not the row's fill around it.
|
||||
fn drawn_in(fixture: &mut Fixture, cell: Rect) -> usize {
|
||||
fixture.frame_shapes().iter().filter(|shape| cell.contains_rect(shape.visual_bounding_rect())).count()
|
||||
}
|
||||
|
||||
/// The pointer over a hidden layer's eye box draws nothing there (no crossed-out eye), while a visible layer's box
|
||||
/// under the pointer draws its eye.
|
||||
#[trial]
|
||||
fn a_hidden_layers_eye_box_stays_empty_under_the_pointer() {
|
||||
let mut fixture = rig();
|
||||
let shown = fixture.by_label("Visibility Shown").unwrap_or_else(|| panic!("no eye box for Shown")).rect;
|
||||
let hidden = fixture.by_label("Visibility Hidden").unwrap_or_else(|| panic!("no eye box for Hidden")).rect;
|
||||
|
||||
fixture.frame(vec![pointer::moved(shown.center())]).idle(2);
|
||||
assert!(drawn_in(&mut fixture, shown) > 0, "the visible layer's eye is drawn");
|
||||
|
||||
fixture.frame(vec![pointer::moved(hidden.center())]).idle(2);
|
||||
assert_eq!(drawn_in(&mut fixture, hidden), 0, "the hidden layer's box stays empty under the pointer");
|
||||
}
|
||||
@@ -91,7 +91,7 @@ impl ListRow<'_> {
|
||||
ToggleFace::Icons { on, off } => {
|
||||
let shown = match toggle.state {
|
||||
ToggleState::On | ToggleState::Mixed => Some(on),
|
||||
ToggleState::Off if toggle.always_visible || cx.part(part).hovered => Some(off),
|
||||
ToggleState::Off if toggle.shows_off(cx.part(part).hovered) => Some(off),
|
||||
ToggleState::Off => None,
|
||||
};
|
||||
if let Some(id) = shown {
|
||||
|
||||
@@ -80,6 +80,9 @@ pub struct ToggleCell {
|
||||
pub fill: Option<DataColor>,
|
||||
/// The off icon shows in every row, not only under the pointer. No effect on a check face.
|
||||
pub always_visible: bool,
|
||||
/// The off icon never shows, also under the pointer: an off cell stays empty (a hidden layer's eye box). Wins
|
||||
/// over `always_visible`. No effect on a check face.
|
||||
pub empty_off: bool,
|
||||
/// A screen reader announces a check box instead of a toggle button: for a setting the row carries rather than
|
||||
/// an action on the row.
|
||||
pub check_box: bool,
|
||||
@@ -99,6 +102,7 @@ impl ToggleCell {
|
||||
tooltip: None,
|
||||
fill: None,
|
||||
always_visible: false,
|
||||
empty_off: false,
|
||||
check_box: false,
|
||||
row_press: false,
|
||||
}
|
||||
@@ -162,10 +166,37 @@ impl ToggleCell {
|
||||
self
|
||||
}
|
||||
|
||||
/// The off icon never shows, also under the pointer: an off cell stays an empty box.
|
||||
#[must_use]
|
||||
pub fn empty_off(mut self) -> Self {
|
||||
self.empty_off = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// A press on the row's own area shows on the cell, for a row whose click turns on what the cell shows.
|
||||
#[must_use]
|
||||
pub fn row_press(mut self) -> Self {
|
||||
self.row_press = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether an off cell draws its off icon, under the pointer when `hovered`.
|
||||
pub(super) fn shows_off(&self, hovered: bool) -> bool {
|
||||
!self.empty_off && (self.always_visible || hovered)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn an_empty_off_cell_never_draws_its_off_icon() {
|
||||
let eye = ToggleCell::eye(ColumnKey::new("eye"), false);
|
||||
assert!(!eye.shows_off(false) && eye.shows_off(true), "a plain off cell shows its off icon only under the pointer");
|
||||
assert!(eye.clone().always_visible().shows_off(false), "always_visible shows it in every row");
|
||||
let empty = eye.empty_off();
|
||||
assert!(!empty.shows_off(true), "an empty_off cell stays empty under the pointer");
|
||||
assert!(!empty.always_visible().shows_off(true), "empty_off wins over always_visible");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user