mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Bind Perspective Grid Options to its live preferences
This commit is contained in:
1 parent
315c07fe9d
commit
a4fa9739c4
1 file changed
+39
-2
@@ -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<Param> {
|
||||
]
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user