Skip to content

Commit

Permalink
DYN-7945 pin home button when reducing library size (#15692)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnenov authored Dec 2, 2024
1 parent 715fabd commit f2db372
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 74 deletions.
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ Dynamo.Controls.LacingToVisibilityConverter
Dynamo.Controls.LacingToVisibilityConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.LacingToVisibilityConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.LacingToVisibilityConverter.LacingToVisibilityConverter() -> void
Dynamo.Controls.LeftMarginConverter
Dynamo.Controls.LeftMarginConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.LeftMarginConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.LeftMarginConverter.LeftMarginConverter() -> void
Dynamo.Controls.LeftThicknessConverter
Dynamo.Controls.LeftThicknessConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.LeftThicknessConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Expand Down Expand Up @@ -2003,6 +2007,8 @@ Dynamo.ViewModels.DynamoViewModel.LogText.get -> string
Dynamo.ViewModels.DynamoViewModel.MainGuideManager.get -> Dynamo.Wpf.UI.GuidedTour.GuidesManager
Dynamo.ViewModels.DynamoViewModel.MainGuideManager.set -> void
Dynamo.ViewModels.DynamoViewModel.MakeNewHomeWorkspace(object parameter) -> void
Dynamo.ViewModels.DynamoViewModel.MinLeftMarginOffset.get -> double
Dynamo.ViewModels.DynamoViewModel.MinLeftMarginOffset.set -> void
Dynamo.ViewModels.DynamoViewModel.Model.get -> Dynamo.Models.DynamoModel
Dynamo.ViewModels.DynamoViewModel.MutateTestDelegateCommand.get -> Dynamo.UI.Commands.DelegateCommand
Dynamo.ViewModels.DynamoViewModel.MutateTestDelegateCommand.set -> void
Expand Down
18 changes: 18 additions & 0 deletions src/DynamoCoreWpf/UI/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,24 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste
}
}

/// <summary>
/// A custom converter to 'pin' the location of the Home button in place when the slider goes under a certain value
/// Do not use for other purposes, and please, do not change
/// </summary>
public class LeftMarginConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double offset = (double)value;
return new System.Windows.Thickness(offset * 1, 0, offset * -1, 0);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}

public class PathToFileNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
Expand Down
123 changes: 54 additions & 69 deletions src/DynamoCoreWpf/UI/Themes/Modern/DynamoConverters.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Dynamo.Controls;assembly=DynamoCoreWpf"
xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf">
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Dynamo.Controls;assembly=DynamoCoreWpf"
xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf">

<ResourceDictionary.MergedDictionaries>
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoColorsAndBrushesDictionaryUri}" />
Expand All @@ -11,45 +10,38 @@
<controls:ToolTipFirstLineOnly x:Key="ToolTipFirstLine" />
<controls:ToolTipAllLinesButFirst x:Key="ToolTipFirstLineNot" />
<controls:WorkspaceTypeConverter x:Key="WorkspaceTypeConverter" />
<controls:WorkspaceBackgroundColorConverter
x:Key="WorkspaceBackgroundColorConverter"
CustomBackgroundColor="{StaticResource WorkspaceBackgroundCustom}"
HomeBackgroundColor="{StaticResource WorkspaceBackgroundHome}" />
<controls:WorkspaceBackgroundBrushConverter
x:Key="WorkspaceBackgroundBrushConverter"
CustomBackgroundBrush="{StaticResource WorkspaceBackgroundCustomBrush}"
HomeBackgroundBrush="{StaticResource WorkspaceBackgroundHomeBrush}" />
<controls:WorkspaceBackgroundColorConverter x:Key="WorkspaceBackgroundColorConverter"
CustomBackgroundColor="{StaticResource WorkspaceBackgroundCustom}"
HomeBackgroundColor="{StaticResource WorkspaceBackgroundHome}" />
<controls:WorkspaceBackgroundBrushConverter x:Key="WorkspaceBackgroundBrushConverter"
CustomBackgroundBrush="{StaticResource WorkspaceBackgroundCustomBrush}"
HomeBackgroundBrush="{StaticResource WorkspaceBackgroundHomeBrush}" />

<controls:MarginConverter x:Key="MarginConverter" />

