Measure: copy button next to the Distance value (#4442)
This commit is contained in:
1 parent
6d8d53aac8
commit
2cab9dc142
2 files changed
+38
-1
No files matched your search
@@ -909,7 +909,21 @@ fn measure_rows(app: &SolveApp, ui: &mut egui::Ui, r: Option<&Value>, show: &mut
|
||||
}
|
||||
}
|
||||
} else {
|
||||
value(ui, crate::i18n::tr_label("Distance"), &crate::prefs::show_mm(app, d, 1));
|
||||
let text = crate::prefs::show_mm(app, d, 1);
|
||||
form_row(ui, crate::i18n::tr_label("Distance"), |ui| {
|
||||
let size = crate::theme::Tokens::get().form_close_size;
|
||||
// The value keeps the room left of the button, so the button stays inside the row.
|
||||
ui.scope(|ui| {
|
||||
ui.set_max_width((ui.available_width() - size).max(0.0));
|
||||
ui_kit::text(ui, &text, ui_kit::Text::Cell);
|
||||
});
|
||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(size, size), egui::Sense::hover());
|
||||
let copy = ui_kit::icon_button_at(ui, rect, "copy", crate::i18n::tr_label("Copy"));
|
||||
crate::scenario::publish_handle("measure:copy:distance", copy.rect.center());
|
||||
if copy.clicked() {
|
||||
ui.ctx().copy_text(text.clone());
|
||||
}
|
||||
});
|
||||
}
|
||||
let delta = b - a;
|
||||
for (l, v) in [("ΔX", delta.x), ("ΔY", delta.y), ("ΔZ", delta.z)] {
|
||||
|
||||
@@ -178,3 +178,26 @@ fn measurement_axis_distances_can_be_disabled_saved_and_restored_in_preferences(
|
||||
h.call("ui.prefs", json!({"button":"cancel"}));
|
||||
assert!(h.app.preferences.measure_axis_distances, "Cancel restores the last Apply");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_distance_row_has_a_copy_button_that_copies_the_shown_value() {
|
||||
let mut h = vertex_measurement([0., 0., 0.], [3., 4., 0.]);
|
||||
h.frames(4);
|
||||
let want = crate::prefs::show_mm(&h.app, 5.0, 1);
|
||||
assert!(crate::scenario::handle_at("measure:copy:distance").is_some(), "the Distance row publishes its copy button");
|
||||
let at = crate::scenario::handle_at("measure:copy:distance").unwrap_or_default();
|
||||
let (hover, _) = crate::control::ControlRequest::new("ui.move", json!({"x": f64::from(at.x), "y": f64::from(at.y)}));
|
||||
crate::control::handle(&mut h.app, &h.ctx, &hover);
|
||||
h.frames(2);
|
||||
let (request, _reply) = crate::control::ControlRequest::new("ui.click", json!({"x": f64::from(at.x), "y": f64::from(at.y)}));
|
||||
crate::control::handle(&mut h.app, &h.ctx, &request);
|
||||
let mut copied = Vec::new();
|
||||
for _ in 0..8 {
|
||||
h.frame();
|
||||
copied.extend(h.output.commands.iter().filter_map(|c| match c {
|
||||
egui::OutputCommand::CopyText(text) => Some(text.clone()),
|
||||
_ => None,
|
||||
}));
|
||||
}
|
||||
assert_eq!(copied, [want]);
|
||||
}
|
||||
Reference in new issue
Block a user