mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-24 10:27:00 -06:00
#766: keep the label rename in layers::Rename like the layers panel
This commit is contained in:
@@ -108,7 +108,7 @@ fn double_clicking_a_label_renames_the_frame_there() {
|
||||
let before = u.app.session.doc().unwrap().world_bounds(a).unwrap();
|
||||
double_click_label(&mut u, a);
|
||||
assert_eq!(u.app.session.selection(), vec![a]);
|
||||
assert_eq!(u.app.ui.rename_label.map(|r| r.0), Some(a), "a field over the label");
|
||||
assert_eq!(u.app.ui.rename_label.map(|r| r.id), Some(a), "a field over the label");
|
||||
// The name starts selected: typing replaces it, Enter keeps it.
|
||||
u.frame(vec![Event::Text("Sign in".into())]);
|
||||
u.frame(key(egui::Key::Enter));
|
||||
@@ -127,7 +127,7 @@ fn double_clicking_a_label_renames_the_frame_there() {
|
||||
fn escape_leaves_a_label_rename_with_the_old_name() {
|
||||
let (mut u, _, b) = setup();
|
||||
double_click_label(&mut u, b);
|
||||
assert_eq!(u.app.ui.rename_label.map(|r| r.0), Some(b), "rotated labels rename too");
|
||||
assert_eq!(u.app.ui.rename_label.map(|r| r.id), Some(b), "rotated labels rename too");
|
||||
u.frame(vec![Event::Text("Nope".into())]);
|
||||
u.frame(key(egui::Key::Escape));
|
||||
u.frame(vec![]);
|
||||
|
||||
@@ -151,18 +151,13 @@ pub fn draw(app: &FigApp, painter: &Painter, t: &Tokens, doc: &Document, id: Nod
|
||||
Some([area.left_top(), area.right_top(), area.right_bottom(), area.left_bottom()].map(|p| tl + rot * (p - tl)))
|
||||
}
|
||||
|
||||
/// Rename `id`'s name label on the canvas: a field over the label from the next frame on.
|
||||
pub fn start_rename(app: &mut FigApp, id: NodeId) {
|
||||
// The field takes the focus once it's drawn (as the pages list does).
|
||||
app.ui.rename_label = Some((id, true));
|
||||
}
|
||||
|
||||
/// The field over a label being renamed (see [`start_rename`]): Enter or a click elsewhere
|
||||
/// renames the layer, Escape keeps the name.
|
||||
/// The field over a frame's or section's name label being renamed (`UiState::rename_label`, from a
|
||||
/// double-click on the label): Enter or a click elsewhere renames the layer, Escape keeps the name.
|
||||
/// The rename ends when the field lets go of the keyboard or the label is gone.
|
||||
pub fn rename_field(app: &mut FigApp, ui: &mut egui::Ui) {
|
||||
let Some((id, start)) = app.ui.rename_label else { return };
|
||||
let quad = app.session.tool.labels.iter().find(|(i, _)| *i == id).map(|(_, q)| q.map(|p| app.to_screen(p.x, p.y)));
|
||||
let name = app.session.doc().ok().and_then(|d| d.node(id)).map(|n| n.name.clone());
|
||||
let Some(r) = app.ui.rename_label else { return };
|
||||
let quad = app.session.tool.labels.iter().find(|(i, _)| *i == r.id).map(|(_, q)| q.map(|p| app.to_screen(p.x, p.y)));
|
||||
let name = app.session.doc().ok().and_then(|d| d.node(r.id)).map(|n| n.name.clone());
|
||||
let (Some(quad), Some(name)) = (quad, name) else {
|
||||
app.ui.rename_label = None;
|
||||
return;
|
||||
@@ -171,14 +166,10 @@ pub fn rename_field(app: &mut FigApp, ui: &mut egui::Ui) {
|
||||
let font = regular(11.0);
|
||||
let text_w = ui.painter().layout_no_wrap(name.clone(), font.clone(), Color32::WHITE).size().x;
|
||||
let rect = Rect::from_min_size(pos2(area.min.x, area.max.y - 16.0), vec2((text_w + 24.0).max(area.width()).clamp(80.0, 480.0), 16.0));
|
||||
let (done, open) = crate::widgets::rename_field(ui, egui::Id::new(("frame_label_rename", id)), &name, rect, font, start);
|
||||
let (done, open) = crate::widgets::rename_field(ui, egui::Id::new(("frame_label_rename", r.id)), &name, rect, font, r.start);
|
||||
app.ui.rename_label = open.then_some(crate::layers::Rename { id: r.id, start: false });
|
||||
if let Some(new) = done {
|
||||
app.ui.rename_label = None;
|
||||
app.run("object.rename", serde_json::json!({"ids": [id], "name": new}));
|
||||
} else if !open && !start {
|
||||
app.ui.rename_label = None;
|
||||
} else {
|
||||
app.ui.rename_label = Some((id, false));
|
||||
app.run("object.rename", serde_json::json!({"ids": [r.id], "name": new}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -430,9 +430,8 @@ pub struct UiState {
|
||||
/// The layer being renamed in the layers panel.
|
||||
pub rename: Option<layers::Rename>,
|
||||
pub rename_page: Option<(NodeId, String)>,
|
||||
/// The frame or section whose name label on the canvas is being renamed (a double-click on
|
||||
/// it), and whether the rename just started (its field takes the keyboard when next drawn).
|
||||
pub rename_label: Option<(NodeId, bool)>,
|
||||
/// The frame or section whose name label on the canvas is being renamed (a double-click on it).
|
||||
pub rename_label: Option<layers::Rename>,
|
||||
pub main_menu: bool,
|
||||
pub palette: Option<String>,
|
||||
/// The Actions palette's tab.
|
||||
@@ -966,9 +965,7 @@ impl FigApp {
|
||||
"contextMenu" => self.ui.key_menu = true,
|
||||
"selectArea" => self.start_key_box(),
|
||||
"canvas.renameLabel" => {
|
||||
if let Some(id) = r.data.get("id").and_then(figcraft_engine::params::id_of) {
|
||||
frame_labels::start_rename(self, id);
|
||||
}
|
||||
self.ui.rename_label = r.data.get("id").and_then(figcraft_engine::params::id_of).map(|id| layers::Rename { id, start: true });
|
||||
}
|
||||
"layers.rename" => {
|
||||
let ids: Vec<NodeId> =
|
||||
|
||||
Reference in New Issue
Block a user