sim_lib_view/
universal.rs1use std::sync::Arc;
7
8use sim_kernel::Symbol;
9use sim_shape::{AnyShape, shape_value};
10
11use crate::contract::{Lens, LensKind, LensMeta};
12use crate::dispatch::LensRegistry;
13use crate::universal_editor::UniversalEditor;
14use crate::universal_view::UniversalView;
15
16pub const UNIVERSAL_VIEW_ID: &str = "view:default";
18
19pub const UNIVERSAL_EDITOR_ID: &str = "edit:default";
21
22const LOWEST_QUALITY: i32 = -1_000_000;
24
25fn any_shape() -> sim_kernel::Value {
26 shape_value(Symbol::qualified("core", "Any"), Arc::new(AnyShape))
27}
28
29pub fn register_universal_default(registry: &mut LensRegistry, readonly: bool) {
32 registry.register(Lens::view(
33 LensMeta::new(Symbol::new(UNIVERSAL_VIEW_ID), LensKind::View)
34 .claiming_shape(any_shape())
35 .with_quality_cost(LOWEST_QUALITY, 0)
36 .as_universal_default(),
37 Arc::new(UniversalView),
38 ));
39 let editor = if readonly {
40 UniversalEditor::readonly()
41 } else {
42 UniversalEditor::writable()
43 };
44 registry.register(Lens::editor(
45 LensMeta::new(Symbol::new(UNIVERSAL_EDITOR_ID), LensKind::Editor)
46 .claiming_shape(any_shape())
47 .with_quality_cost(LOWEST_QUALITY, 0)
48 .as_universal_default(),
49 Arc::new(editor),
50 ));
51}