Skip to content

Commit

Permalink
feat(AutoLayout): add Height and Width support and update documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-Louis committed Aug 30, 2022
1 parent cdd407c commit 280f1f9
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 12 deletions.
45 changes: 45 additions & 0 deletions doc/controls/AutoLayoutControl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
> [!TIP]
> This guide covers details for `AutoLayoutControl` specifically. If you are just getting started with the Uno Toolkit UI Library, please see our [general getting started](../getting-started.md) page to make sure you have the correct setup in place.
## Summary
`AutoLayoutControl` arranges child elements into a single line that can be oriented horizontally or vertically. It is the reflection in XAML of the [Autolayout frame in Figma](https://www.figma.com/widget-docs/api/component-AutoLayout).

### C#
```csharp
public partial class AutoLayout : Control
```

### XAML
```xml
xmlns:utu="using:Uno.Toolkit.UI"
...

<utu:AutoLayout>
contents
</utu:AutoLayout>
```

### Inheritance
Object &#8594; DependencyObject &#8594; UIElement &#8594; FrameworkElement &#8594; Control

### Constructors
| Constructor | Description |
|-----------------|----------------------------------------------------------|
| AutoLayout() | Initializes a new instance of the `AutoLayout` class. |

### Properties
Property|Type|Description
-|-|-
Orientation | Orientation | Defines constants that specify the different orientations that a control or layout can have.
Spacing | double | Gets or sets the uniform distance (in pixels) between grid. Each grid of the AutoLayout will have the spacing set by this value depending the AautoLayout orientation
Justify | AutoLayoutJustify | Either Stack, space between children behave like a `StackPanel`, or SpaceBetween, between each children a equal space is added assuring that all the `AutoLayout` space is occupy. Note : if a child has his `PrimaryAlignment` set to Stretch, it will default to Stack.
Children | AutoLayoutChildren | List of FrameworkElement that are the AutoLayout children
PrimaryAxisAlignment | AutoLayoutAlignment | Indicates where the content be displayed on the axis of the AutoLayout orientation

### Attached Properties
Property|Type|Description
-|-|-
PrimaryAlignment|AutoLayoutPrimaryAlignment|Either Auto, the child grid take only the place it need in the autolayout direction, or Stretch, the child grid take all the available place in the autolayout direction. Note if set to Strech AutoLayoutJustify will behave as if in Stack mode.
CounterAlignment|AutoLayoutAlignment|Indicates where an element should be displayed on the counter axis of the parent orientation relative to the allocated layout slot of the parent element
PrimaryLength|double| Set the grid size in parent orientation [Deprecated should Height and Width instead]
CounterLength|double|Sets the child size in parent counter orientation [Deprecated should Height and Width instead]
2 changes: 2 additions & 0 deletions doc/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# ***************** Controls *******************
- name: Controls
items:
- name: AutoLayout
href: controls/AutoLayoutControl.md
- name: Cards
href: controls/CardAndCardContentControl.md
- name: Chip and ChipGroup
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Page
x:Class="Uno.Toolkit.Samples.Content.Controls.AutoLayoutPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Uno.Toolkit.Samples.Content.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sample="using:Uno.Toolkit.Samples"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<sample:SamplePageLayout x:Name="SamplePageLayout" IsDesignAgnostic="True">
<sample:SamplePageLayout.DesignAgnosticTemplate>
<DataTemplate>
<ScrollViewer HorizontalScrollMode="Disabled">
<StackPanel>
<TextBlock Text="Use a AutoLayout behave almost like a StackPanel, but with row that that can stretch. It was made to emulate the Figma auto layout"
Style="{StaticResource BodyTextBlockStyle}"
Margin="0,24,0,0" />

<utu:AutoLayout Spacing="10"
Margin="0,24,0,0">
<TextBlock Text="With the attached properties CounterLength and PrimaryLength" TextAlignment="Center"/>
<Rectangle utu:AutoLayout.CounterLength="100" utu:AutoLayout.PrimaryLength="100" Fill="Blue"/>
<TextBlock Text="With Width and Height" TextAlignment="Center"/>
<Rectangle Height="100" Width="100" Fill="Red"/>
<TextBlock Text="Margin don't work with the attached properties CounterLength and PrimaryLength" TextAlignment="Center"/>
<Rectangle Margin="20" utu:AutoLayout.CounterLength="100" utu:AutoLayout.PrimaryLength="100" Fill="Green"/>
<TextBlock Text="Margin work With Width and Height" TextAlignment="Center"/>
<Rectangle Margin="20" Width="100" Height="100" Fill="Pink"/>
</utu:AutoLayout>
</StackPanel>
</ScrollViewer>
</DataTemplate>
</sample:SamplePageLayout.DesignAgnosticTemplate>
</sample:SamplePageLayout>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.Toolkit.Samples.Entities;
using Windows.Foundation;
using Windows.Foundation.Collections;
#if IS_WINUI
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
#else
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
#endif

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace Uno.Toolkit.Samples.Content.Controls
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
[SamplePage(SampleCategory.Controls, "AutoLayout")]
public sealed partial class AutoLayoutPage : Page
{
public AutoLayoutPage()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)App.xaml.Navigation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Content\Controls\AutoLayoutPage.xaml.cs">
<DependentUpon>AutoLayoutPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Content\Controls\CardSamplePage.xaml.cs">
<DependentUpon>CardSamplePage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -148,6 +151,10 @@
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\en\Resources.resw" />
</ItemGroup>
<ItemGroup>
<Page Include="$(MSBuildThisFileDirectory)Content\Controls\AutoLayoutPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Content\Controls\CardSamplePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
12 changes: 0 additions & 12 deletions src/Uno.Toolkit.UI/Controls/AutoLayout/AutoLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,6 @@ private void UpdateAlignments()
{
child.Width = width;
}
else
{
child.ClearValue(WidthProperty);
}

child.ClearValue(HeightProperty);
}

// Process "space between"
Expand Down Expand Up @@ -356,12 +350,6 @@ private void UpdateAlignments()
{
child.Height = height;
}
else
{
child.ClearValue(HeightProperty);
}

child.ClearValue(WidthProperty);
}

// Process "space between"
Expand Down

0 comments on commit 280f1f9

Please sign in to comment.