Beispiel #1
0
 public TextPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
 {
     EditorContainer.AddNode(new Widget {
         Layout = new HBoxLayout(),
         Nodes  =
         {
             (editor         = editorParams.EditBoxFactory()),
             Spacer.HSpacer(4),
             (button         = new ThemedButton {
                 Text        = "...",
                 MinMaxWidth =                             20,
                 LayoutCell  = new LayoutCell(Alignment.Center)
             })
         }
     });
     editor.LayoutCell = new LayoutCell(Alignment.Center);
     editor.Editor.EditorParams.MaxLines = maxLines;
     editor.MinHeight += editor.TextWidget.FontHeight * (maxLines - 1);
     editor.Submitted += text => SetProperty(text);
     editor.AddChangeWatcher(CoalescedPropertyValue(), v => editor.Text = v);
     button.Clicked += () => {
         var window = new TextEditorDialog(editorParams.DisplayName ?? editorParams.PropertyName, editor.Text, (s) => {
             SetProperty(s);
         });
     };
 }
        public ShortcutPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            editor            = editorParams.EditBoxFactory();
            editor.Updating  += Updating;
            editor.Updated   += Updated;
            editor.LayoutCell = new LayoutCell(Alignment.Center);
            editor.AddChangeWatcher(CoalescedPropertyValue(), v => {
                var text    = v.ToString();
                editor.Text = v.Main != Key.Unknown ? text : text.Replace("Unknown", "");
            });
            editor.IsReadOnly = true;
            editor.TextWidget.Tasks.Clear();
            editor.TextWidget.Position = new Vector2(0, editor.MinHeight / 2);
            editor.TextWidget.Padding  = new Thickness(5, 0);
            editor.Gestures.Add(new ClickGesture(() => editor.SetFocus()));
            editor.Gestures.Add(new ClickGesture(1, () => {
                main      = Key.Unknown;
                modifiers = Modifiers.None;
                SetValue(new Shortcut(modifiers, main));
            }));
            editor.AddToNode(EditorContainer);

            PropertyLabel.Tasks.Clear();
            PropertyLabel.Tasks.Add(ManageLabelFocus());
            ContainerWidget.Tasks.Add(ManageFocusTask());

            var value = CoalescedPropertyValue().GetValue();

            main              = value.Main;
            modifiers         = value.Modifiers;
            flatFillPresenter = new WidgetFlatFillPresenter(Theme.Colors.GrayBackground);
            ContainerWidget.CompoundPresenter.Add(flatFillPresenter);
        }
Beispiel #3
0
        protected FilePropertyEditor(IPropertyEditorParams editorParams, string[] allowedFileTypes) : base(editorParams)
        {
            EditorContainer.AddNode(new Widget {
                Layout = new HBoxLayout(),
                Nodes  =
                {
                    (editor         = editorParams.EditBoxFactory()),
                    Spacer.HSpacer(4),
                    (button         = new ThemedButton {
                        Text        = "...",
                        MinMaxWidth =                             20,
                        LayoutCell  = new LayoutCell(Alignment.Center)
                    })
                }
            });
            editor.LayoutCell = new LayoutCell(Alignment.Center);
            editor.Submitted += text => SetComponent(text);
            bool textValid = true;

            editor.AddChangeWatcher(() => editor.Text, text => textValid = IsValid(text));
            editor.CompoundPostPresenter.Add(new SyncDelegatePresenter <EditBox>(editBox => {
                if (!textValid)
                {
                    editBox.PrepareRendererState();
                    Renderer.DrawRect(Vector2.Zero, editBox.Size, Color4.Red.Transparentify(0.8f));
                }
            }));
            button.Clicked += () => {
                var dlg = new FileDialog {
                    AllowedFileTypes = allowedFileTypes,
                    Mode             = FileDialogMode.Open,
                    InitialDirectory = Directory.Exists(LastOpenedDirectory) ? LastOpenedDirectory : Project.Current.GetSystemDirectory(Document.Current.Path),
                };
                if (dlg.RunModal())
                {
                    SetFilePath(dlg.FileName);
                    LastOpenedDirectory = Project.Current.GetSystemDirectory(dlg.FileName);
                }
            };
            ExpandableContent.Padding = new Thickness(24, 10, 2, 2);
            var prefixEditor = new StringPropertyEditor(new PropertyEditorParams(ExpandableContent, prefix, nameof(PrefixData.Prefix))
            {
                LabelWidth = 180
            });

            prefix.Prefix = GetLongestCommonPrefix(GetPaths());
            ContainerWidget.AddChangeWatcher(() => prefix.Prefix, v => {
                string oldPrefix = GetLongestCommonPrefix(GetPaths());
                if (oldPrefix == v)
                {
                    return;
                }
                SetPathPrefix(oldPrefix, v);
                prefix.Prefix = v.Trim('/');
            });
        }
