fix(ui): disable alignment when the selection can't be aligned

One layer directly on the page has nothing to align to (one layer aligns
to its parent frame), so the six Alignment buttons looked active and did
nothing. They are now disabled there, with a hover explaining why.

- cmd/arrange.rs: align_target (unchanged rule) and pub can_align.
- right.rs: the align rows in add_enabled_ui + on_disabled_hover_text.
- The hover text in every catalog.

Tests: a_layer_alone_on_the_page_has_nothing_to_align_to (engine),
the_align_buttons_are_off_for_a_layer_alone_on_the_page (AccessKit).

Refs #256

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
RealtaNua
2026-10-14 16:53:33 +07:00
co-authored by Claude Opus 5.5
parent bcedfeba10
commit 9c0b441119
12 changed files with 69 additions and 15 deletions
+18 -11
View File
@@ -145,21 +145,28 @@ pub fn rotate_world(doc: &mut Document, id: NodeId, pivot: Point, deg: f64) -> R
Ok(())
}
/// Whether aligning `ids` would move anything: a layer alone on the page has nothing to align to.
pub fn can_align(doc: &Document, ids: &[NodeId]) -> bool {
align_target(doc, &roots(doc, ids)).is_some()
}
/// What `roots` align to: one layer to its parent frame, several to their combined bounds.
fn align_target(doc: &Document, roots: &[NodeId]) -> Option<Rect> {
match roots {
[] => None,
[id] => {
let parent = doc.node(*id)?.parent.filter(|pp| !doc.node(*pp).is_some_and(Node::is_page))?;
Some(doc.world_bounds(parent).unwrap_or_default())
}
_ => Some(doc.bounds_of(roots).unwrap_or_default()),
}
}
fn align(s: &mut Session, p: &Value, a: Al) -> Result<Value> {
let ids = req_targets("align", s, p)?;
let doc = s.doc_mut()?;
let ids = roots(doc, &ids);
// One layer aligns within its parent frame; several align to their combined bounds.
let target: Rect = if ids.len() == 1 {
let Some(id) = ids.first() else { return ok() };
let parent = doc.get(*id)?.parent;
match parent.filter(|pp| !doc.node(*pp).is_some_and(Node::is_page)) {
Some(pp) => doc.world_bounds(pp).unwrap_or_default(),
None => return ok(),
}
} else {
doc.bounds_of(&ids).unwrap_or_default()
};
let Some(target) = align_target(doc, &ids) else { return ok() };
for i in ids {
let Some(b) = doc.world_bounds(i) else { continue };
let (dx, dy) = match a {