Beispiel #1
0
        private Node CreatePipetteButton()
        {
            var button = new ToolbarButton {
                Texture = IconPool.GetTexture("Tools.Pipette"),
            };

            button.Tasks.Add(UIProcessors.PickColorProcessor(button, v => SetProperty(v)));
            return(button);
        }
Beispiel #2
0
        private Node CreatePipetteButton()
        {
            var button = new ToolbarButton {
                Texture = IconPool.GetTexture("Tools.Pipette"),
            };

            button.Tasks.Add(UIProcessors.PickColorProcessor(
                                 button, v => SetControlPointProperty(nameof(GradientControlPoint.Color), v)));
            return(button);
        }
		public AnchorsPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
		{
			group = new Widget { Layout = new HBoxLayout { DefaultCell = new DefaultLayoutCell(Alignment.Center), Spacing = 4 } };
			EditorContainer.AddNode(group);
			firstButton = AddButton(Anchors.Left, "Anchor to the left");
			AddButton(Anchors.Right, "Anchor to the right");
			AddButton(Anchors.Top, "Anchor to the top");
			AddButton(Anchors.Bottom, "Anchor to the bottom");
			AddButton(Anchors.CenterH, "Anchor to the center horizontally");
			AddButton(Anchors.CenterV, "Anchor to the center vertically");
			group.AddNode(Spacer.HStretch());
		}
Beispiel #4
0
        private Node CreatePipetteButton()
        {
            pipetteButton = new ToolbarButton {
                Texture = IconPool.GetTexture("Tools.Pipette"),
            };
            var current = CoalescedPropertyValue();

            pipetteButton.Tasks.Add(PickColorProcessor(pipetteButton, v => {
                var value = current.GetValue();
                v.A       = value.IsDefined ? value.Value.A : v.A;
                SetProperty(v);
            }));
            return(pipetteButton);
        }
