Framework / Editors / Editors / Editor Factories
In This Topic

    Editor Factories

    In This Topic

    Editor factories are delegate functions, which create new instances of editors of a certain type. Currently used in the NDesigner are the following editor factory method signatures:

    You may need to specify a custom editor factory, when you want to modify the default editor created by the designer for a specific property, child-slot, category, or modify the default standalone and embedded node editors.

    For example, suppose you have a double property and you want the user to be able to enter values only n the [0-100] range, with a step of 0.1 and a precision of 2 digits. You can achieve this by specifying an editor factory for the property with modified properties, as shown in the following example:

    Setting an custom editor template for a property
    Copy Code
    public class MyNode : NNode
    {
        ...
        public static readonly NProperty MyDoubleProperty;
        public class MyNodeDesigner : NDesigner
        {
            public MyNodeDesigner()
            {
                    DNFunctionResult<NMemberEditor> myFactory = delegate()
                    {
                        NDoublePropertyEditor editor = new NDoublePropertyEditor();
                        editor.Minimum = -100.00;
                        editor.Maximum = 100.00;
                        editor.Step = 0.1;
                        editor.DecimalPlaces = 2;
                        return editor;
                    };
                    SetMemberEditorTemplate(MyDoubleProperty, myFactory);
            }
        }
    }
    

    The NEditorFactory static class contains helper methods for creating editor factories for the three major categories - node, member and category as described in the following table:

    Method Description
    DNFunctionResult<NNodeEditor> CreateNodeEditorFactory<TNNodeEditor>(DNFunction<TNNodeEditor> initFunction = null) Creates a new NNodeEditor of type TNNodeEditor and optionally calls the specified initFunction to additionally tune it.
    DNFunctionResult<NCategoryEditor> CreateCategoryEditorFactory<TNCategoryEditor>(DNFunction<TNCategoryEditor> initFunction = null) Creates a new NCategoryEditor of type TNCategoryEditor and optionally calls the specified initFunction to additionally tune it.
    DNFunctionResult<NMemberEditor> CreateMemberEditorFactory<TNMemberEditor>(DNFunction<TNMemberEditor> initFunction = null) Creates a new NMemberEditor of type TNMemberEditor and optionally calls the specified initFunction to additionally tune it.

    The following example creates the same editor factory as the one shown in the previous example, but with the help of the NEditorFactory class:

    Using the NEditorFactory to create new editor factories
    Copy Code
    DNFunctionResult<NMemberEditor> myFactory = NEditorFactory.CreateMemberEditorFactory<NDoublePropertyEditor>((editor)=>
    {
        editor.Minimum = -100.00;
        editor.Maximum = 100.00;
        editor.Step = 0.1;
        editor.DecimalPlaces = 2;
    });