Example #1
0
        public Color4PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            ColorBoxButton colorBox;
            var            panel        = new ColorPickerPanel();
            var            currentColor = CoalescedPropertyValue(Color4.White).DistinctUntilChanged();

            EditorContainer.AddNode(new Widget {
                Layout = new HBoxLayout {
                    DefaultCell = new DefaultLayoutCell(Alignment.Center)
                },
                Nodes =
                {
                    (editor   = editorParams.EditBoxFactory()),
                    Spacer.HSpacer(4),
                    (colorBox = new ColorBoxButton(currentColor)),
                    CreatePipetteButton(),
                    Spacer.HStretch(),
                },
            });
            ExpandableContent.AddNode(panel.Widget);
            panel.Widget.Padding = panel.Widget.Padding + new Thickness(right: 12.0f);
            panel.Widget.Tasks.Add(currentColor.Consume(v => {
                if (panel.Color != v)
                {
                    panel.Color = v;
                }
                Changed?.Invoke();
            }));
            panel.Changed += () => {
                EditorParams.History?.RollbackTransaction();
                SetProperty(panel.Color);
            };
            panel.DragStarted += () => {
                EditorParams.History?.BeginTransaction();
                lastColor = panel.Color;
            };
            panel.DragEnded += () => {
                if (panel.Color != lastColor)
                {
                    EditorParams.History?.CommitTransaction();
                }
                EditorParams.History?.EndTransaction();
            };
            colorBox.Clicked += () => Expanded = !Expanded;
            var currentColorString = currentColor.Select(i => i.ToString(Color4.StringPresentation.Dec));

            editor.Submitted += text => SetComponent(text, currentColorString);
            editor.Tasks.Add(currentColorString.Consume(v => editor.Text = v));
            editor.AddChangeWatcher(() => editor.Text, value => CheckEditorText(value, editor));
        }
Example #2
0
        public Color4PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            ColorBoxButton colorBox;
            var            panel        = new ColorPickerPanel();
            var            currentColor = CoalescedPropertyValue(Color4.White).DistinctUntilChanged();

            ContainerWidget.AddNode(new Widget {
                Layout = new HBoxLayout {
                    CellDefaults = new LayoutCell(Alignment.Center)
                },
                Nodes =
                {
                    (editor   = editorParams.EditBoxFactory()),
                    new HSpacer(4),
                    (colorBox = new ColorBoxButton(currentColor)),
                    CreatePipetteButton(),
                }
            });
            ExpandableContent.AddNode(panel.Widget);
            panel.Widget.Padding.Right = 12;
            panel.Widget.Tasks.Add(currentColor.Consume(v => panel.Color = v));
            panel.Changed     += () => SetProperty(panel.Color);
            panel.DragStarted += Document.Current.History.BeginTransaction;
            panel.DragEnded   += Document.Current.History.EndTransaction;
            colorBox.Clicked  += () => Expanded = !Expanded;
            var currentColorString = currentColor.Select(i => i.ToString(Color4.StringPresentation.Dec));

            editor.Submitted += text => {
                Color4 newColor;
                if (Color4.TryParse(text, out newColor))
                {
                    SetProperty(newColor);
                }
                else
                {
                    editor.Text = currentColorString.GetValue();
                }
            };
            editor.Tasks.Add(currentColorString.Consume(v => editor.Text = v));
        }
Example #3
0
        public Color4PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            ColorBoxButton colorBox;

            panel = new ColorPickerPanel();
            var objects  = EditorParams.Objects.ToList();
            var first    = PropertyValue(objects.First()).GetValue();
            var @default = objects.All(o =>
                                       PropertyValue(o).GetValue().A == first.A) ? new Color4(255, 255, 255, first.A) : Color4.White;
            var currentColor = CoalescedPropertyValue(@default).DistinctUntilChanged();

            panel.Color = currentColor.GetValue().Value;
            EditorContainer.AddNode(new Widget {
                Layout = new HBoxLayout {
                    DefaultCell = new DefaultLayoutCell(Alignment.Center)
                },
                Nodes =
                {
                    (editor   = editorParams.EditBoxFactory()),
                    Spacer.HSpacer(4),
                    (colorBox = new ColorBoxButton(currentColor)),
                    CreatePipetteButton(),
                    Spacer.HStretch(),
                },
            });
            ExpandableContent.AddNode(panel.Widget);
            panel.Widget.Padding += new Thickness(right: 12.0f);
            panel.Widget.Components.GetOrAdd <LateConsumeBehaviour>().Add(currentColor.Consume(v => {
                if (panel.Color != v.Value)
                {
                    panel.Color = v.Value;
                }
                Changed?.Invoke();
            }));
            panel.Changed += () => {
                EditorParams.History?.RollbackTransaction();
                if ((panel.Color.ABGR & 0xFFFFFF) == (previousColor.ABGR & 0xFFFFFF) && panel.Color.A != previousColor.A)
                {
                    SetProperty <Color4>(c => {
                        c.A = panel.Color.A;
                        return(c);
                    });
                }
                else
                {
                    SetProperty(panel.Color);
                }
            };
            panel.DragStarted += () => {
                EditorParams.History?.BeginTransaction();
                previousColor = panel.Color;
            };
            panel.DragEnded += () => {
                if (panel.Color != previousColor || (editorParams.Objects.Skip(1).Any() && SameValues()))
                {
                    EditorParams.History?.CommitTransaction();
                }
                EditorParams.History?.EndTransaction();
            };
            colorBox.Clicked += () => Expanded = !Expanded;
            var currentColorString = currentColor.Select(i => i.Value.ToString(Color4.StringPresentation.Dec));

            editor.Submitted += text => {
                SetComponent(text, currentColorString);
            };
            editor.AddChangeLateWatcher(currentColorString, v => editor.Text = SameValues() ? v : ManyValuesText);
            editor.AddChangeLateWatcher(() => editor.Text, value => CheckEditorText(value, editor));
            ManageManyValuesOnFocusChange(editor, currentColor);
        }