mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Editor - Autofit surface on open
Data model picker - Expand on double click
This commit is contained in:
parent
b0c7dd4290
commit
e401fdf964
@ -13,6 +13,8 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.LogicalTree;
|
||||
using Avalonia.Threading;
|
||||
using Material.Icons.Avalonia;
|
||||
using ReactiveUI;
|
||||
@ -129,7 +131,7 @@ public class DataModelPicker : TemplatedControl
|
||||
get => GetValue(DataModelViewModelProperty);
|
||||
private set => SetValue(DataModelViewModelProperty, value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A list of types to filter the selectable paths on.
|
||||
/// </summary>
|
||||
@ -246,6 +248,13 @@ public class DataModelPicker : TemplatedControl
|
||||
DataModelPath = new DataModelPath(dataModelEvent.DataModelPath);
|
||||
}
|
||||
|
||||
private void DataModelTreeViewOnDoubleTapped(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
TreeViewItem? treeViewItem = (e.Source as ILogical)?.FindLogicalAncestorOfType<TreeViewItem>();
|
||||
if (treeViewItem != null)
|
||||
treeViewItem.IsExpanded = !treeViewItem.IsExpanded;
|
||||
}
|
||||
|
||||
private void UpdateCurrentPath(bool selectCurrentPath)
|
||||
{
|
||||
if (DataModelPath == null)
|
||||
@ -278,6 +287,8 @@ public class DataModelPicker : TemplatedControl
|
||||
{
|
||||
if (_dataModelTreeView != null)
|
||||
_dataModelTreeView.SelectionChanged -= DataModelTreeViewOnSelectionChanged;
|
||||
if (_dataModelTreeView != null)
|
||||
_dataModelTreeView.DoubleTapped -= DataModelTreeViewOnDoubleTapped;
|
||||
|
||||
_currentPathIcon = e.NameScope.Find<MaterialIcon>("CurrentPathIcon");
|
||||
_currentPathDisplay = e.NameScope.Find<TextBlock>("CurrentPathDisplay");
|
||||
@ -286,6 +297,8 @@ public class DataModelPicker : TemplatedControl
|
||||
|
||||
if (_dataModelTreeView != null)
|
||||
_dataModelTreeView.SelectionChanged += DataModelTreeViewOnSelectionChanged;
|
||||
if (_dataModelTreeView != null)
|
||||
_dataModelTreeView.DoubleTapped += DataModelTreeViewOnDoubleTapped;
|
||||
}
|
||||
|
||||
#region Overrides of Visual
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
</Grid.Transitions>
|
||||
|
||||
<!-- The bottom layer consists of devices -->
|
||||
<ItemsControl Items="{CompiledBinding Devices}" ClipToBounds="False">
|
||||
<ItemsControl Name="DevicesContainer" Items="{CompiledBinding Devices}" ClipToBounds="False">
|
||||
<ItemsControl.Styles>
|
||||
<Style Selector="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding X}" />
|
||||
|
||||
@ -1,15 +1,22 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.PanAndZoom;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.VisualEditor;
|
||||
|
||||
public class VisualEditorView : ReactiveUserControl<VisualEditorViewModel>
|
||||
{
|
||||
private readonly ZoomBorder _zoomBorder;
|
||||
private bool _movedByUser;
|
||||
|
||||
public VisualEditorView()
|
||||
{
|
||||
@ -17,7 +24,37 @@ public class VisualEditorView : ReactiveUserControl<VisualEditorViewModel>
|
||||
|
||||
_zoomBorder = this.Find<ZoomBorder>("ZoomBorder");
|
||||
_zoomBorder.PropertyChanged += ZoomBorderOnPropertyChanged;
|
||||
_zoomBorder.PointerMoved += ZoomBorderOnPointerMoved;
|
||||
_zoomBorder.PointerWheelChanged += ZoomBorderOnPointerWheelChanged;
|
||||
UpdateZoomBorderBackground();
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
ViewModel!.AutoFitRequested += ViewModelOnAutoFitRequested;
|
||||
Disposable.Create(() => ViewModel.AutoFitRequested -= ViewModelOnAutoFitRequested).DisposeWith(d);
|
||||
});
|
||||
|
||||
this.WhenAnyValue(v => v.Bounds).Subscribe(_ =>
|
||||
{
|
||||
if (!_movedByUser)
|
||||
AutoFit(true);
|
||||
});
|
||||
}
|
||||
|
||||
private void ZoomBorderOnPointerWheelChanged(object? sender, PointerWheelEventArgs e)
|
||||
{
|
||||
_movedByUser = true;
|
||||
}
|
||||
|
||||
private void ZoomBorderOnPointerMoved(object? sender, PointerEventArgs e)
|
||||
{
|
||||
if (e.GetCurrentPoint(_zoomBorder).Properties.IsMiddleButtonPressed)
|
||||
_movedByUser = true;
|
||||
}
|
||||
|
||||
private void ViewModelOnAutoFitRequested(object? sender, EventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => AutoFit(false));
|
||||
}
|
||||
|
||||
private void ZoomBorderOnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
@ -41,4 +78,27 @@ public class VisualEditorView : ReactiveUserControl<VisualEditorViewModel>
|
||||
{
|
||||
UpdateZoomBorderBackground();
|
||||
}
|
||||
|
||||
private void AutoFit(bool skipTransitions)
|
||||
{
|
||||
if (ViewModel == null)
|
||||
return;
|
||||
|
||||
double left = ViewModel.Devices.Select(d => d.Rectangle.Left).Min();
|
||||
double top = ViewModel.Devices.Select(d => d.Rectangle.Top).Min();
|
||||
double bottom = ViewModel.Devices.Select(d => d.Rectangle.Bottom).Max();
|
||||
double right = ViewModel.Devices.Select(d => d.Rectangle.Right).Max();
|
||||
|
||||
// Add a 10 pixel margin around the rect
|
||||
Rect scriptRect = new(new Point(left - 10, top - 10), new Point(right + 10, bottom + 10));
|
||||
|
||||
// The scale depends on the available space
|
||||
double scale = Math.Min(3, Math.Min(Bounds.Width / scriptRect.Width, Bounds.Height / scriptRect.Height));
|
||||
|
||||
// Pan and zoom to make the script fit
|
||||
_zoomBorder.Zoom(scale, 0, 0, skipTransitions);
|
||||
_zoomBorder.Pan(Bounds.Center.X - scriptRect.Center.X * scale, Bounds.Center.Y - scriptRect.Center.Y * scale, skipTransitions);
|
||||
|
||||
_movedByUser = false;
|
||||
}
|
||||
}
|
||||
@ -113,4 +113,11 @@ public class VisualEditorViewModel : ActivatableViewModelBase
|
||||
visualizerViewModels.Add(_vmFactory.LayerShapeVisualizerViewModel(layer));
|
||||
visualizerViewModels.Add(_vmFactory.LayerVisualizerViewModel(layer));
|
||||
}
|
||||
|
||||
public void RequestAutoFit()
|
||||
{
|
||||
AutoFitRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public event EventHandler? AutoFitRequested;
|
||||
}
|
||||
@ -2,13 +2,11 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:screens="clr-namespace:Artemis.VisualScripting.Nodes.Operators.Screens"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.VisualScripting.Nodes.Operators.Screens.EnumEqualsNodeCustomView"
|
||||
x:DataType="screens:EnumEqualsNodeCustomViewModel">
|
||||
<ComboBox IsEnabled="{CompiledBinding EnumValues.Count}"
|
||||
Items="{CompiledBinding EnumValues}"
|
||||
SelectedItem="{CompiledBinding CurrentValue}"
|
||||
x:Class="Artemis.VisualScripting.Nodes.Operators.Screens.EnumEqualsNodeCustomView">
|
||||
<ComboBox IsEnabled="{Binding EnumValues.Count}"
|
||||
Items="{Binding EnumValues}"
|
||||
SelectedItem="{Binding CurrentValue}"
|
||||
VirtualizationMode="Simple"
|
||||
PlaceholderText="Select a value"
|
||||
Classes="condensed"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user