Beispiel #4
0
 public StringPropertyEditor(IPropertyEditorParams editorParams, bool multiline = false) : base(editorParams)
 {
     editor            = editorParams.EditBoxFactory();
     editor.LayoutCell = new LayoutCell(Alignment.Center);
     editor.Editor.EditorParams.MaxLines = multiline ? maxLines : 1;
     editor.MinHeight += multiline ? editor.TextWidget.FontHeight * (maxLines - 1) : 0;
     ContainerWidget.AddNode(editor);
     editor.Submitted += SetProperty;
     editor.AddChangeWatcher(CoalescedPropertyValue(), v => editor.Text = v);
 }
Beispiel #5
0
        public NodeIdPropertyEditor(IPropertyEditorParams editorParams, bool multiline = false) : base(editorParams)
        {
            editor            = editorParams.EditBoxFactory();
            editor.LayoutCell = new LayoutCell(Alignment.Center);
            editor.Editor.EditorParams.MaxLines = 1;
            EditorContainer.AddNode(editor);
            bool textValid = true;

            editor.AddChangeWatcher(() => editor.Text, text => textValid = IsValid(text));
            editor.CompoundPostPresenter.Add(new SyncDelegatePresenter <EditBox>(editBox => {
                if (!textValid)
                {
                    editBox.PrepareRendererState();
                    Renderer.DrawRect(Vector2.Zero, editBox.Size, Color4.Red.Transparentify(0.8f));
                }
            }));
            editor.Submitted += text => SetValue(text);
            editor.AddChangeWatcher(CoalescedPropertyValue(), v => editor.Text = v);
        }
Beispiel #6
0
 public RenderTexturePropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
 {
     editor            = editorParams.EditBoxFactory();
     editor.IsReadOnly = true;
     editor.LayoutCell = new LayoutCell(Alignment.Center);
     ContainerWidget.AddNode(editor);
     editor.AddChangeWatcher(CoalescedPropertyValue(), v =>
                             editor.Text = v == null ?
                                           "RenderTexture (null)" :
                                           $"RenderTexture ({v.ImageSize.Width}x{v.ImageSize.Height})"
                             );
 }
Beispiel #7
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));
        }
Beispiel #8
0
        public NodeReferencePropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            var propName = editorParams.PropertyName;

            if (propName.EndsWith("Ref"))
            {
                PropertyLabel.Text = propName.Substring(0, propName.Length - 3);
            }
            editor            = editorParams.EditBoxFactory();
            editor.LayoutCell = new LayoutCell(Alignment.Center);
            EditorContainer.AddNode(editor);
            editor.Submitted += text => SetComponent(text);
            editor.AddChangeWatcher(CoalescedPropertyValue(), v => editor.Text = v?.Id);
        }
Beispiel #9
0
 private Widget CreateSearchBox()
 {
     filterEditBox = new ThemedEditBox();
     filterEditBox.AddChangeWatcher(() => filterEditBox.Text, _ => RefreshAvailableCommands());
     return(new Widget {
         Layout = new HBoxLayout(),
         LayoutCell = new LayoutCell {
             StretchX = 2
         },
         Nodes =
         {
             new ThemedSimpleText("Search: ")
             {
                 LayoutCell = new LayoutCell(Alignment.LeftCenter)
             },
             filterEditBox
         }
     });
 }
Beispiel #10
0
        public IntPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            editor             = editorParams.EditBoxFactory();
            editor.MinMaxWidth = 80;
            editor.LayoutCell  = new LayoutCell(Alignment.Center);
            ContainerWidget.AddNode(editor);
            var current = CoalescedPropertyValue();

            editor.Submitted += text => {
                int newValue;
                if (int.TryParse(text, out newValue))
                {
                    SetProperty(newValue);
                }
                else
                {
                    editor.Text = current.GetValue().ToString();
                }
            };
            editor.AddChangeWatcher(current, v => editor.Text = v.ToString());
        }