Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dyn 5530 library zoom scaling #13733

Merged
merged 15 commits into from
Feb 16, 2023
Merged
7 changes: 7 additions & 0 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public bool IsADPAnalyticsReportingApproved
/// </summary>
public bool ShowConnectorToolTip { get; set; }

/// <summary>
/// Indicates the zoom scale of the library
/// </summary>
public double LibraryZoomScale { get; set; }

/// <summary>
/// The types of connector: Bezier or Polyline.
/// </summary>
Expand Down Expand Up @@ -777,6 +782,8 @@ public PreferenceSettings()
BackupFilesCount = 1;
BackupFiles = new List<string>();

LibraryZoomScale = 1;

CustomPackageFolders = new List<string>();

PythonTemplateFilePath = "";
Expand Down
5 changes: 3 additions & 2 deletions src/DynamoCoreWpf/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -46,6 +46,7 @@
[assembly: InternalsVisibleTo("GraphMetadataViewExtension")]
[assembly: InternalsVisibleTo("PackageDetailsViewExtension")]
[assembly: InternalsVisibleTo("Notifications")]
[assembly: InternalsVisibleTo("LibraryViewExtensionWebView2")]
[assembly: InternalsVisibleTo("IronPythonTests")]
[assembly: InternalsVisibleTo("DynamoPackagesWPF")]
[assembly: InternalsVisibleTo("DynamoPlayerExtension")]
Expand All @@ -56,4 +57,4 @@
[assembly: TypeForwardedTo(typeof(Dynamo.Wpf.Interfaces.LayoutElement))]
[assembly: TypeForwardedTo(typeof(Dynamo.Wpf.Interfaces.LayoutElementType))]
[assembly: TypeForwardedTo(typeof(Dynamo.Wpf.Interfaces.LayoutIncludeInfo))]
[assembly: TypeForwardedTo(typeof(Dynamo.Wpf.Interfaces.ILibraryViewCustomization))]
[assembly: TypeForwardedTo(typeof(Dynamo.Wpf.Interfaces.ILibraryViewCustomization))]
9 changes: 9 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3488,4 +3488,7 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="GroupContextMenuPreview" xml:space="preserve">
<value>Preview Geometry</value>
</data>
<data name="LibraryZoomScaleTooltipText" xml:space="preserve">
<value>Drag to adjust Library zoom scale between 10% and 300%. You can also adjust this in Library by pressing “Shift” and scrolling the mouse wheel.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3475,4 +3475,7 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="GroupContextMenuPreview" xml:space="preserve">
<value>Preview Geometry</value>
</data>
<data name="LibraryZoomScaleTooltipText" xml:space="preserve">
<value>Drag to adjust Library zoom scale between 10% and 300%. You can also adjust this in Library by pressing “Shift” and scrolling the mouse wheel.</value>
</data>
</root>
71 changes: 71 additions & 0 deletions src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5487,4 +5487,75 @@
</Style.Triggers>
</Style>

<!-- Custom Slider -->
<Style x:Key="SliderRepeatButton" TargetType="RepeatButton">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="IsTabStop" Value="false" />
<Setter Property="Focusable" Value="false" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border BorderThickness="1" BorderBrush="#757575" Background="#757575" Height="3"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="SliderRepeatButton1" TargetType="RepeatButton">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border SnapsToDevicePixels="True" Background="#eeeeee" BorderThickness="1" BorderBrush="#eeeeee" Height="3"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="SliderThumb" TargetType="Thumb">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Border Width="6" Height="20" CornerRadius="1 1 1 1" Background="#eeeeee"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<ControlTemplate x:Key="Slider" TargetType="Slider">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Track Grid.Row="1" x:Name="PART_Track" >
<Track.DecreaseRepeatButton>
<RepeatButton Style="{StaticResource SliderRepeatButton1}" Command="Slider.DecreaseLarge" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource SliderThumb}" />
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Style="{StaticResource SliderRepeatButton}" Command="Slider.IncreaseLarge" />
</Track.IncreaseRepeatButton>
</Track>
</Grid>
</ControlTemplate>

<Style x:Key="SliderStyle" TargetType="Slider">
<Setter Property="Focusable" Value="False"/>
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Style.Triggers>
<Trigger Property="Orientation" Value="Horizontal">
<Setter Property="Template" Value="{StaticResource Slider}" />
</Trigger>
</Style.Triggers>
</Style>

