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

GridSplitter changes, rebased on top of OG GridSplitter PR #3

Open
wants to merge 22 commits into
base: user/mhawker/gridsplitter
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 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
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
<Content Include="Icons\More.png" />
<Content Include="Icons\Notifications.png" />
<Content Include="Icons\Services.png" />
<Content Include="SamplePages\ContentSizer\ContentSizer.png" />
<Content Include="SamplePages\Animations\Effects\EffectAnimations.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -607,6 +608,7 @@
<Content Include="SamplePages\StaggeredLayout\StaggeredLayout.bind" />
<Content Include="SamplePages\EnumValuesExtension\EnumValuesExtensionXaml.bind" />
<Content Include="SamplePages\EnumValuesExtension\EnumValuesExtensionCode.bind" />
<Content Include="SamplePages\ContentSizer\ContentSizer.bind" />
<Content Include="SamplePages\FocusBehavior\FocusBehaviorXaml.bind" />
<Content Include="SamplePages\AutoFocusBehavior\AutoFocusBehaviorXaml.bind" />
<Content Include="SamplePages\ColorPicker\ColorPickerXaml.bind" />
Expand Down Expand Up @@ -1565,4 +1567,4 @@
</Target>
<!-- No-op to avoid build error when packing solution from commandline -->
<Target Name="Pack" />
</Project>
</Project>
4 changes: 2 additions & 2 deletions Microsoft.Toolkit.Uwp.SampleApp/Pages/SampleController.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@
Width="11"
Background="Transparent"
HorizontalAlignment="Left"
GripperForeground="{ThemeResource Brush-Alt}"
ParentLevel="1" />
ParentLevel="1">
</controls:GridSplitter>
</Grid>

<Border HorizontalAlignment="Stretch"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d">

<Grid x:Name="RootGrid">
<!-- Just to separate our two examples -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<!-- Left-side 'Shelf' -->
<StackPanel Orientation="Horizontal">
<Border x:Name="SideContent"
Background="DarkGreen"
MinWidth="200"
MaxWidth="600">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center">
Side Content
</TextBlock>
</Border>
<controls:ContentSizer TargetControl="{Binding ElementName=SideContent}"/>
</StackPanel>

<!-- Bottom 'Shelf' -->
<controls:Expander x:Name="TopExpander"
VerticalAlignment="Top"
ExpandDirection="Up"
Header="This is some Shelf"
HorizontalContentAlignment="Stretch"
IsExpanded="True"
Grid.Column="1">
<Grid Height="256">
<TextBlock HorizontalAlignment="Center"
TextWrapping="Wrap"
Text="This is the expanded content"
VerticalAlignment="Center"/>
<controls:ContentSizer ResizeDirection="Horizontal" Height="16"
VerticalAlignment="Bottom"/>
</Grid>
</controls:Expander>
</Grid>
</Page>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,28 @@
<controls:GridSplitter
Width="11"
Background="{ThemeResource Brush-Grey-04}"
GripperCursor="Default"
GripperCursor="Arrow"
HorizontalAlignment="Left"
Grid.Column="1"
ResizeDirection="Auto"
ResizeBehavior="BasedOnAlignment"
CursorBehavior="ChangeOnGripperHover"
GripperForeground="{ThemeResource Brush-Alt}">
Foreground="{ThemeResource Brush-Alt}">
</controls:GridSplitter>

<!--Row Grid Splitter-->
<controls:GridSplitter
Grid.Row="1"
Background="{ThemeResource Brush-Grey-04}" Height="11"
HorizontalAlignment="Stretch">
<controls:GridSplitter.Element>
<controls:GridSplitter.Content>
michael-hawker marked this conversation as resolved.
Show resolved Hide resolved
<Grid>
<TextBlock HorizontalAlignment="Center"
IsHitTestVisible="False"
VerticalAlignment="Center"
Text="&#xE76F;"
Foreground="{ThemeResource Brush-Alt}"
FontFamily="Segoe MDL2 Assets"/>
Foreground="{ThemeResource Brush-Alt}" />
</Grid>
</controls:GridSplitter.Element>
</controls:GridSplitter.Content>
</controls:GridSplitter>
</Grid>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@

