mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Editor - Autofit surface on open
Data model picker - Expand on double click
This commit is contained in:
1 parent
b0c7dd4290
commit
e401fdf964
5 files changed
+86
-8
No files matched your search
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user