Example #1
0
        /// <summary>
        /// Adds new integer value element.
        /// </summary>
        /// <returns>The created element.</returns>
        public IntegerValueElement IntegerValue()
        {
            IntegerValueElement element = new IntegerValueElement();

            OnAddElement(element);
            return(element);
        }
Example #2
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            var grid        = layout.CustomContainer <UniformGridPanel>();
            var gridControl = grid.CustomControl;

            gridControl.ClipChildren      = false;
            gridControl.Height            = TextBox.DefaultHeight;
            gridControl.SlotsHorizontally = 4;
            gridControl.SlotsVertically   = 1;

            Major = grid.IntegerValue();
            Major.IntValue.SetLimits(0, 100000000);
            Major.IntValue.ValueChanged += OnValueChanged;
            Major.IntValue.SlidingEnd   += ClearToken;

            Minor = grid.IntegerValue();
            Minor.IntValue.SetLimits(0, 100000000);
            Minor.IntValue.ValueChanged += OnValueChanged;
            Minor.IntValue.SlidingEnd   += ClearToken;

            Build = grid.IntegerValue();
            Build.IntValue.SetLimits(-1, 100000000);
            Build.IntValue.ValueChanged += OnValueChanged;
            Build.IntValue.SlidingEnd   += ClearToken;

            Revision = grid.IntegerValue();
            Revision.IntValue.SetLimits(-1, 100000000);
            Revision.IntValue.ValueChanged += OnValueChanged;
            Revision.IntValue.SlidingEnd   += ClearToken;
        }
Example #3
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            var grid        = layout.CustomContainer <UniformGridPanel>();
            var gridControl = grid.CustomControl;

            gridControl.ClipChildren      = false;
            gridControl.Height            = TextBox.DefaultHeight;
            gridControl.SlotsHorizontally = 3;
            gridControl.SlotsVertically   = 1;

            LimitAttribute limit      = null;
            var            attributes = Values.GetAttributes();

            if (attributes != null)
            {
                limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
            }

            XElement = grid.IntegerValue();
            XElement.SetLimits(limit);
            XElement.IntValue.ValueChanged += OnValueChanged;
            XElement.IntValue.SlidingEnd   += ClearToken;

            YElement = grid.IntegerValue();
            YElement.SetLimits(limit);
            YElement.IntValue.ValueChanged += OnValueChanged;
            YElement.IntValue.SlidingEnd   += ClearToken;

            ZElement = grid.IntegerValue();
            ZElement.SetLimits(limit);
            ZElement.IntValue.ValueChanged += OnValueChanged;
            ZElement.IntValue.SlidingEnd   += ClearToken;
        }
Example #4
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;
        }
        /// <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;
        }
Example #6
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);
                };
            }
        }
Example #7
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);
                };
            }
        }
Example #8
0
 /// <inheritdoc />
 public override void Initialize(LayoutElementsContainer layout)
 {
     element = layout.IntegerValue();
     element.SetLimits(Values.Info);
     element.IntValue.ValueChanged += () => SetValue(element.IntValue.Value);
 }
Example #9
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);
                };
            }
        }
Example #10
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);
                };
            }
        }