<!--Column Grid Splitter-->
<controls:GridSplitter
GripperCursor="@[GripperCursor:Enum:GripperCursorType.Default]"
HorizontalAlignment="Left"
Grid.Column="@[Column:Slider:1:0-2]"
ResizeDirection="@[ResizeDirection:Enum:GridResizeDirection.Auto]"
Expand All @@ -85,14 +84,6 @@
<controls:GridSplitter.RenderTransform>
<TranslateTransform Y="-8" />
</controls:GridSplitter.RenderTransform>
<controls:GridSplitter.Element>
Copy link
Author

Choose a reason for hiding this comment

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

BREAKING CHANGE: When removing the reliance upon the now-defunct GripperHoverWrapper class, this then allowed further refactoring, to where this Element property behaved more or less just like the framework Content property, so I refactored the Element property out.

  • The change would be invisible to anyone just using the default GridSplitter settings, and would not introduce any breaking changes.
  • However, for anyone that has a custom implementation of the GridSplitter, this could break the customization after we remove this Element property.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, if we can just use the default Content pattern, then that's going to be fine to remove the custom Element thing. :)

<TextBlock HorizontalAlignment="Center"
IsHitTestVisible="False"
VerticalAlignment="Center"
Text="&#xE76F;"
Foreground="White"
FontFamily="Segoe MDL2 Assets"/>
</controls:GridSplitter.Element>
</controls:GridSplitter>

