Skip to content

Commit

Permalink
Rename ConstrainedPresenter to ConstrainedBox
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-hawker committed Jul 22, 2021
1 parent 4fe6c67 commit 1a68b20
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
<Content Include="SamplePages\Graph\LoginButton.png" />
<Content Include="SamplePages\Graph\PeoplePicker.png" />
<Content Include="SamplePages\Graph\PersonView.png" />
<Content Include="SamplePages\Primitives\ConstrainedPresenter.png" />
<Content Include="SamplePages\Primitives\ConstrainedBox.png" />
<Content Include="SamplePages\Primitives\SwitchPresenter.png" />
<Content Include="SamplePages\TabbedCommandBar\TabbedCommandBar.png" />
<Content Include="SamplePages\Animations\Effects\FadeBehavior.png" />
Expand Down Expand Up @@ -622,7 +622,7 @@
<Content Include="SamplePages\Graph\PeoplePickerXaml.bind" />
<Content Include="SamplePages\Graph\PersonViewXaml.bind" />
<Content Include="SamplePages\ListViewExtensions\ListViewExtensionsCode.bind" />
<Content Include="SamplePages\Primitives\ConstrainedPresenter.bind">
<Content Include="SamplePages\Primitives\ConstrainedBox.bind">
<SubType>Designer</SubType>
</Content>
</ItemGroup>
Expand Down Expand Up @@ -1538,4 +1538,4 @@
</Target>
<!-- No-op to avoid build error when packing solution from commandline -->
<Target Name="Pack" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
mc:Ignorable="d">

<Grid>
<controls:ConstrainedPresenter AspectRatio="16:3" VerticalAlignment="Top">
<controls:ConstrainedBox AspectRatio="16:3" VerticalAlignment="Top">
<Image Source="/Assets/Photos/WestSeattleView.jpg" Stretch="UniformToFill"/>
</controls:ConstrainedPresenter>
</controls:ConstrainedBox>
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<controls:Case IsDefault="True" />
</controls:CaseCollection>
</controls:SwitchPresenter>
<controls:ConstrainedPresenter x:Key="ConstrainedPresenterControl" />
<controls:ConstrainedBox x:Key="ConstrainedBoxControl" />
</Page.Resources>

<Grid>
Expand Down
12 changes: 6 additions & 6 deletions Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,13 @@
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/SwitchPresenter.md"
},
{
"Name": "ConstrainedPresenter",
"Name": "ConstrainedBox",
"Subcategory": "Layout",
"About": "The ConstrainedPresenter is a ContentPresenter which can allow a developer to constrain the scale or aspect ratio of its content.",
"CodeUrl": "https://github.com/CommunityToolkit/WindowsCommunityToolkit/tree/main/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/ConstrainedPresenter",
"XamlCodeFile": "/SamplePages/Primitives/ConstrainedPresenter.bind",
"Icon": "/SamplePages/Primitives/ConstrainedPresenter.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/ConstrainedPresenter.md"
"About": "The ConstrainedBox is a FrameworkElement which can allow a developer to constrain the scale or aspect ratio of its content.",
"CodeUrl": "https://github.com/CommunityToolkit/WindowsCommunityToolkit/tree/main/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/ConstrainedBox",
"XamlCodeFile": "/SamplePages/Primitives/ConstrainedBox.bind",
"Icon": "/SamplePages/Primitives/ConstrainedBox.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/ConstrainedBox.md"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// The <see cref="AspectRatio"/> structure is used by the <see cref="ConstrainedPresenter"/> control to
/// The <see cref="AspectRatio"/> structure is used by the <see cref="ConstrainedBox"/> control to
/// define a specific ratio to restrict its content.
/// </summary>
[Windows.Foundation.Metadata.CreateFromString(MethodName = "Microsoft.Toolkit.Uwp.UI.Controls.AspectRatio.ConvertToAspectRatio")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// The <see cref="ConstrainedPresenter"/> is a <see cref="ContentPresenter"/> control which can restrict the
/// The <see cref="ConstrainedBox"/> is a <see cref="FrameworkElement"/> control akin to <see cref="Viewbox"/>
/// which can modify the behavior of it's child element's layout. <see cref="ConstrainedBox"/> restricts the
/// available size for its content based on a scale factor and/or a specific <see cref="AspectRatio"/>.
/// This is performed as a layout calculation modification.
/// </summary>
public class ConstrainedPresenter : ContentPresenter // TODO: Think it should be a Border? But it's sealed; hopefully can change in WinUI 3.
/// <remarks>
/// Note that this class being implemented as a <see cref="ContentPresenter"/> is an implementation detail, and
/// is not meant to be used as one with a template. It is recommended to avoid styling the frame of the control
/// with borders and not using <see cref="ContentPresenter.ContentTemplate"/> for future compatibility of your
/// code if moving to WinUI 3 in the future.
/// </remarks>
public class ConstrainedBox : ContentPresenter // TODO: Should be FrameworkElement directly, see https://github.com/microsoft/microsoft-ui-xaml/issues/5530
{
/// <summary>
/// Gets or sets aspect Ratio to use for the contents of the Panel (after scaling).
Expand All @@ -32,11 +40,11 @@ public AspectRatio AspectRatio
/// Identifies the <see cref="AspectRatio"/> property.
/// </summary>
public static readonly DependencyProperty AspectRatioProperty =
DependencyProperty.Register(nameof(AspectRatio), typeof(AspectRatio), typeof(ConstrainedPresenter), new PropertyMetadata(null, AspectRatioPropertyChanged));
DependencyProperty.Register(nameof(AspectRatio), typeof(AspectRatio), typeof(ConstrainedBox), new PropertyMetadata(null, AspectRatioPropertyChanged));

private static void AspectRatioPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is ConstrainedPresenter panel)
if (d is ConstrainedBox panel)
{
panel.InvalidateMeasure();
}
Expand All @@ -55,7 +63,7 @@ public double ScaleX
/// Identifies the <see cref="ScaleX"/> property.
/// </summary>
public static readonly DependencyProperty ScaleXProperty =
DependencyProperty.Register(nameof(ScaleX), typeof(double), typeof(ConstrainedPresenter), new PropertyMetadata(1.0, ScalePropertyChanged));
DependencyProperty.Register(nameof(ScaleX), typeof(double), typeof(ConstrainedBox), new PropertyMetadata(1.0, ScalePropertyChanged));

/// <summary>
/// Gets or sets the scale for the height of the panel. Should be a value between 0-1.0. Default is 1.0.
Expand All @@ -70,11 +78,11 @@ public double ScaleY
/// Identifies the <see cref="ScaleY"/> property.
/// </summary>
public static readonly DependencyProperty ScaleYProperty =
DependencyProperty.Register(nameof(ScaleY), typeof(double), typeof(ConstrainedPresenter), new PropertyMetadata(1.0, ScalePropertyChanged));
DependencyProperty.Register(nameof(ScaleY), typeof(double), typeof(ConstrainedBox), new PropertyMetadata(1.0, ScalePropertyChanged));

private static void ScalePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is ConstrainedPresenter panel)
if (d is ConstrainedBox panel)
{
panel.InvalidateMeasure();
}
Expand Down

0 comments on commit 1a68b20

Please sign in to comment.