-
Notifications
You must be signed in to change notification settings - Fork 751
Introduce "Composition" > "Basics" page #2205
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
Open
Tera (0x5bfa)
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
0x5bfa:composition1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
WinUIGallery/Samples/CompositionBasics/CompositionBasicsChildVisual.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- header | ||
| Attach a Composition child Visual and position it with AnchorPoint | ||
| --- xaml | ||
| <Grid | ||
| x:Name="ChildVisualHost" | ||
| Height="220" | ||
| SizeChanged="ChildVisualHost_SizeChanged" /> | ||
| --- c# | ||
| private SpriteVisual? _childVisual; | ||
|
|
||
| private void ChildVisualExample_Loaded(object sender, RoutedEventArgs e) | ||
| { | ||
| Visual hostVisual = ElementCompositionPreview.GetElementVisual(ChildVisualHost); | ||
| _childVisual = hostVisual.Compositor.CreateSpriteVisual(); | ||
| _childVisual.Size = new Vector2(80); | ||
| _childVisual.Brush = hostVisual.Compositor.CreateColorBrush(Colors.DodgerBlue); | ||
|
|
||
| ElementCompositionPreview.SetElementChildVisual(ChildVisualHost, _childVisual); | ||
| UpdateChildVisual(); | ||
| } | ||
|
|
||
| private void UpdateChildVisual() | ||
| { | ||
| // AnchorPoint is normalized: (0,0) is the top-left and (1,1) is the bottom-right. | ||
| _childVisual.AnchorPoint = new Vector2(anchorX, anchorY); | ||
| _childVisual.Offset = new Vector3(ChildVisualHost.ActualSize / 2, 0); | ||
| } | ||
|
|
||
| private void Page_Unloaded(object sender, RoutedEventArgs e) | ||
| { | ||
| ElementCompositionPreview.SetElementChildVisual(ChildVisualHost, null); | ||
| _childVisual?.Dispose(); | ||
| } |
26 changes: 26 additions & 0 deletions
26
WinUIGallery/Samples/CompositionBasics/CompositionBasicsClip.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- header | ||
| Clip a XAML element through its Composition Visual | ||
| --- xaml | ||
| <Grid | ||
| x:Name="ClipTarget" | ||
| Width="240" | ||
| Height="140"> | ||
| <!-- Sample content --> | ||
| </Grid> | ||
| --- c# | ||
| private InsetClip? _insetClip; | ||
|
|
||
| private void ClipExample_Loaded(object sender, RoutedEventArgs e) | ||
| { | ||
| Visual visual = ElementCompositionPreview.GetElementVisual(ClipTarget); | ||
| _insetClip = visual.Compositor.CreateInsetClip(); | ||
| visual.Clip = _insetClip; | ||
| } | ||
|
|
||
| private void UpdateClip(float horizontalInset, float verticalInset) | ||
| { | ||
| _insetClip.LeftInset = horizontalInset; | ||
| _insetClip.RightInset = horizontalInset; | ||
| _insetClip.TopInset = verticalInset; | ||
| _insetClip.BottomInset = verticalInset; | ||
| } |
32 changes: 32 additions & 0 deletions
32
WinUIGallery/Samples/CompositionBasics/CompositionBasicsGetElementVisual.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| --- header | ||
| Get and transform the Visual backing a XAML element | ||
| --- xaml | ||
| <Border | ||
| x:Name="ElementVisualTarget" | ||
| Width="160" | ||
| Height="100" | ||
| SizeChanged="ElementVisualTarget_SizeChanged"> | ||
| <TextBlock Text="XAML element" /> | ||
| </Border> | ||
| --- c# | ||
| private Visual? _elementVisual; | ||
|
|
||
| private void ElementVisualExample_Loaded(object sender, RoutedEventArgs e) | ||
| { | ||
| _elementVisual = ElementCompositionPreview.GetElementVisual(ElementVisualTarget); | ||
| UpdateVisual(); | ||
| } | ||
|
|
||
| private void UpdateVisual() | ||
| { | ||
| if (_elementVisual is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // CenterPoint uses pixels in the Visual's coordinate space. | ||
| _elementVisual.CenterPoint = new Vector3(ElementVisualTarget.ActualSize / 2, 0); | ||
| // Translation is also exposed directly on UIElement as a Composition facade. | ||
| ElementVisualTarget.Translation = new Vector3(translationX, translationY, 0); | ||
| _elementVisual.RotationAngleInDegrees = rotation; | ||
| } |
175 changes: 175 additions & 0 deletions
175
WinUIGallery/Samples/CompositionBasics/CompositionBasicsPage.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <Page | ||
| x:Class="WinUIGallery.ControlPages.CompositionBasicsPage" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:controls="using:WinUIGallery.Controls" | ||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| mc:Ignorable="d"> | ||
|
|
||
| <StackPanel> | ||
| <controls:ControlExample | ||
| SampleDefinition="CompositionBasics\CompositionBasicsGetElementVisual.txt" | ||
| Loaded="ElementVisualExample_Loaded"> | ||
| <controls:ControlExample.Options> | ||
| <StackPanel MinWidth="180" Spacing="8"> | ||
| <Slider | ||
| x:Name="TranslationXSlider" | ||
| Header="Translation X" | ||
| Maximum="80" | ||
| Minimum="-80" | ||
| ValueChanged="ElementVisualTransform_ValueChanged" /> | ||
| <Slider | ||
| x:Name="TranslationYSlider" | ||
| Header="Translation Y" | ||
| Maximum="50" | ||
| Minimum="-50" | ||
| ValueChanged="ElementVisualTransform_ValueChanged" /> | ||
| <Slider | ||
| x:Name="RotationSlider" | ||
| Header="Rotation" | ||
| Maximum="360" | ||
| ValueChanged="ElementVisualTransform_ValueChanged" /> | ||
| </StackPanel> | ||
| </controls:ControlExample.Options> | ||
|
|
||
| <Grid Height="240"> | ||
| <Border | ||
| x:Name="ElementVisualTarget" | ||
| Width="160" | ||
| Height="100" | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| Background="{ThemeResource AccentFillColorDefaultBrush}" | ||
| CornerRadius="8" | ||
| SizeChanged="ElementVisualTarget_SizeChanged"> | ||
| <TextBlock | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| Foreground="{ThemeResource TextOnAccentFillColorPrimaryBrush}" | ||
| Text="XAML element" /> | ||
| </Border> | ||
| </Grid> | ||
| </controls:ControlExample> | ||
|
|
||
| <controls:ControlExample | ||
| SampleDefinition="CompositionBasics\CompositionBasicsChildVisual.txt" | ||
| Loaded="ChildVisualExample_Loaded"> | ||
| <controls:ControlExample.Options> | ||
| <StackPanel MinWidth="180" Spacing="8"> | ||
| <Slider | ||
| x:Name="AnchorXSlider" | ||
| Header="AnchorPoint X" | ||
| Maximum="1" | ||
| StepFrequency="0.1" | ||
| Value="0.5" | ||
| ValueChanged="AnchorPointSlider_ValueChanged" /> | ||
| <Slider | ||
| x:Name="AnchorYSlider" | ||
| Header="AnchorPoint Y" | ||
| Maximum="1" | ||
| StepFrequency="0.1" | ||
| Value="0.5" | ||
| ValueChanged="AnchorPointSlider_ValueChanged" /> | ||
| </StackPanel> | ||
| </controls:ControlExample.Options> | ||
|
|
||
| <Grid | ||
| x:Name="ChildVisualHost" | ||
| Height="220" | ||
| MinWidth="280" | ||
| Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" | ||
| BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" | ||
| BorderThickness="1" | ||
| CornerRadius="8" | ||
| SizeChanged="ChildVisualHost_SizeChanged"> | ||
| <TextBlock | ||
| Margin="12" | ||
| VerticalAlignment="Bottom" | ||
| Foreground="{ThemeResource TextFillColorSecondaryBrush}" | ||
| Text="The child visual's offset stays at the center of this host." /> | ||
| </Grid> | ||
| </controls:ControlExample> | ||
|
|
||
| <controls:ControlExample | ||
| SampleDefinition="CompositionBasics\CompositionBasicsTransformMatrix.txt" | ||
| Loaded="TransformMatrixExample_Loaded"> | ||
| <controls:ControlExample.Options> | ||
| <StackPanel MinWidth="180" Spacing="8"> | ||
| <Slider | ||
| x:Name="SkewXSlider" | ||
| Header="Horizontal skew" | ||
| Maximum="45" | ||
| Minimum="-45" | ||
| ValueChanged="TransformMatrixSlider_ValueChanged" /> | ||
| <Slider | ||
| x:Name="ScaleXSlider" | ||
| Header="Horizontal scale" | ||
| Maximum="1.5" | ||
| Minimum="0.5" | ||
| StepFrequency="0.1" | ||
| Value="1" | ||
| ValueChanged="TransformMatrixSlider_ValueChanged" /> | ||
| </StackPanel> | ||
| </controls:ControlExample.Options> | ||
|
|
||
| <Grid Height="220"> | ||
| <Border | ||
| x:Name="TransformMatrixTarget" | ||
| Width="170" | ||
| Height="100" | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| Background="{ThemeResource AccentFillColorSecondaryBrush}" | ||
| CornerRadius="8" | ||
| SizeChanged="TransformMatrixTarget_SizeChanged"> | ||
| <TextBlock | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| Foreground="{ThemeResource TextOnAccentFillColorPrimaryBrush}" | ||
| Text="TransformMatrix" /> | ||
| </Border> | ||
| </Grid> | ||
| </controls:ControlExample> | ||
|
|
||
| <controls:ControlExample | ||
| SampleDefinition="CompositionBasics\CompositionBasicsClip.txt" | ||
| Loaded="ClipExample_Loaded"> | ||
| <controls:ControlExample.Options> | ||
| <StackPanel MinWidth="180" Spacing="8"> | ||
| <Slider | ||
| x:Name="HorizontalClipSlider" | ||
| Header="Left and right inset" | ||
| Maximum="70" | ||
| ValueChanged="ClipSlider_ValueChanged" /> | ||
| <Slider | ||
| x:Name="VerticalClipSlider" | ||
| Header="Top and bottom inset" | ||
| Maximum="40" | ||
| ValueChanged="ClipSlider_ValueChanged" /> | ||
| </StackPanel> | ||
| </controls:ControlExample.Options> | ||
|
|
||
| <Grid Height="220"> | ||
| <Grid | ||
| x:Name="ClipTarget" | ||
| Width="240" | ||
| Height="140" | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| Background="{ThemeResource AccentFillColorDefaultBrush}"> | ||
| <Ellipse | ||
| Width="170" | ||
| Height="170" | ||
| Fill="{ThemeResource LayerFillColorAltBrush}" /> | ||
| <TextBlock | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| Foreground="{ThemeResource TextFillColorPrimaryBrush}" | ||
| Text="Composition clip" /> | ||
| </Grid> | ||
| </Grid> | ||
| </controls:ControlExample> | ||
| </StackPanel> | ||
| </Page> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you expect an "CompositionAdvanced" page or why is this called basics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the list of pages trying to implement, the one we discussed earlier.
Do you have something else in mind?