Esempio n. 1
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly        = false;
            _canReorderItems = true;
            _notNullItems    = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var type = Values.Type;
            var size = Count;

            // Try get MemberCollectionAttribute for collection editor meta
            var attributes = Values.GetAttributes();

            if (attributes != null)
            {
                var memberCollection = (MemberCollectionAttribute)attributes.FirstOrDefault(x => x is MemberCollectionAttribute);
                if (memberCollection != null)
                {
                    // TODO: handle ReadOnly and NotNullItems by filtering child editors SetValue
                    // TODO: handle CanReorderItems

                    _readOnly        = memberCollection.ReadOnly;
                    _canReorderItems = memberCollection.CanReorderItems;
                    _notNullItems    = memberCollection.NotNullItems;
                }
            }

            // Size
            if (_readOnly)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var elementType = ElementType;
                for (int i = 0; i < size; i++)
                {
                    layout.Object("Element " + i, new ListValueContainer(elementType, i, Values));
                }
            }
            _elementsCount = size;
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _element = null;

            // Try get limit attribute for value min/max range setting and slider speed
            var attributes = Values.GetAttributes();

            if (attributes != null)
            {
                var range = attributes.FirstOrDefault(x => x is RangeAttribute);
                if (range != null)
                {
                    // Use slider
                    var element = layout.Slider();
                    element.SetLimits((RangeAttribute)range);
                    element.Slider.ValueChanged += OnValueChanged;
                    element.Slider.SlidingEnd   += ClearToken;
                    _element = element;
                    return;
                }
                var limit = attributes.FirstOrDefault(x => x is LimitAttribute);
                if (limit != null)
                {
                    // Use int value editor with limit
                    var element = layout.IntegerValue();
                    element.SetLimits((LimitAttribute)limit);
                    element.IntValue.ValueChanged += OnValueChanged;
                    element.IntValue.SlidingEnd   += ClearToken;
                    _element = element;
                    return;
                }
            }
            if (_element == null)
            {
                // Use int value editor
                var element = layout.IntegerValue();
                element.IntValue.ValueChanged += OnValueChanged;
                element.IntValue.SlidingEnd   += ClearToken;
                _element = element;
            }
        }
Esempio n. 3
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            element = null;

            // Try get limit attribute for value min/max range setting and slider speed
            if (Values.Info != null)
            {
                var attributes = Values.Info.GetCustomAttributes(true);
                var range      = attributes.FirstOrDefault(x => x is RangeAttribute);
                if (range != null)
                {
                    // Use slider
                    var slider = layout.Slider();
                    slider.SetLimits((RangeAttribute)range);
                    slider.Slider.ValueChanged += OnValueChanged;
                    slider.Slider.SlidingEnd   += ClearToken;
                    element = slider;
                }
                var limit = attributes.FirstOrDefault(x => x is LimitAttribute);
                if (limit != null)
                {
                    // Use int value editor with limit
                    var intValue = layout.IntegerValue();
                    intValue.SetLimits((LimitAttribute)limit);
                    intValue.IntValue.ValueChanged += OnValueChanged;
                    intValue.IntValue.SlidingEnd   += ClearToken;
                    element = intValue;
                }
            }
            if (element == null)
            {
                // Use int value editor
                var intValue = layout.IntegerValue();
                intValue.IntValue.ValueChanged += OnValueChanged;
                intValue.IntValue.SlidingEnd   += ClearToken;
                element = intValue;
            }
        }
