Merge pull request #8757 from Hassan1305/fix-8711-layers-target-ring

Layers: keep the targeted ring visible around the appearance dot (#8711)
This commit is contained in:
BFlat
2026-11-20 07:16:03 +07:00
committed by GitHub
5 changed files with 94 additions and 12 deletions
+27 -6
View File
@@ -926,8 +926,28 @@ fn shows_targeted(view: &View, n: &Node, is_sel: bool) -> bool {
}
}
/// The target circle of `n`'s row at `c`: a ring, doubled while `n` is targeted, filled when `n`
/// has an appearance or transparency of its own. Its response is clicked to target `n`; dragging
/// The radius of the inner ring of a targeted item's target circle (the double ring); the outer
/// ring's radius is 5.
pub(super) const TARGET_RING: f32 = 2.8;
/// The width of the inner ring.
pub(super) const TARGET_STROKE: f32 = 1.0;
/// The radius of the dot filling the circle of an item that has an appearance of its own and is
/// not targeted.
pub(super) const TARGET_DOT: f32 = 3.2;
/// The radius of that dot inside a targeted item's inner ring: clear of the ring, so a targeted
/// item with an appearance of its own shows both (#8711).
pub(super) const TARGET_DOT_IN_RING: f32 = 1.5;
/// The marks inside a target circle's outer ring: the inner ring's radius when the item is
/// `targeted`, and the appearance dot's radius when it is `styled` (has an appearance of its own).
/// Each of the four combinations looks different, as the Layers panel's target icons do.
pub(super) fn target_marks(targeted: bool, styled: bool) -> (Option<f32>, Option<f32>) {
let dot = if targeted { TARGET_DOT_IN_RING } else { TARGET_DOT };
(targeted.then_some(TARGET_RING), styled.then_some(dot))
}
/// The target circle of `n`'s row at `c`: a ring, doubled while `n` is targeted, with a dot when
/// `n` has an appearance or transparency of its own ([`target_marks`]). Its response is clicked to target `n`; dragging
/// it carries `n`'s appearance ([`PanelDrag::Appearance`]) onto another row's circle (Alt
/// copies it) or the trash.
fn target_circle(ui: &mut Ui, n: &Node, c: egui::Pos2, h: f32, targeted: bool, actions: &mut Vec<(String, Value)>, t: &Tokens) -> egui::Response {
@@ -946,11 +966,12 @@ fn target_circle(ui: &mut Ui, n: &Node, c: egui::Pos2, h: f32, targeted: bool, a
}
let ring = if held { t.accent } else { t.icon };
ui.painter().circle_stroke(c, 5.0, Stroke::new(if held { 1.5 } else { 1.0 }, ring));
if targeted {
ui.painter().circle_stroke(c, 2.8, Stroke::new(1.0, t.icon));
let (inner, dot) = target_marks(targeted, has_styled_target(n));
if let Some(r) = inner {
ui.painter().circle_stroke(c, r, Stroke::new(TARGET_STROKE, t.icon));
}
if has_styled_target(n) {
ui.painter().circle_filled(c, 3.2, t.icon);
if let Some(r) = dot {
ui.painter().circle_filled(c, r, t.icon);
}
if resp.dragged_by(egui::PointerButton::Primary) {
ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing);
+58 -2
View File
@@ -7,7 +7,8 @@ use super::*;
fn filled_targets(app: &mut VectorcraftApp, ctx: &egui::Context) -> usize {
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| show(app, ui));
out.textures_delta.clear();
out.shapes.iter().filter(|c| matches!(&c.shape, egui::Shape::Circle(cs) if cs.radius == 3.2 && cs.fill != Color32::TRANSPARENT)).count()
let dot = |r: f32| r == rows::TARGET_DOT || r == rows::TARGET_DOT_IN_RING;
out.shapes.iter().filter(|c| matches!(&c.shape, egui::Shape::Circle(cs) if dot(cs.radius) && cs.fill != Color32::TRANSPARENT)).count()
}
/// A generated `<Kind>` name is translated where painted; an unnamed text object's text never
@@ -417,12 +418,67 @@ fn targeted_rows(app: &mut VectorcraftApp, ctx: &egui::Context) -> Vec<usize> {
let rings: Vec<egui::Pos2> = out
.shapes
.iter()
.filter(|c| matches!(&c.shape, egui::Shape::Circle(cs) if cs.radius == 2.8))
.filter(|c| matches!(&c.shape, egui::Shape::Circle(cs) if cs.radius == rows::TARGET_RING))
.map(|c| c.shape.visual_bounding_rect().center())
.collect();
circles.iter().enumerate().filter(|(_, c)| rings.iter().any(|r| r.distance(**c) < 0.5)).map(|(i, _)| i).collect()
}
/// The marks one headless frame paints inside the outer ring of each target circle, top row
/// first: per circle, its (radius, fill, stroke width) circles, sorted by radius.
fn target_marks_painted(app: &mut VectorcraftApp, ctx: &egui::Context) -> Vec<Vec<(f32, bool, f32)>> {
let (circles, _) = frame(app, ctx, vec![], false);
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| show(app, ui));
out.textures_delta.clear();
circles
.iter()
.map(|c| {
let mut marks: Vec<(f32, bool, f32)> = out
.shapes
.iter()
.filter_map(|s| match &s.shape {
egui::Shape::Circle(cs) if cs.radius < 5.0 && cs.center.distance(*c) < 0.01 => {
Some((cs.radius, cs.fill != Color32::TRANSPARENT, cs.stroke.width))
}
_ => None,
})
.collect();
marks.sort_by(|a, b| a.0.total_cmp(&b.0));
marks
})
.collect()
}
/// A targeted item with an appearance of its own keeps its inner ring in view: the appearance
/// dot sits inside the ring with a gap, so the four looks (neither, targeted, with an appearance,
/// both) differ, as the target icons the Appearance attributes help describes do (#8711).
#[test]
fn a_targeted_circle_with_an_appearance_shows_both_ring_and_dot() {
let (mut app, _layer, [a, b]) = two_rects();
app.session.execute("transparency.set", &json!({"ids": [a.0], "opacity": 30})).unwrap();
let ctx = egui::Context::default();
// Rows top down: the layer, b, a.
let marks = target_marks_painted(&mut app, &ctx);
assert_eq!(marks.len(), 3);
let (neither, styled) = (marks[1].clone(), marks[2].clone());
app.session.execute("layer.target", &json!({"id": b.0})).unwrap();
let targeted = target_marks_painted(&mut app, &ctx)[1].clone();
app.session.execute("layer.target", &json!({"id": a.0})).unwrap();
let both = target_marks_painted(&mut app, &ctx)[2].clone();
// The inner ring is painted, and nothing filled reaches its inner edge.
let ring = both.iter().find(|m| m.0 == rows::TARGET_RING && !m.1).expect("the inner ring");
let inner_edge = ring.0 - ring.2 / 2.0;
let dot = both.iter().find(|m| m.1).expect("the appearance dot");
assert!(dot.0 + dot.2 / 2.0 < inner_edge - 0.5, "the dot {dot:?} covers the ring {ring:?}");
let looks = [&neither, &targeted, &styled, &both];
for (i, x) in looks.iter().enumerate() {
for y in &looks[i + 1..] {
assert_ne!(x, y, "two states look the same: {looks:?}");
}
}
assert_eq!(neither, vec![]);
}
/// A layer added to the selection from its target circle shows as targeted, as an object added
/// the same way does (#8646): with nothing targeted, a layer's circle shows its inner ring while
/// all of its visible, unlocked art is selected, and not while only part of it is.
+3 -2
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -1
View File
File diff suppressed because one or more lines are too long