<controls:BooleanToBrushConverter
x:Key="BooleanToBrushConverter"
FalseBrush="Black"
TrueBrush="#6AC0E7" />
<controls:BooleanToBrushConverter x:Key="BooleanToBrushConverter"
FalseBrush="Black"
TrueBrush="#6AC0E7" />

<controls:BooleanToBrushConverter
x:Key="PortConnectedBooleanToBrushConverter"
FalseBrush="White"
TrueBrush="Black" />
<controls:BooleanToBrushConverter x:Key="PortConnectedBooleanToBrushConverter"
FalseBrush="White"
TrueBrush="Black" />

<controls:BooleanToSelectionColorConverter
x:Key="BooleanToSelectionColorConverter"
False="#444"
True="#6AC0E7" />
<controls:BooleanToSelectionColorConverter x:Key="BooleanToSelectionColorConverter"
False="#444"
True="#6AC0E7" />

<controls:ConnectionStateToColorConverter
x:Key="ConnectionStateToColorConverter"
ExecutionPreview="#F2930C"
None="#444"
Selection="#6AC0E7"
Hover="#808080"/>
<controls:ConnectionStateToColorConverter x:Key="ConnectionStateToColorConverter"
ExecutionPreview="#F2930C"
Hover="#808080"
None="#444"
Selection="#6AC0E7" />

<controls:ConnectionStateToBrushConverter x:Key="ConnectionStateToBrushConverter"
ExecutionPreviewBrush="#F2930C"
SelectionBrush="#6AC0E7"
HoverBrush="#808080"
NoneBrush="#444">
</controls:ConnectionStateToBrushConverter>
NoneBrush="#444"
SelectionBrush="#6AC0E7" />