Esempio n. 4
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly        = false;
            _canReorderItems = true;
            _notNullItems    = false;

            // No support for different collections for now
            if (HasDiffrentValues || HasDiffrentTypes)
            {
                return;
            }

            var type = Values.Type;
            var size = Count;

            // Try get MemberCollectionAttribute for collection editor meta
            if (Values.Info != null)
            {
                var attributes       = Values.Info.GetCustomAttributes(true);
                var memberCollection = (MemberCollectionAttribute)attributes.FirstOrDefault(x => x is MemberCollectionAttribute);
                if (memberCollection != null)
                {
                    // TODO: handle ReadOnly and NotNullItems by filtering child editors SetValue
                    // TODO: handle CanReorderItems

                    _readOnly        = memberCollection.ReadOnly;
                    _canReorderItems = memberCollection.CanReorderItems;
                    _notNullItems    = memberCollection.NotNullItems;
                }
            }

            // Size
            if (_readOnly)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var argTypes       = type.GetGenericArguments();
                var keyType        = argTypes[0];
                var valueType      = argTypes[1];
                var keysEnumerable = ((IDictionary)Values[0]).Keys.OfType <object>();
                var keys           = keysEnumerable as object[] ?? keysEnumerable.ToArray();
                for (int i = 0; i < size; i++)
                {
                    var item     = layout.CustomContainer <UniformGridPanel>();
                    var itemGrid = item.CustomControl;
                    itemGrid.Height            = TextBox.DefaultHeight;// TODO: make slots auto sizable instead of fixed height
                    itemGrid.SlotsHorizontally = 2;
                    itemGrid.SlotsVertically   = 1;

                    // Key
                    // TODO: allow edit keys
                    var key = keys.ElementAt(i);
                    item.Label(key.ToString());

                    // Value
                    item.Object(new DictionaryValueContainer(valueType, key, Values));
                }
            }
            _elementsCount = size;
        }
Esempio n. 5
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly     = false;
            _notNullItems = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var type      = Values.Type;
            var size      = Count;
            var argTypes  = type.GetGenericArguments();
            var keyType   = argTypes[0];
            var valueType = argTypes[1];

            _canEditKeys = keyType == typeof(string) || keyType.IsPrimitive || keyType.IsEnum;

            // Try get CollectionAttribute for collection editor meta
            var   attributes         = Values.GetAttributes();
            Type  overrideEditorType = null;
            float spacing            = 0.0f;

            if (attributes != null)
            {
                var collection = (CollectionAttribute)attributes.FirstOrDefault(x => x is CollectionAttribute);
                if (collection != null)
                {
                    // TODO: handle ReadOnly and NotNullItems by filtering child editors SetValue

                    _readOnly          = collection.ReadOnly;
                    _notNullItems      = collection.NotNullItems;
                    overrideEditorType = TypeUtils.GetType(collection.OverrideEditorTypeName).Type;
                    spacing            = collection.Spacing;
                }
            }

            // Size
            if (_readOnly || !_canEditKeys)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var keysEnumerable = ((IDictionary)Values[0]).Keys.OfType <object>();
                var keys           = keysEnumerable as object[] ?? keysEnumerable.ToArray();
                for (int i = 0; i < size; i++)
                {
                    if (i != 0 && spacing > 0f)
                    {
                        if (layout.Children.Count > 0 && layout.Children[layout.Children.Count - 1] is PropertiesListElement propertiesListElement)
                        {
                            if (propertiesListElement.Labels.Count > 0)
                            {
                                var label  = propertiesListElement.Labels[propertiesListElement.Labels.Count - 1];
                                var margin = label.Margin;
                                margin.Bottom += spacing;
                                label.Margin   = margin;
                            }
                            propertiesListElement.Space(spacing);
                        }
                        else
                        {
                            layout.Space(spacing);
                        }
                    }

                    var key            = keys.ElementAt(i);
                    var overrideEditor = overrideEditorType != null ? (CustomEditor)Activator.CreateInstance(overrideEditorType) : null;
                    layout.Object(new DictionaryItemLabel(this, key), new DictionaryValueContainer(new ScriptType(valueType), key, Values), overrideEditor);
                }
            }
            _elementsCount = size;

            // Add/Remove buttons
            if (!_readOnly && _canEditKeys)
            {
                var area      = layout.Space(20);
                var addButton = new Button(area.ContainerControl.Width - (16 + 16 + 2 + 2), 2, 16, 16)
                {
                    Text         = "+",
                    TooltipText  = "Add new item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl
                };
                addButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count + 1);
                };
                var removeButton = new Button(addButton.Right + 2, addButton.Y, 16, 16)
                {
                    Text         = "-",
                    TooltipText  = "Remove last item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl,
                    Enabled      = size > 0
                };
                removeButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count - 1);
                };
            }
        }
