Artboard labels: one helper for the artboards the Artboard tool labels itself

This commit is contained in:
bflatastic
2026-10-30 00:15:54 +07:00
parent 7064969327
commit 148517f3eb
2 changed files with 15 additions and 19 deletions
+4 -8
View File
@@ -3,7 +3,7 @@
use egui::emath::GuiRounding as _;
use egui::{Color32, CornerRadius, Pos2, Sense, Shape, Stroke, StrokeKind, Ui, Vec2, pos2, vec2};
use serde_json::{Value, json};
use serde_json::json;
use vectorcraft_doc::text::TextKind;
use vectorcraft_doc::{Node, NodeKind, SymbolBoxes, Unit};
use vectorcraft_geom::{Affine, BezPath, PathEl, Point, Rect};
@@ -713,15 +713,11 @@ fn reproject_frame(app: &VectorcraftApp, painter: &egui::Painter, xf: &Xf, rect:
fn artboard_outlines(app: &VectorcraftApp, ui: &Ui, painter: &egui::Painter, xf: &Xf, t: &Tokens) {
let Some(st) = app.session.active() else { return };
let doc = &st.doc;
// Artboard edges and names. The Artboard tool labels its active artboard itself (following
// a move or resize): that one isn't named twice.
// Artboard edges and names. The Artboard tool labels its selected artboards itself (following
// a move or resize): those aren't named twice.
let active_ab = crate::panels::artboards::selected(app, doc.artboards.len());
let artboard_tool = app.session.tool_id() == "artboard";
let tool_selected: Vec<u64> = if artboard_tool {
app.session.tool_options()["selected"].as_array().map(|a| a.iter().filter_map(Value::as_u64).collect()).unwrap_or_default()
} else {
vec![]
};
let tool_selected = artboards::tool_labelled(app);
let editing_name = ui.data(|d| d.get_temp::<ArtboardNameEdit>(name_edit_id()).map(|e| e.index));
for (i, ab) in doc.artboards.iter().enumerate() {
let c = if i == active_ab { Color32::from_gray(0) } else { Color32::from_gray(120) };
+11 -11
View File
@@ -91,6 +91,15 @@ pub(super) fn tool_name_rect(painter: &egui::Painter, xf: &Xf, rect: Rect, index
egui::Rect::from_min_size(sp, galley.size()).expand(2.0)
}
/// The artboards the Artboard tool labels itself, following a move or resize (its selected
/// ones): the canvas doesn't name them again. Empty with another tool.
pub(super) fn tool_labelled(app: &VectorcraftApp) -> Vec<u64> {
if app.session.tool_id() != "artboard" {
return vec![];
}
app.session.tool_options()["selected"].as_array().map(|a| a.iter().filter_map(Value::as_u64).collect()).unwrap_or_default()
}
/// The artboard whose on-canvas name contains `screen`, if that name is being drawn.
pub(super) fn artboard_name_at(app: &VectorcraftApp, ui: &Ui, xf: &Xf, screen: Pos2) -> Option<usize> {
let st = app.session.active()?;
@@ -98,11 +107,7 @@ pub(super) fn artboard_name_at(app: &VectorcraftApp, ui: &Ui, xf: &Xf, screen: P
if !artboard_tool && st.doc.artboards.len() <= 1 {
return None;
}
let tool_selected: Vec<u64> = if artboard_tool {
app.session.tool_options()["selected"].as_array().map(|a| a.iter().filter_map(Value::as_u64).collect()).unwrap_or_default()
} else {
vec![]
};
let tool_selected = tool_labelled(app);
let painter = ui.painter();
let mut hit = None;
for (i, ab) in st.doc.artboards.iter().enumerate() {
@@ -207,12 +212,7 @@ pub(super) fn artboard_name_editor(app: &mut VectorcraftApp, ui: &mut Ui, xf: &X
pub(super) fn artboard_name_field_rect(app: &VectorcraftApp, ui: &Ui, xf: &Xf, index: usize) -> Option<egui::Rect> {
let st = app.session.active()?;
let ab = st.doc.artboards.get(index)?;
let artboard_tool = app.session.tool_id() == "artboard";
let tool_selected: Vec<u64> = if artboard_tool {
app.session.tool_options()["selected"].as_array().map(|a| a.iter().filter_map(Value::as_u64).collect()).unwrap_or_default()
} else {
vec![]
};
let tool_selected = tool_labelled(app);
let painter = ui.painter();
let is_tool_labelled = u64::try_from(index).ok().is_some_and(|idx| tool_selected.contains(&idx));
let rect = if is_tool_labelled {