<controls:ConnectionStateToVisibilityCollapsedConverter x:Key="ConnectionStateToVisibilityCollapsedConverter" />
<controls:AttachmentToPathConverter x:Key="AttachmentToPathConverter" />
Expand Down Expand Up @@ -86,15 +78,15 @@
<controls:AutoLacingToVisibilityConverter x:Key="AutoLacingToVisibilityConverter" />
<controls:LacingToAbbreviationConverter x:Key="LacingToAbbreviationConverter" />
<controls:LacingToTooltipConverter x:Key="LacingToTooltipConverter" />
<controls:NodeWarningConverter x:Key="NodeWarningConverter"/>
<controls:NodeWarningConverter x:Key="NodeWarningConverter" />
<controls:NodeOriginalNameToMarginConverter x:Key="NodeOriginalNameToMarginConverter" />
<controls:BoolToFAIconNameConverter x:Key="BoolToFAIconNameConverter" />
<controls:BoolToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<controls:BoolToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
<controls:InverseBooleanToVisibilityCollapsedConverter x:Key="InverseBoolToVisibilityCollapsedConverter" />
<controls:EmptyToVisibilityCollapsedConverter x:Key="EmptyToVisibilityCollapsedConverter" />
<controls:ZeroToVisibilityCollapsedConverter x:Key="ZeroToVisibilityCollapsedConverter" />
<controls:EmptyToZeroLengthConverter x:Key="EmptyToZeroLengthConverter"/>
<controls:ZeroToVisibilityCollapsedConverter x:Key="ZeroToVisibilityCollapsedConverter" />
<controls:EmptyToZeroLengthConverter x:Key="EmptyToZeroLengthConverter" />
<controls:NavigationToOpacityConverter x:Key="NavigationToOpacityConverter" />
<controls:ViewButtonClipRectConverter x:Key="ViewButtonClipRectConverter" />
<controls:ZoomToOpacityConverter x:Key="ZoomToOpacityConverter" />
Expand Down Expand Up @@ -131,14 +123,12 @@
<controls:SearchHighlightMarginConverter x:Key="SearchHighlightMarginConverter" />
<controls:ConfidenceScoreFormattingConverter x:Key="ConfidenceScoreFormattingConverter" />
<controls:InOutParamTypeConverter x:Key="InOutParamTypeConverter" />
<controls:NodeTypeToColorConverter
x:Key="NodeTypeToColorConverter"
FalseBrush="#777777"
TrueBrush="#cccccc" />
<controls:BooleanToBrushConverter
x:Key="DescriptionToColorConverter"
FalseBrush="#666666"
TrueBrush="#cccccc" />
<controls:NodeTypeToColorConverter x:Key="NodeTypeToColorConverter"
FalseBrush="#777777"
TrueBrush="#cccccc" />
<controls:BooleanToBrushConverter x:Key="DescriptionToColorConverter"
FalseBrush="#666666"
TrueBrush="#cccccc" />
<controls:GroupFontSizeToEditorEnabledConverter x:Key="GroupFontSizeToEditorEnabledConverter" />
<controls:ElementTypeToShortConverter x:Key="ElementTypeToShortConverter" />
<controls:GroupTitleVisibilityConverter x:Key="GroupTitleVisibilityConverter" />
Expand All @@ -157,35 +147,30 @@
<controls:ClassViewMarginConverter x:Key="ClassViewMarginConverter" />
<controls:ElementGroupToColorConverter x:Key="ElementGroupToColorConverter" />
<controls:RgbaStringToBrushConverter x:Key="RgbaStringToBrushConverter" />
<controls:BooleanToBrushConverter
x:Key="FilterIsSelertedCategoryToBrushConverter"
FalseBrush="{StaticResource FilterCategoryIsNotSelectedColor}"
TrueBrush="{StaticResource CommonSidebarTextColor}" />
<controls:BooleanToBrushConverter
x:Key="FilterIconForegroundConverter"
FalseBrush="{StaticResource LibraryItemHostBackground}"
TrueBrush="{StaticResource FilterIconColor}" />
<controls:BooleanToBrushConverter
x:Key="FilterIsSelertedCategoryForegroundConverter"
FalseBrush="{StaticResource NodeCategoryForeground}"
TrueBrush="{StaticResource NodeNameForeground}" />
<controls:BooleanToBrushConverter
x:Key="CompactLayoutForegroundConverter"
FalseBrush="{StaticResource NodeNameForeground}"
TrueBrush="{StaticResource UnSelectedLayoutForeground}" />
<controls:BooleanToBrushConverter
x:Key="DetailedLayoutForegroundConverter"
FalseBrush="{StaticResource UnSelectedLayoutForeground}"
TrueBrush="{StaticResource NodeNameForeground}" />
<controls:BooleanToBrushConverter
x:Key="PinIconForegroundConverter"
FalseBrush="{StaticResource UnpinnedIconForegroundColor}"
TrueBrush="{StaticResource PinnedIconForegroundColor}" />
<controls:BooleanToBrushConverter x:Key="FilterIsSelertedCategoryToBrushConverter"
FalseBrush="{StaticResource FilterCategoryIsNotSelectedColor}"
TrueBrush="{StaticResource CommonSidebarTextColor}" />
<controls:BooleanToBrushConverter x:Key="FilterIconForegroundConverter"
FalseBrush="{StaticResource LibraryItemHostBackground}"
TrueBrush="{StaticResource FilterIconColor}" />
<controls:BooleanToBrushConverter x:Key="FilterIsSelertedCategoryForegroundConverter"
FalseBrush="{StaticResource NodeCategoryForeground}"
TrueBrush="{StaticResource NodeNameForeground}" />
<controls:BooleanToBrushConverter x:Key="CompactLayoutForegroundConverter"
FalseBrush="{StaticResource NodeNameForeground}"
TrueBrush="{StaticResource UnSelectedLayoutForeground}" />
<controls:BooleanToBrushConverter x:Key="DetailedLayoutForegroundConverter"
FalseBrush="{StaticResource UnSelectedLayoutForeground}"
TrueBrush="{StaticResource NodeNameForeground}" />
<controls:BooleanToBrushConverter x:Key="PinIconForegroundConverter"
FalseBrush="{StaticResource UnpinnedIconForegroundColor}"
TrueBrush="{StaticResource PinnedIconForegroundColor}" />
<controls:NestedGroupsLabelConverter x:Key="NestedGroupsLabelConverter" />
<controls:CollectionHasMoreThanNItemsToBoolConverter x:Key="CollectionHasMoreThanNItemsToBoolConverter" />
<controls:ListHasMoreThanNItemsToVisibilityConverter x:Key="ListHasMoreThanNItemsToVisibilityConverter" />
<controls:ObjectTypeConverter x:Key="ObjectTypeConverter" />
<controls:TextForegroundSaturationColorConverter x:Key="TextForegroundSaturationColorConverter" />
<controls:PortTypeToStringConverter x:Key="PortTypeToStringConverter" />
<controls:BooleanNegationConverter x:Key="BooleanNegationConverter" />
<controls:LeftMarginConverter x:Key="LeftMarginConverter" />
</ResourceDictionary>
17 changes: 17 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,23 @@ public int ConsoleHeight
}
}

