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

Fix custom border thickness causing layout shifting #72

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

> - Breaking Changes:
> - Features:
> - Added ItemContainer.SelectedBorderThickness dependency property
> - Bugfixes:
> - Fixed PendingConnection.PreviewTarget not being set to null when there is no actual target
> - Fixed connectors panel not being affected by Node.VerticalAlignment
> - Changing BorderThickness causes layout shift when selecting an item container

#### **Version 5.0.2**

Expand Down
1 change: 1 addition & 0 deletions Examples/Nodify.Calculator/EditorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Setter Property="ActualSize"
Value="{Binding Size, Mode=OneWayToSource}" />
<Setter Property="BorderBrush" Value="{Binding BorderBrush, Source={StaticResource AnimatedBorderPlaceholder}}" />
<Setter Property="BorderThickness" Value="2" />
</Style>
</UserControl.Resources>

Expand Down
6 changes: 5 additions & 1 deletion Examples/Nodify.Playground/Editor/NodifyEditorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
<Setter.Value>
<DataTemplate DataType="{x:Type local:ConnectorViewModel}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Title}" Margin="0 0 5 0" />
<TextBlock Text="{Binding Title}" Margin="0 0 5 0" VerticalAlignment="Center" />
<ComboBox DisplayMemberPath="Name"
SelectedValuePath="Value"
SelectedValue="{Binding Shape}"
Expand Down Expand Up @@ -383,6 +383,10 @@
<nodify:NodifyEditor.ItemContainerStyle>
<Style TargetType="{x:Type nodify:ItemContainer}"
BasedOn="{StaticResource {x:Type nodify:ItemContainer}}">
<Setter Property="BorderThickness"
Value="2" />
<Setter Property="SelectedBorderThickness"
Value="4" />
<Setter Property="CacheMode">
<Setter.Value>
<BitmapCache RenderAtScale="{Binding MaxZoom, Source={x:Static local:EditorSettings.Instance}}" EnableClearType="True" />
Expand Down
1 change: 1 addition & 0 deletions Nodify/Helpers/BoxValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static class BoxValue
public static readonly object Int1 = 1;
public static readonly object UInt1 = 1u;

public static readonly object Thickness2 = new Thickness(2);
public static readonly object ArrowSize = new Size(8, 8);
public static readonly object ConnectionOffset = new Size(14, 0);
}
Expand Down
19 changes: 19 additions & 0 deletions Nodify/ItemContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ItemContainer : ContentControl, INodifyCanvasItem

public static readonly DependencyProperty HighlightBrushProperty = DependencyProperty.Register(nameof(HighlightBrush), typeof(Brush), typeof(ItemContainer));
public static readonly DependencyProperty SelectedBrushProperty = DependencyProperty.Register(nameof(SelectedBrush), typeof(Brush), typeof(ItemContainer));
public static readonly DependencyProperty SelectedBorderThicknessProperty = DependencyProperty.Register(nameof(SelectedBorderThickness), typeof(Thickness), typeof(ItemContainer), new FrameworkPropertyMetadata(BoxValue.Thickness2));
public static readonly DependencyProperty IsSelectableProperty = DependencyProperty.Register(nameof(IsSelectable), typeof(bool), typeof(ItemContainer), new FrameworkPropertyMetadata(BoxValue.True));
public static readonly DependencyProperty IsSelectedProperty = Selector.IsSelectedProperty.AddOwner(typeof(ItemContainer), new FrameworkPropertyMetadata(BoxValue.False, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsSelectedChanged));
public static readonly DependencyPropertyKey IsPreviewingSelectionPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsPreviewingSelection), typeof(bool?), typeof(ItemContainer), new FrameworkPropertyMetadata(null));
Expand Down Expand Up @@ -51,6 +52,15 @@ public Brush SelectedBrush
set => SetValue(SelectedBrushProperty, value);
}

/// <summary>
/// Gets or sets the border thickness used when <see cref="IsSelected"/> or <see cref="IsPreviewingSelection"/> is true.
/// </summary>
public Thickness SelectedBorderThickness
{
get => (Thickness)GetValue(SelectedBorderThicknessProperty);
set => SetValue(SelectedBorderThicknessProperty, value);
}

/// <summary>
/// Gets or sets the location of this <see cref="ItemContainer"/> inside the <see cref="NodifyEditor"/> in graph space coordinates.
/// </summary>
Expand Down Expand Up @@ -246,6 +256,15 @@ private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyCh
/// </summary>
public NodifyEditor Editor { get; }

/// <summary>
/// The calculated margin when the container is selected or previewing selection.
/// </summary>
public Thickness SelectedMargin => new Thickness(
BorderThickness.Left - SelectedBorderThickness.Left,
BorderThickness.Top - SelectedBorderThickness.Top,
BorderThickness.Right - SelectedBorderThickness.Right,
BorderThickness.Bottom - SelectedBorderThickness.Bottom);

#endregion

/// <summary>
Expand Down
20 changes: 11 additions & 9 deletions Nodify/Themes/Styles/ItemContainer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<Style TargetType="{x:Type local:ItemContainer}">
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="SelectedBorderThickness"
Value="2" />
<Setter Property="BorderBrush"
Value="DodgerBlue" />
<Setter Property="SelectedBrush"
Expand Down Expand Up @@ -59,29 +61,29 @@
<MultiTrigger.Setters>
<Setter Property="BorderBrush"
Value="{Binding SelectedBrush, RelativeSource={RelativeSource Self}}" />
<Setter Property="BorderThickness"
Value="2" />
<Setter Property="Margin"
Value="-1" />
Value="{Binding SelectedMargin, RelativeSource={RelativeSource Self}}" />
<Setter Property="BorderThickness"
Value="{Binding SelectedBorderThickness, RelativeSource={RelativeSource Self}}" />
</MultiTrigger.Setters>
</MultiTrigger>
<Trigger Property="IsPreviewingSelection"
Value="True">
<Setter Property="BorderBrush"
Value="{Binding SelectedBrush, RelativeSource={RelativeSource Self}}" />
<Setter Property="BorderThickness"
Value="2" />
<Setter Property="Margin"
Value="-1" />
Value="{Binding SelectedMargin, RelativeSource={RelativeSource Self}}" />
<Setter Property="BorderThickness"
Value="{Binding SelectedBorderThickness, RelativeSource={RelativeSource Self}}" />
</Trigger>
<Trigger Property="local:PendingConnection.IsOverElement"
Value="True">
<Setter Property="BorderBrush"
Value="{Binding HighlightBrush, RelativeSource={RelativeSource Self}}" />
<Setter Property="BorderThickness"
Value="2" />
<Setter Property="Margin"
Value="-1" />
Value="{Binding SelectedMargin, RelativeSource={RelativeSource Self}}" />
<Setter Property="BorderThickness"
Value="{Binding SelectedBorderThickness, RelativeSource={RelativeSource Self}}" />
</Trigger>
</Style.Triggers>
</Style>
Expand Down