<VisualStateManager.VisualStateGroups>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<controls:Case IsDefault="True" />
</controls:CaseCollection>
</controls:SwitchPresenter>
<controls:ContentSizer x:Key="ContentSizerControl" />
<controls:ConstrainedBox x:Key="ConstrainedBoxControl" />
<media:AttachedCardShadow x:Key="AttachedShadow" />
<ui:AttachedDropShadow x:Key="AttachedDropShadow" />
Expand Down
9 changes: 9 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@
"Icon": "/SamplePages/ScrollHeader/ScrollHeader.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/behaviors/HeaderBehaviors.md"
},
{
"Name": "ContentSizer",
"Subcategory": "Layout",
"About": "ContentSizer is a general sizing control which can manipulate the size of its parent or other elements. Used as a building block for more complex UI systems.",
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/main/Microsoft.Toolkit.Uwp.UI.Controls.Layout/ContentSizer",
"XamlCodeFile": "/SamplePages/ContentSizer/ContentSizer.bind",
"Icon": "/SamplePages/ContentSizer/ContentSizer.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/ContentSizer.md"
},
{
"Name": "GridSplitter",
"Type": "GridSplitterPage",
Expand Down
2 changes: 2 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/Styles/Themes.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<SolidColorBrush x:Key="Brush-Red"
Color="{StaticResource Red}" />

<FontFamily x:Key="SymbolFonts">Fonts/#Segoe MDL2 Assets</FontFamily>

<!-- Brushes -->
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public GridSplitterMetadata()
b.AddCustomAttributes(nameof(GridSplitter.Element), new CategoryAttribute(Resources.CategoryCommon));
b.AddCustomAttributes(nameof(GridSplitter.ResizeDirection), new CategoryAttribute(Resources.CategoryCommon));
b.AddCustomAttributes(nameof(GridSplitter.ResizeBehavior), new CategoryAttribute(Resources.CategoryCommon));
b.AddCustomAttributes(nameof(GridSplitter.GripperForeground), new CategoryAttribute(Resources.CategoryBrush));
b.AddCustomAttributes(nameof(GridSplitter.ParentLevel), new CategoryAttribute(Resources.CategoryCommon));
b.AddCustomAttributes(nameof(GridSplitter.GripperCursor), new CategoryAttribute(Resources.CategoryAppearance));
b.AddCustomAttributes(nameof(GridSplitter.GripperCustomCursorResource),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ internal static class GridSplitter
internal const string Element = nameof(Element);
internal const string GripperCursor = nameof(GripperCursor);
internal const string GripperCustomCursorResource = nameof(GripperCustomCursorResource);
internal const string GripperForeground = nameof(GripperForeground);
internal const string ParentLevel = nameof(ParentLevel);
internal const string ResizeBehavior = nameof(ResizeBehavior);
internal const string ResizeDirection = nameof(ResizeDirection);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// Enum to indicate whether <see cref="ContentSizer"/> resizes Vertically or Horizontally.
/// </summary>
public enum ContentResizeDirection
{
/// <summary>
/// Determines whether to resize rows or columns based on its Alignment and
/// width compared to height
/// </summary>
Auto, // TODO: Detect?

/// <summary>
/// Resize columns when dragging Splitter.
/// </summary>
Vertical,

/// <summary>
/// Resize rows when dragging Splitter.
/// </summary>
Horizontal
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Toolkit.Uwp.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// Events for <see cref="ContentSizer"/>.
/// </summary>
public partial class ContentSizer
{
// If no values specified, setup our default behaviors.
private void ContentSizer_Loaded(object sender, RoutedEventArgs e)
{
// Adding Grip to Grid Splitter
if (Content == null)
{
// TODO: Make Converter to put in XAML?
Content =
ResizeDirection == ContentResizeDirection.Vertical ? GripperBarVertical : GripperBarHorizontal;
}

if (TargetControl == null)
{
TargetControl = this.FindAscendant<FrameworkElement>();
}
}

/// <inheritdoc />
protected override void OnManipulationDelta(ManipulationDeltaRoutedEventArgs e)
{
var horizontalChange = e.Delta.Translation.X;
var verticalChange = e.Delta.Translation.Y;

if (ResizeDirection == ContentResizeDirection.Vertical)
{
if (HorizontalMove(horizontalChange))
{
return;
}
}
else if (ResizeDirection == ContentResizeDirection.Horizontal)
{
if (VerticalMove(verticalChange))
{
return;
}
}

base.OnManipulationDelta(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Toolkit.Uwp.UI.Automation.Peers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Markup;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// The <see cref="ContentSizer"/> is a control which can be used to resize any element, usually its parent. If you are using a <see cref="Grid"/>, use <see cref="GridSplitter"/> instead.
/// </summary>
[ContentProperty(Name = nameof(Content))]
michael-hawker marked this conversation as resolved.
Show resolved Hide resolved
public partial class ContentSizer : SplitBase
{
/// <summary>
/// Initializes a new instance of the <see cref="ContentSizer"/> class.
/// </summary>
public ContentSizer()
{
this.DefaultStyleKey = typeof(ContentSizer);

// TODO: Can this be set in XAML, do we open a WinUI issue to track?
ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
michael-hawker marked this conversation as resolved.
Show resolved Hide resolved

KeyUp += SplitBase_KeyUp;
}

/// <inheritdoc/>
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

// Note, we re-register for the proper timing to check for default property values. If we just set Loaded once in our constructor this doesn't work... Not sure why... 🤷‍

// Unhook registered events
Loaded -= ContentSizer_Loaded;

// Register Events
Loaded += ContentSizer_Loaded;
}

/// <summary>
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
/// </summary>
/// <returns>An automation peer for this <see cref="ContentSizer"/>.</returns>
protected override AutomationPeer OnCreateAutomationPeer()
{
return new ContentSizerAutomationPeer(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:ui="using:Microsoft.Toolkit.Uwp.UI">
<Style TargetType="local:ContentSizer">
<Setter Property="IsTabStop" Value="True" />
<Setter Property="UseSystemFocusVisuals" Value="True" />
<Setter Property="IsFocusEngagementEnabled" Value="True" />
<Setter Property="MinWidth" Value="16" />
<Setter Property="MinHeight" Value="16" />
<Setter Property="Background" Value="{ThemeResource SystemControlHighlightChromeHighBrush}" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="AutomationProperties.Name" Value="ms-resource://Microsoft.Toolkit.Uwp.UI.Controls.Layout/Microsoft.Toolkit.Uwp.UI.Controls.Layout/Resources/WCT_ContentSizer_AutomationName" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock AutomationProperties.AccessibilityView="Raw"
FontFamily="{StaticResource SymbolFonts}"
michael-hawker marked this conversation as resolved.
Show resolved Hide resolved
Foreground="{ThemeResource SystemControlForegroundAltHighBrush}"
Text="{Binding}" />
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:ContentSizer">
<Grid ui:FrameworkElementExtensions.Cursor="{TemplateBinding GripperCursor}"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Loading