diff --git a/crates/ui-egui/src/dialogs/perspective_options.rs b/crates/ui-egui/src/dialogs/perspective_options.rs index 7db0191871..87d3269327 100644 --- a/crates/ui-egui/src/dialogs/perspective_options.rs +++ b/crates/ui-egui/src/dialogs/perspective_options.rs @@ -5,6 +5,7 @@ //! Fields: `show` (bool), `position` (`topLeft`, `topRight`, `bottomLeft`, `bottomRight`), //! `anchorPoint` (bool) and `gridlineIntersection` (bool). +use craft::ui::contract::Bind; use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, Param, ParamDialog, ParamKind}; use serde_json::{Value, json}; use vectorcraft_tools::distort::perspective::widget::WidgetCorner; @@ -31,8 +32,8 @@ fn params() -> Vec { ] } -fn build(_fields: &mut DialogFields) -> ParamDialog<'_> { - ParamDialog::new(KIND, tl!("Perspective Grid Options"), params()) +fn build(fields: &mut DialogFields) -> ParamDialog<'_> { + ParamDialog::new(KIND, tl!("Perspective Grid Options"), params()).values(Bind::bound(fields)) } /// Open the dialog with the current options. @@ -51,3 +52,39 @@ pub fn open(app: &mut VectorcraftApp) { app.status("no window".to_string()); } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::tests::{panel_harness::Panel, picks::dialogs}; + use craft::ui::contract::Role; + use vectorcraft_engine::Session; + + fn open_options(panel: &mut Panel) { + panel.app().run("tool.options", json!({"tool": "perspectiveGrid"})).unwrap(); + panel.frame(); + } + + #[test] + fn perspective_grid_options_show_and_apply_widget_preferences() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.session.prefs.perspective_widget.position = WidgetCorner::BottomRight; + let mut panel = Panel::new(app, dialogs); + open_options(&mut panel); + + assert_eq!(panel.value_role("Widget Position", Role::COMBO_BOX).as_deref(), Some("Bottom Right")); + panel.click_role("Widget Position", Role::COMBO_BOX); + panel.click("Top Right"); + panel.click("Intersection of Gridlines"); + panel.click("OK"); + let saved = panel.app().session.prefs.perspective_widget; + assert_eq!(saved.position, WidgetCorner::TopRight); + assert!(!saved.gridline_intersection); + + open_options(&mut panel); + assert_eq!(panel.value_role("Widget Position", Role::COMBO_BOX).as_deref(), Some("Top Right")); + panel.click("Show Active Plane Widget"); + panel.click("Cancel"); + assert_eq!(panel.app().session.prefs.perspective_widget, saved); + } +}