</ResourceDictionary>
10 changes: 9 additions & 1 deletion src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public partial class DynamoView : Window, IDisposable
private int tabSlidingWindowStart, tabSlidingWindowEnd;
private readonly LoginService loginService;
private ShortcutToolbar shortcutBar;
private PreferencesView preferencesWindow;
private bool loaded = false;
// This is to identify whether the PerformShutdownSequenceOnViewModel() method has been
// called on the view model and the process is not cancelled
Expand All @@ -98,6 +99,12 @@ public partial class DynamoView : Window, IDisposable

internal ShortcutToolbar ShortcutBar { get { return shortcutBar; } }

internal PreferencesView PreferencesWindow {
get { return preferencesWindow; }
}

internal event Action OnPreferencesWindowChanged;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library extension didn't have access to the new PreferencesView object created. So, this event was added to be called after a new preferences window is opened.


/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -1866,7 +1873,8 @@ private void OnDebugModesClick(object sender, RoutedEventArgs e)

private void OnPreferencesWindowClick(object sender, RoutedEventArgs e)
{
var preferencesWindow = new PreferencesView(this);
preferencesWindow = new PreferencesView(this);
OnPreferencesWindowChanged();
preferencesWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
preferencesWindow.ShowDialog();
}
Expand Down
64 changes: 64 additions & 0 deletions src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!--Group Styles Expander-->
<Expander x:Name="Styles"
Expand Down Expand Up @@ -1258,6 +1259,69 @@
</StackPanel>
</Grid>
</Expander>

<!--Render Zoom Scaling Expander-->
<Expander x:Name="ZoomScaling"
Grid.Row="3"
Style="{StaticResource MenuExpanderStyle}"
IsExpanded="{Binding PreferencesTabs[VisualSettings].ExpanderActive, Converter={StaticResource ExpandersBindingConverter}, ConverterParameter=ZoomScaling}"
Header="Zoom Scaling">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Margin="0,10,0,5" Grid.Row="0" Orientation="Horizontal">
<TextBlock FontSize="12" Text="Library"></TextBlock>
<Label HorizontalAlignment="Left"
Name="LibraryZoomScaleInfoLabel"
VerticalAlignment="Center"
Height="26"
Width="53">
<Image
Width="14"
Height="14"
Margin="0,0,0,5"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Style="{StaticResource QuestionIcon}"
ToolTipService.ShowDuration="30000">
<Image.ToolTip>
<ToolTip Content="{x:Static p:Resources.LibraryZoomScaleTooltipText}" Style="{StaticResource GenericToolTipLight}"/>
</Image.ToolTip>
</Image>
</Label>
</StackPanel>

<StackPanel Orientation="Horizontal" Grid.Row="1" Margin="0,0,0,3">

<Slider
x:Name="LibraryZoomScalingSlider"
Style="{StaticResource SliderStyle}"
Width="440"
Minimum="0.1"
Maximum="3"
Value="1">
</Slider>
</StackPanel>
<StackPanel Grid.Row="2" Width="550">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="137"></ColumnDefinition>
<ColumnDefinition Width="137"></ColumnDefinition>
<ColumnDefinition Width="137"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="10%" Grid.Column="0"></TextBlock>
<TextBlock Text="100%" Grid.Column="1"></TextBlock>
<TextBlock Text="200%" Grid.Column="2"></TextBlock>
<TextBlock Text="300%" Grid.Column="3"></TextBlock>
</Grid>
</StackPanel>
</Grid>
</Expander>
</Grid>
</TabItem>

Expand Down
9 changes: 7 additions & 2 deletions src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Dynamo.Exceptions;
using Dynamo.Logging;
using Dynamo.UI;
using Dynamo.UI.Views;
using Dynamo.ViewModels;
using Res = Dynamo.Wpf.Properties.Resources;

