public TextPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { ThemedButton button; 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); var first = true; var submitted = false; var current = CoalescedPropertyValue(); editor.AddChangeLateWatcher(current, v => editor.Text = v.IsDefined ? v.Value : ManyValuesText); button.Clicked += () => { var window = new TextEditorDialog(editorParams.DisplayName ?? editorParams.PropertyName, editor.Text, (s) => { SetProperty(s); }); }; editor.Submitted += text => Submit(); editor.AddChangeLateWatcher(() => editor.Text, text => { if (first) { first = false; return; } if (!editor.IsFocused()) { return; } if (submitted) { Document.Current.History.Undo(); } submitted = true; Submit(); }); editor.AddChangeLateWatcher(() => editor.IsFocused(), focused => { if (submitted) { Document.Current.History.Undo(); } if (!focused) { submitted = false; } }); ManageManyValuesOnFocusChange(editor, current); }
public ShortcutPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { editor = editorParams.EditBoxFactory(); editor.Updating += Updating; editor.Updated += Updated; editor.LayoutCell = new LayoutCell(Alignment.Center); editor.AddChangeLateWatcher(CoalescedPropertyValue(), v => { var text = v.Value.ToString(); editor.Text = v.IsDefined ? v.Value.Main != Key.Unknown ? text : text.Replace("Unknown", "") : ManyValuesText; }); 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.Value.Main; modifiers = value.Value.Modifiers; flatFillPresenter = new WidgetFlatFillPresenter(Theme.Colors.GrayBackground); ContainerWidget.CompoundPresenter.Add(flatFillPresenter); }
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); editor.Submitted += SetValue; editor.AddChangeLateWatcher(CoalescedPropertyValue(), v => editor.Text = v.IsDefined ? v.Value : ManyValuesText); ManageManyValuesOnFocusChange(editor, CoalescedPropertyValue()); }
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; EditorContainer.AddNode(editor); editor.Submitted += text => SetProperty(text); var current = CoalescedPropertyValue(); editor.AddChangeLateWatcher(current, v => editor.Text = v.IsDefined ? v.Value : ManyValuesText); ManageManyValuesOnFocusChange(editor, current); }
public RenderTexturePropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { editor = editorParams.EditBoxFactory(); editor.IsReadOnly = true; editor.LayoutCell = new LayoutCell(Alignment.Center); EditorContainer.AddNode(editor); var current = CoalescedPropertyValue(); editor.AddChangeLateWatcher(current, v => editor.Text = v.Value == null ? "RenderTexture (null)" : $"RenderTexture ({v.Value.ImageSize.Width}x{v.Value.ImageSize.Height})" ); ManageManyValuesOnFocusChange(editor, current); }
protected FilePropertyEditor(IPropertyEditorParams editorParams, string[] allowedFileTypes) : base(editorParams) { ThemedButton button; this.allowedFileTypes = allowedFileTypes; 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); button.Clicked += OnSelectClicked; 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('/'); }); ContainerWidget.AddChangeWatcher(() => ShowPrefix, show => { Expanded = show && Expanded; ExpandButton.Visible = show; }); var current = CoalescedPropertyValue(); editor.AddChangeLateWatcher(current, v => editor.Text = ValueToStringConverter(v.Value) ?? ""); ManageManyValuesOnFocusChange(editor, current); }
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 += SetComponent; var current = CoalescedPropertyValue(); editor.AddChangeLateWatcher(current, v => { editor.Text = v.IsDefined ? v.Value?.Id: ManyValuesText; }); ManageManyValuesOnFocusChange(editor, current); }
public TriggerPropertyEditor(IPropertyEditorParams editorParams, bool multiline = false) : base(editorParams) { if (EditorParams.Objects.Skip(1).Any()) { EditorContainer.AddNode(CreateWarning("Edit of triggers isn't supported for multiple selection.")); return; } node = (Node)editorParams.Objects.First(); var button = new ThemedButton { Text = "...", MinMaxWidth = 20, LayoutCell = new LayoutCell(Alignment.Center) }; var color = button.GlobalColor; EditorContainer.AddNode(editBox = editorParams.EditBoxFactory()); EditorContainer.AddNode(Spacer.HSpacer(4)); EditorContainer.AddNode(button); EditorContainer.AddNode(Spacer.HStretch()); editBox.Submitted += text => { var newValue = FilterTriggers(text); editBox.Text = newValue; SetProperty(newValue); }; button.Clicked += () => { var window = new TriggerSelectionDialog( GetAvailableTriggers(), new HashSet <string>(CurrentTriggers), s => { s = FilterTriggers(s); SetProperty(s); editBox.Text = s; } ); }; editBox.AddChangeLateWatcher(CoalescedPropertyValue(), v => editBox.Text = v.Value); Invalidate(); }
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); }