mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 21:29:35 +00:00
Merge pull request #9365 from dotCooCoo/fix/status-bar-rotation-angle
Status bar: the Rotation box shows an angle between the presets
This commit is contained in:
@@ -34,6 +34,9 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let angles: Vec<Entry<usize>> = ROTATE_VIEW_ANGLES.iter().enumerate().map(|(i, (label, _))| Entry::new(i, *label)).collect();
|
||||
let rotation = app.view().map_or(0.0, |v| v.rotation);
|
||||
let turned = ROTATE_VIEW_ANGLES.iter().position(|(_, a)| (rotation - a).abs() < 1e-9).unwrap_or(usize::MAX);
|
||||
// An angle between the presets, from the Rotate View tool or `view.rotate`, shows in whole degrees; adding 0.0
|
||||
// turns the -0 of a small negative angle into 0.
|
||||
let angle = format!("{}°", rotation.round() + 0.0);
|
||||
let shows: Vec<Entry<StatusBarShow>> =
|
||||
StatusBarShow::ALL.into_iter().map(|s| Entry::new(s, s.label()).checked(app.ui.status_bar_show == s)).collect();
|
||||
let unit = app.session.general_unit();
|
||||
@@ -74,7 +77,12 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
}
|
||||
Field::new(tl!("Rotation")).side(SideLabel::new().kind(LabelKind::Hidden)).show(ui, |ui, _| {
|
||||
// Entries are keyed by index: an angle is not a hashable value.
|
||||
rotate_to = Select::new(tl!("Rotation"), Bind::given(turned), &angles).look(SelectLook::Filled).show(ui).value().copied();
|
||||
rotate_to = Select::new(tl!("Rotation"), Bind::given(turned), &angles)
|
||||
.placeholder(angle.clone())
|
||||
.look(SelectLook::Filled)
|
||||
.show(ui)
|
||||
.value()
|
||||
.copied();
|
||||
});
|
||||
Divider::vertical().show(ui);
|
||||
for (icon, to, tip, enabled) in
|
||||
|
||||
@@ -716,6 +716,33 @@ fn the_status_bar_show_choice_is_checked_and_saved() {
|
||||
);
|
||||
}
|
||||
|
||||
/// The status bar's Rotation box shows the view's angle: a preset angle shows its row's label, an angle between the
|
||||
/// presets shows rounded to a whole degree, and a pick from the list still turns the view.
|
||||
#[test]
|
||||
fn the_status_bar_rotation_box_shows_the_view_angle() {
|
||||
let mut bar = status_readout_app();
|
||||
let rotation = |bar: &mut Shown, angle: f64| {
|
||||
bar.app().run("view.rotate", json!({ "angle": angle })).unwrap();
|
||||
let rotation = bar.settle().find("Rotation").unwrap_or_else(|| panic!("the status bar has the Rotation box"));
|
||||
let value = bar.tree().value_of(rotation.node).map(str::to_owned);
|
||||
(rotation, value)
|
||||
};
|
||||
for (angle, shown) in [(17.0, "17°"), (37.4, "37°"), (-0.3, "0°"), (-122.6, "-123°")] {
|
||||
let (_, value) = rotation(&mut bar, angle);
|
||||
assert_eq!(value.as_deref(), Some(shown), "the box at {angle}°");
|
||||
assert!(bar.texts().iter().any(|t| t.text == shown), "the box draws {shown}");
|
||||
}
|
||||
let (_, value) = rotation(&mut bar, 45.0);
|
||||
assert_eq!(value.as_deref(), Some("45°"));
|
||||
// From an angle between the presets, the list still turns the view to the row picked.
|
||||
let (opener, _) = rotation(&mut bar, 17.0);
|
||||
bar.click_on(&opener).settle();
|
||||
bar.click("-45°").settle();
|
||||
assert_eq!(bar.app().view().map(|v| v.rotation), Some(-45.0));
|
||||
let rotation = bar.find("Rotation").unwrap_or_else(|| panic!("the status bar has the Rotation box"));
|
||||
assert_eq!(bar.tree().value_of(rotation.node), Some("-45°"));
|
||||
}
|
||||
|
||||
/// While background work runs the status bar shows it where the message was, with the count of the jobs after the
|
||||
/// first, and the message of the work's result takes the same place when it ends. Screen readers find the progress.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user