Expand All @@ -27,6 +28,7 @@ public partial class PreferencesView : Window
{
private readonly PreferencesViewModel viewModel;
private readonly DynamoViewModel dynViewModel;
private readonly DynamoView dynView;
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
private List<GroupStyleItem> originalCustomGroupStyles { get; set; }

// Used for tracking the manage package command event
Expand Down Expand Up @@ -54,12 +56,13 @@ private void StoreOriginalCustomGroupStyles()
/// </summary>
/// <param name="dynamoViewModel"> Dynamo ViewModel</param>
public PreferencesView(DynamoView dynamoView)
{
{
dynView = dynamoView;
dynViewModel = dynamoView.DataContext as DynamoViewModel;
SetupPreferencesViewModel(dynViewModel);

DataContext = dynViewModel.PreferencesViewModel;

InitializeComponent();
Dynamo.Logging.Analytics.TrackEvent(
Actions.Open,
Expand All @@ -81,6 +84,8 @@ public PreferencesView(DynamoView dynamoView)
viewModel.InitializeGeometryScaling();

viewModel.RequestShowFileDialog += OnRequestShowFileDialog;

LibraryZoomScalingSlider.Value = dynViewModel.Model.PreferenceSettings.LibraryZoomScale;
}

/// <summary>
Expand Down
33 changes: 33 additions & 0 deletions src/LibraryViewExtensionWebView2/LibraryViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Dynamo.Controls;
using Dynamo.Extensions;
using Dynamo.LibraryViewExtensionWebView2.Handlers;
using Dynamo.LibraryViewExtensionWebView2.ViewModels;
Expand All @@ -31,6 +32,7 @@ namespace Dynamo.LibraryViewExtensionWebView2
public class LibraryViewController : IDisposable
{
private Window dynamoWindow;
private DynamoView dynamoView;
private ICommandExecutive commandExecutive;
private DynamoViewModel dynamoViewModel;
private FloatingLibraryTooltipPopup libraryViewTooltip;
Expand All @@ -42,6 +44,8 @@ public class LibraryViewController : IDisposable
// TODO remove this when we can control the library state from Dynamo more precisely.
private bool disableObserver = false;

private static readonly string LibrarSlider = "notificationsButton";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used?


private LayoutSpecProvider layoutProvider;
private NodeItemDataProvider nodeProvider;
internal SearchResultDataProvider searchResultDataProvider;
Expand Down Expand Up @@ -72,6 +76,9 @@ internal LibraryViewController(Window dynamoView, ICommandExecutive commandExecu
dynamoWindow.StateChanged += DynamoWindowStateChanged;
dynamoWindow.SizeChanged += DynamoWindow_SizeChanged;

this.dynamoView = dynamoView as DynamoView;
this.dynamoView.OnPreferencesWindowChanged += PreferencesWindowChanged;

DirectoryInfo webBrowserUserDataFolder;
var userDataDir = new DirectoryInfo(dynamoViewModel.Model.PathManager.UserDataDirectory);
webBrowserUserDataFolder = userDataDir.Exists ? userDataDir : null;
Expand All @@ -81,6 +88,16 @@ internal LibraryViewController(Window dynamoView, ICommandExecutive commandExecu
}
}

private void Browser_ZoomFactorChanged(object sender, EventArgs e)
{
dynamoViewModel.Model.PreferenceSettings.LibraryZoomScale = browser.ZoomFactor;
}

void PreferencesWindowChanged()
{
this.dynamoView.PreferencesWindow.LibraryZoomScalingSlider.ValueChanged += DynamoSliderValueChanged;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a new PreferencesWindow is created, the value of the slider is subscribed.

}

//if the window is resized toggle visibility of browser to force redraw
private void DynamoWindow_SizeChanged(object sender, SizeChangedEventArgs e)
{
Expand Down Expand Up @@ -321,6 +338,9 @@ private void Browser_CoreWebView2InitializationCompleted(object sender, CoreWebV
}

SetLibraryFontSize();

browser.ZoomFactor = dynamoViewModel.Model.PreferenceSettings.LibraryZoomScale;
browser.ZoomFactorChanged += Browser_ZoomFactorChanged;
}

private void Browser_Loaded(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -528,6 +548,13 @@ private void InitializeResourceProviders(DynamoModel model, LibraryViewCustomiza
layoutProvider = new LayoutSpecProvider(customization, iconProvider, "Dynamo.LibraryViewExtensionWebView2.web.library.layoutSpecs.json");
}

private void DynamoSliderValueChanged(object sender, EventArgs e)
{
Slider slider = (Slider)sender;
browser.ZoomFactor = slider.Value;
dynamoViewModel.Model.PreferenceSettings.LibraryZoomScale = slider.Value;
}

/// <summary>
/// This method will execute the action of moving the Guide to the next Step (it is triggered when a specific html div that contains the package is clicked).
/// </summary>
Expand Down Expand Up @@ -567,6 +594,12 @@ protected void Dispose(bool disposing)
{
dynamoWindow.StateChanged -= DynamoWindowStateChanged;
dynamoWindow.SizeChanged -= DynamoWindow_SizeChanged;
browser.ZoomFactorChanged -= Browser_ZoomFactorChanged;
this.dynamoView.PreferencesWindow.LibraryZoomScalingSlider.ValueChanged -= DynamoSliderValueChanged;
this.dynamoView.OnPreferencesWindowChanged -= PreferencesWindowChanged;

var dynamoViewWindow = dynamoWindow as DynamoView;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this line here?


dynamoWindow = null;
}
if (this.browser != null)
Expand Down
Loading