private double minLeftMarignOffset;
/// <summary>
/// The
/// </summary>
public double MinLeftMarginOffset
{
get => minLeftMarignOffset;
set
{
if(minLeftMarignOffset != value)
{
minLeftMarignOffset = value;
RaisePropertyChanged(nameof(MinLeftMarginOffset));
}
}
}

/// <summary>
/// Indicates if preview bubbles should be displayed on nodes.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@
<Button Name="HomeButton"
Width="42"
Height="42"
Margin="{Binding MinLeftMarginOffset, Converter={StaticResource LeftMarginConverter}}"
BorderThickness="0"
Click="HomeButton_Click"
Cursor="Hand">
Expand Down
34 changes: 29 additions & 5 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public DynamoView(DynamoViewModel dynamoViewModel)
}

DefaultMinWidth = MinWidth;
PinHomeButton();
}
private void OnRequestCloseHomeWorkSpace()
{
Expand Down Expand Up @@ -2925,17 +2926,18 @@ private void WorkspaceTabs_SizeChanged(object sender, SizeChangedEventArgs e)
UpdateLibraryCollapseIcon();
}

// The Workspace TabItems must appear to the right of icon buttons (New File, Open, Save, Undo, Redo)
// but never overlap them. 230 is the minimum offset required to achieve this.
// If the library panel is stretched greater than 230, they must align with its width instead.
private const int FirstTabItemMinimumLeftMarginOffset = 230;
private const int LibraryScrollBarWidth = 15;

/// <summary>
/// Updates the workspace TabItems to have the correct margins in response to events
/// such as the library being stretched or a Custom Node workspace being created.
/// </summary>
private void UpdateWorkspaceTabSizes()
{
// The Workspace TabItems must appear to the right of icon buttons (New File, Open, Save, Undo, Redo)
// but never overlap them. 230 is the minimum offset required to achieve this.
// If the library panel is stretched greater than 230, they must align with its width instead.
const int FirstTabItemMinimumLeftMarginOffset = 230;
const int LibraryScrollBarWidth = 15;

// We measure the full library width at runtime.
int fullLibraryWidth = dynamoViewModel.LibraryWidth + LibraryScrollBarWidth;
Expand All @@ -2960,6 +2962,8 @@ private void UpdateWorkspaceTabSizes()
{
tabItem.Margin = new System.Windows.Thickness(-leftMargin, 0, leftMargin, 0);
}

PinHomeButton();
}

private void DynamoView_OnDrop(object sender, DragEventArgs e)
Expand Down Expand Up @@ -3085,6 +3089,26 @@ private void TabItem_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
this.dynamoViewModel.ShowStartPage = false;
}

private void PinHomeButton()
{
const int minimumLeftMarginOffset = FirstTabItemMinimumLeftMarginOffset - LibraryScrollBarWidth;

var parentGrid = (Grid)verticalSplitter.Parent;
var columnWidth = parentGrid.ColumnDefinitions[0].ActualWidth == 0
? dynamoViewModel.LibraryWidth + LibraryScrollBarWidth
: parentGrid.ColumnDefinitions[0].ActualWidth;

// Constrain the position of the HomeButton.
if (columnWidth < minimumLeftMarginOffset)
{
this.dynamoViewModel.MinLeftMarginOffset = minimumLeftMarginOffset - columnWidth;
}
else
{
this.dynamoViewModel.MinLeftMarginOffset = 0;
}
}

public void Dispose()
{
viewExtensionManager.Dispose();
Expand Down

0 comments on commit f2db372

Please sign in to comment.