Trait editor::Editor [] [src]

pub trait Editor {
    fn cursor_2d(&self) -> Option<[f64; 2]>;
    fn cursor_3d(&self) -> Option<[f64; 3]>;
    fn hit_2d(&self, pos: [f64; 2]) -> Vec<(Type, Object)>;
    fn hit_3d(&self, pos: [f64; 3]) -> Vec<(Type, Object)>;
    fn select(&mut self, ty: Type, obj: Object) -> Result<()()>;
    fn select_multiple(&mut self, ty: Type, objs: &[Object]) -> Result<()()>;
    fn deselect_multiple(&mut self, ty: Type, objs: &[Object]) -> Result<()()>;
    fn select_none(&mut self, ty: Type) -> Result<()()>;
    fn insert(&mut self, ty: Type, args: &Any) -> Result<Object()>;
    fn delete(&mut self, ty: Type, obj: Object) -> Result<Option<Object>, ()>;
    fn update(&mut self, ty: Type, obj: Object, args: &Any) -> Result<()()>;
    fn replace(&mut self, ty: Type, from: Object, to: Object) -> Result<Option<Object>, ()>;
    fn get<'a>(&'a self, ty: Type, obj: Object) -> Result<&'a Any()>;
    fn references_to(&self, ty: Type, obj: Object) -> Vec<Reference>;
    fn references_from(&self, ty: Type, obj: Object) -> Vec<Reference>;
    fn visible(&self, ty: Type) -> Vec<Object>;
    fn selected(&self, ty: Type) -> Option<Object>;
    fn multiple_selected(&self, ty: Type) -> Vec<Object>;
    fn all(&self, ty: Type) -> Vec<Object>;
    fn navigate_to(&mut self, ty: Type, obj: Object) -> Result<()()>;
    fn types(&self) -> Vec<Type>;
    fn fields_of(&self, ty: Type, obj: Object) -> Vec<Field>;
    fn update_field(&mut self, ty: Type, obj: Object, field: Field, val: &Any) -> Result<()()>;
    fn refresh_views(&mut self);
}

A generic interface for editors, implemented on controllers.

Provides all information necessary to execute actions, select objects, navigate and update. This makes it possible to write reusable generic actions.

History is handled externally, using Box<Any> for changes. The editor should not store any history internally, unless it is garbage collected from within the Any data sent outside.

All changes must be reversible from the information that is sent outside. You can use Arc to check for uniqueness for resources with a handle. If the internal Arc is unique, it means the information can safely be removed. This must happen internally.

A history buffer must keep handles alive since they can not be recreated. If this is a problem, then the editor must map to a recreatable resource.

The controller should keep same selection state across multiple views.

References should not be handled internally. This is done through algorithms using the reference information. For example, before deleting an object, checks that all affected references are cascading, such there are no loose references after deletion. Cascading references deletes the objects that the reference points from.

Methods that returns Result can trigger a rollback in actions. This is to prevent logical errors from affecting data. Concurrent actions are not permitted at the same time.

View information must be stored internally in the editor. If the editor state depends on the view state, then it should not be updated before refresh_views is called.

Required Methods

fn cursor_2d(&self) -> Option<[f64; 2]>

Gets the current cursor position in 2D.

fn cursor_3d(&self) -> Option<[f64; 3]>

Gets the current cursor position in 3D world coordinates.

fn hit_2d(&self, pos: [f64; 2]) -> Vec<(Type, Object)>

Try to hit objects at 2D position.

fn hit_3d(&self, pos: [f64; 3]) -> Vec<(Type, Object)>

Try to hit objects at 3D position.

fn select(&mut self, ty: Type, obj: Object) -> Result<()()>

Select a single object.

fn select_multiple(&mut self, ty: Type, objs: &[Object]) -> Result<()()>

Select multiple objects. Adds to the current selection.

fn deselect_multiple(&mut self, ty: Type, objs: &[Object]) -> Result<()()>

Deselect multiple objects. Removes from the current selection.

fn select_none(&mut self, ty: Type) -> Result<()()>

Deselect everything of a type.

fn insert(&mut self, ty: Type, args: &Any) -> Result<Object()>

Inserts a new object.

fn delete(&mut self, ty: Type, obj: Object) -> Result<Option<Object>, ()>

Returns an object which references must be updated when using swap-remove by replacing object with last one in same table.

fn update(&mut self, ty: Type, obj: Object, args: &Any) -> Result<()()>

Updates an object with new values.

fn replace(&mut self, ty: Type, from: Object, to: Object) -> Result<Option<Object>, ()>

Replaces an object with another. Keeps references pointing to the old object, but deletes references pointing from the old object.

fn get<'a>(&'a self, ty: Type, obj: Object) -> Result<&'a Any()>

Get the field of an object.

fn references_to(&self, ty: Type, obj: Object) -> Vec<Reference>

Get references pointing to an object.

fn references_from(&self, ty: Type, obj: Object) -> Vec<Reference>

Get references pointing from an object to other objects.

fn visible(&self, ty: Type) -> Vec<Object>

Get the visible objects of a type.

fn selected(&self, ty: Type) -> Option<Object>

Gets the selected object of a type. If the editor supports multiple selection, the selected object is usually the last in the selected list.

fn multiple_selected(&self, ty: Type) -> Vec<Object>

Gets the multiple selected objects of a type. The order of the selected objects matter.

fn all(&self, ty: Type) -> Vec<Object>

Get all objects of a type.

fn navigate_to(&mut self, ty: Type, obj: Object) -> Result<()()>

Navigate to an object such that it becomes visible.

fn types(&self) -> Vec<Type>

Gets the types in the editor.

fn fields_of(&self, ty: Type, obj: Object) -> Vec<Field>

Get the fields of an object. This requires an object because it can be dynamically typed. Fields of statically types are known at compile time.

fn update_field(&mut self, ty: Type, obj: Object, field: Field, val: &Any) -> Result<()()>

Updates a field. This is used by property widgets.

fn refresh_views(&mut self)

Refreshes the views. This is called at the end of each action to update cached data.

Implementors