Beispiel #5
0
        public InstancePropertyEditor(IPropertyEditorParams editorParams, Action <Widget> onValueChanged) : base(editorParams)
        {
            Selector            = editorParams.DropDownListFactory();
            Selector.LayoutCell = new LayoutCell(Alignment.Center);
            var propertyType = typeof(T);
            var meta         = Yuzu.Metadata.Meta.Get(editorParams.Type, InternalPersistence.Instance.YuzuCommonOptions);

            if (!propertyType.IsInterface && !propertyType.IsAbstract)
            {
                Selector.Items.Add(new CommonDropDownList.Item(propertyType.Name, propertyType));
            }
            foreach (var t in DerivedTypesCache.GetDerivedTypesFor(propertyType))
            {
                Selector.Items.Add(new CommonDropDownList.Item(t.Name, t));
            }
            EditorContainer.AddChangeLateWatcher(CoalescedPropertyValue(
                                                     comparator: (t1, t2) => t1 == null && t2 == null || t1 != null && t2 != null && t1.GetType() == t2.GetType()),
                                                 v => {
                onValueChanged?.Invoke(ExpandableContent);
                if (v.IsDefined)
                {
                    Selector.Value = v.Value?.GetType();
                }
                else
                {
                    Selector.Text = ManyValuesText;
                }
            }
                                                 );
            Selector.Changed += a => {
                if (a.ChangedByUser)
                {
                    var type = (Type)Selector.Items[a.Index].Value;
                    SetProperty <object>((_) => type != null ? Activator.CreateInstance(type) : null);
                }
            };
            var propertyMetaItem     = meta.Items.FirstOrDefault(i => i.Name == editorParams.PropertyName);
            var defaultValue         = propertyMetaItem?.GetValue(meta.Default);
            var resetToDefaultButton = new ToolbarButton(IconPool.GetTexture("Tools.Revert"))
            {
                Clicked = () => SetProperty(Cloner.Clone(defaultValue))
            };

            if (Selector.Items.Count == 1)
            {
                var t = Selector.Items[0].Value as Type;
                var b = new ToolbarButton("Create")
                {
                    TabTravesable = new TabTraversable(),
                    LayoutCell    = new LayoutCell(Alignment.LeftCenter),
                    Padding       = new Thickness(left: 5.0f),
                    HitTestTarget = true,
                    MinWidth      = 0,
                    MaxWidth      = float.PositiveInfinity
                };
                b.Clicked = () => {
                    b.Visible = false;
                    SetProperty <object>(_ => t != null ? Activator.CreateInstance(t) : null);
                    onValueChanged?.Invoke(ExpandableContent);
                    Expanded = true;
                };
                var value = CoalescedPropertyValue().GetValue();
                b.Visible = Equals(value.Value, defaultValue);
                resetToDefaultButton.Clicked = () => {
                    b.Visible = true;
                    SetProperty(defaultValue);
                    onValueChanged?.Invoke(ExpandableContent);
                };
                EditorContainer.AddNode(b);
                EditorContainer.AddNode(Spacer.HStretch());
                onValueChanged?.Invoke(ExpandableContent);
            }
            else
            {
                EditorContainer.Nodes.Insert(0, Selector);
            }
            EditorContainer.AddNode(resetToDefaultButton);
            EditorContainer.AddChangeLateWatcher(CoalescedPropertyValue(), v => {
                resetToDefaultButton.Visible = !Equals(v.Value, defaultValue);
            });
        }
        public InstancePropertyEditor(IPropertyEditorParams editorParams, Action <Widget> OnValueChanged) : base(editorParams)
        {
            Selector            = editorParams.DropDownListFactory();
            Selector.LayoutCell = new LayoutCell(Alignment.Center);
            EditorContainer.AddNode(Selector);
            var propertyType     = typeof(T);
            var meta             = Yuzu.Metadata.Meta.Get(editorParams.Type, Serialization.YuzuCommonOptions);
            var propertyMetaItem = meta.Items.Where(i => i.Name == editorParams.PropertyName).FirstOrDefault();

            if (propertyMetaItem != null)
            {
                var defaultValue         = propertyMetaItem.GetValue(meta.Default);
                var resetToDefaultButton = new ToolbarButton(IconPool.GetTexture("Tools.Revert"))
                {
                    Clicked = () => { SetProperty(defaultValue); }
                };
                EditorContainer.AddNode(resetToDefaultButton);
                Selector.AddChangeWatcher(CoalescedPropertyValue(), v => {
                    resetToDefaultButton.Visible = !Equals(v, defaultValue);
                });
            }
            if (!propertyType.IsInterface)
            {
                Selector.Items.Add(new CommonDropDownList.Item(propertyType.Name, propertyType));
            }
            // TODO: invalidate cache on loading new assemblies at runtime
            if (!derivedTypesCache.TryGetValue(propertyType, out List <Type> derivedTypes))
            {
                derivedTypes = new List <Type>();
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    var assignables = assembly
                                      .GetTypes()
                                      .Where(t =>
                                             !t.IsInterface &&
                                             t.GetCustomAttribute <TangerineIgnoreAttribute>(false) == null &&
                                             t != propertyType &&
                                             propertyType.IsAssignableFrom(t));
                    foreach (var type in assignables)
                    {
                        derivedTypes.Add(type);
                    }
                }
                derivedTypesCache.Add(propertyType, derivedTypes);
            }
            foreach (var t in derivedTypes)
            {
                Selector.Items.Add(new CommonDropDownList.Item(t.Name, t));
            }
            Selector.Changed += a => {
                if (a.ChangedByUser)
                {
                    Type type = (Type)Selector.Items[a.Index].Value;
                    SetProperty <object>((_) => type != null ? Activator.CreateInstance(type) : null);
                }
            };
            Selector.AddChangeWatcher(CoalescedPropertyValue(), v => {
                OnValueChanged?.Invoke(ExpandableContent);
                Selector.Value = v?.GetType();
            });
        }