Esempio n. 6
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly        = false;
            _canReorderItems = true;
            _notNullItems    = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var size = Count;

            // Try get MemberCollectionAttribute for collection editor meta
            var attributes = Values.GetAttributes();

            if (attributes != null)
            {
                var memberCollection = (MemberCollectionAttribute)attributes.FirstOrDefault(x => x is MemberCollectionAttribute);
                if (memberCollection != null)
                {
                    // TODO: handle NotNullItems by filtering child editors SetValue

                    _readOnly        = memberCollection.ReadOnly;
                    _canReorderItems = memberCollection.CanReorderItems;
                    _notNullItems    = memberCollection.NotNullItems;
                }
            }

            // Size
            if (_readOnly)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var elementType = ElementType;
                if (_canReorderItems)
                {
                    for (int i = 0; i < size; i++)
                    {
                        layout.Object(new CollectionItemLabel(this, i), new ListValueContainer(elementType, i, Values));
                    }
                }
                else
                {
                    for (int i = 0; i < size; i++)
                    {
                        layout.Object("Element " + i, new ListValueContainer(elementType, i, Values));
                    }
                }
            }
            _elementsCount = size;

            // Add/Remove buttons
            if (!_readOnly)
            {
                var area      = layout.Space(20);
                var addButton = new Button(area.ContainerControl.Width - (16 + 16 + 2 + 2), 2, 16, 16)
                {
                    Text        = "+",
                    TooltipText = "Add new item",
                    AnchorStyle = AnchorStyle.UpperRight,
                    Parent      = area.ContainerControl
                };
                addButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count + 1);
                };
                var removeButton = new Button(addButton.Right + 2, addButton.Y, 16, 16)
                {
                    Text        = "-",
                    TooltipText = "Remove last item",
                    AnchorStyle = AnchorStyle.UpperRight,
                    Parent      = area.ContainerControl,
                    Enabled     = size > 0
                };
                removeButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count - 1);
                };
            }
        }
Esempio n. 7
0
 /// <inheritdoc />
 public override void Initialize(LayoutElementsContainer layout)
 {
     element = layout.IntegerValue();
     element.SetLimits(Values.Info);
     element.IntValue.ValueChanged += () => SetValue(element.IntValue.Value);
 }
Esempio n. 8
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly        = false;
            _canReorderItems = true;
            _notNullItems    = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var size = Count;

            // Try get CollectionAttribute for collection editor meta
            var   attributes         = Values.GetAttributes();
            Type  overrideEditorType = null;
            float spacing            = 10.0f;
            var   collection         = (CollectionAttribute)attributes?.FirstOrDefault(x => x is CollectionAttribute);

            if (collection != null)
            {
                // TODO: handle NotNullItems by filtering child editors SetValue

                _readOnly          = collection.ReadOnly;
                _canReorderItems   = collection.CanReorderItems;
                _notNullItems      = collection.NotNullItems;
                overrideEditorType = TypeUtils.GetType(collection.OverrideEditorTypeName).Type;
                spacing            = collection.Spacing;
            }

            // Size
            if (_readOnly)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var elementType = ElementType;
                if (_canReorderItems)
                {
                    for (int i = 0; i < size; i++)
                    {
                        if (i != 0 && spacing > 0f)
                        {
                            if (layout.Children.Count > 0 && layout.Children[layout.Children.Count - 1] is PropertiesListElement propertiesListElement)
                            {
                                if (propertiesListElement.Labels.Count > 0)
                                {
                                    var label  = propertiesListElement.Labels[propertiesListElement.Labels.Count - 1];
                                    var margin = label.Margin;
                                    margin.Bottom += spacing;
                                    label.Margin   = margin;
                                }
                                propertiesListElement.Space(spacing);
                            }
                            else
                            {
                                layout.Space(spacing);
                            }
                        }

                        var overrideEditor = overrideEditorType != null ? (CustomEditor)Activator.CreateInstance(overrideEditorType) : null;
                        layout.Object(new CollectionItemLabel(this, i), new ListValueContainer(elementType, i, Values), overrideEditor);
                    }
                }
                else
                {
                    for (int i = 0; i < size; i++)
                    {
                        if (i != 0 && spacing > 0f)
                        {
                            if (layout.Children.Count > 0 && layout.Children[layout.Children.Count - 1] is PropertiesListElement propertiesListElement)
                            {
                                propertiesListElement.Space(spacing);
                            }
                            else
                            {
                                layout.Space(spacing);
                            }
                        }

                        var overrideEditor = overrideEditorType != null ? (CustomEditor)Activator.CreateInstance(overrideEditorType) : null;
                        layout.Object("Element " + i, new ListValueContainer(elementType, i, Values), overrideEditor);
                    }
                }
            }
            _elementsCount = size;

            // Add/Remove buttons
            if (!_readOnly)
            {
                var area      = layout.Space(20);
                var addButton = new Button(area.ContainerControl.Width - (16 + 16 + 2 + 2), 2, 16, 16)
                {
                    Text         = "+",
                    TooltipText  = "Add new item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl
                };
                addButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count + 1);
                };
                var removeButton = new Button(addButton.Right + 2, addButton.Y, 16, 16)
                {
                    Text         = "-",
                    TooltipText  = "Remove last item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl,
                    Enabled      = size > 0
                };
                removeButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count - 1);
                };
            }
        }
Esempio n. 9
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var type      = Values.Type;
            var size      = Count;
            var argTypes  = type.GetGenericArguments();
            var keyType   = argTypes[0];
            var valueType = argTypes[1];

            _canEditKeys  = keyType == typeof(string) || keyType.IsPrimitive || keyType.IsEnum;
            _background   = FlaxEngine.GUI.Style.Current.CollectionBackgroundColor;
            _readOnly     = false;
            _notNullItems = false;

            // Try get CollectionAttribute for collection editor meta
            var   attributes         = Values.GetAttributes();
            Type  overrideEditorType = null;
            float spacing            = 0.0f;
            var   collection         = (CollectionAttribute)attributes?.FirstOrDefault(x => x is CollectionAttribute);

            if (collection != null)
            {
                _readOnly     = collection.ReadOnly;
                _notNullItems = collection.NotNullItems;
                if (collection.BackgroundColor.HasValue)
                {
                    _background = collection.BackgroundColor.Value;
                }
                overrideEditorType = TypeUtils.GetType(collection.OverrideEditorTypeName).Type;
                spacing            = collection.Spacing;
            }

            // Size
            if (_readOnly || !_canEditKeys)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = _notNullItems ? size : ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var panel = layout.VerticalPanel();
                panel.Panel.BackgroundColor = _background;
                var keysEnumerable = ((IDictionary)Values[0]).Keys.OfType <object>();
                var keys           = keysEnumerable as object[] ?? keysEnumerable.ToArray();
                var valuesType     = new ScriptType(valueType);

                // Use separate layout cells for each collection items to improve layout updates for them in separation
                var useSharedLayout = valueType.IsPrimitive || valueType.IsEnum;

                for (int i = 0; i < size; i++)
                {
                    if (i != 0 && spacing > 0f)
                    {
                        if (panel.Children.Count > 0 && panel.Children[panel.Children.Count - 1] is PropertiesListElement propertiesListElement)
                        {
                            if (propertiesListElement.Labels.Count > 0)
                            {
                                var label  = propertiesListElement.Labels[propertiesListElement.Labels.Count - 1];
                                var margin = label.Margin;
                                margin.Bottom += spacing;
                                label.Margin   = margin;
                            }
                            propertiesListElement.Space(spacing);
                        }
                        else
                        {
                            panel.Space(spacing);
                        }
                    }

                    var key            = keys.ElementAt(i);
                    var overrideEditor = overrideEditorType != null ? (CustomEditor)Activator.CreateInstance(overrideEditorType) : null;
                    var property       = panel.AddPropertyItem(new DictionaryItemLabel(this, key));
                    var itemLayout     = useSharedLayout ? (LayoutElementsContainer)property : property.VerticalPanel();
                    itemLayout.Object(new DictionaryValueContainer(valuesType, key, Values), overrideEditor);
                }
            }
            _elementsCount = size;

            // Add/Remove buttons
            if (!_readOnly && _canEditKeys)
            {
                var area      = layout.Space(20);
                var addButton = new Button(area.ContainerControl.Width - (16 + 16 + 2 + 2), 2, 16, 16)
                {
                    Text         = "+",
                    TooltipText  = "Add new item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl,
                    Enabled      = !_notNullItems,
                };
                addButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count + 1);
                };
                var removeButton = new Button(addButton.Right + 2, addButton.Y, 16, 16)
                {
                    Text         = "-",
                    TooltipText  = "Remove last item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl,
                    Enabled      = size > 0,
                };
                removeButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count - 1);
                };
            }
        }