-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Feature - Container Queries #16846
Open
emmauss
wants to merge
25
commits into
master
Choose a base branch
from
feat-container-queries
base: master
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
Feature - Container Queries #16846
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7022ed1
add container queries
emmauss 584179a
make visual query provider SetSize virtual
emmauss d88474d
fix container name matching
emmauss 6bd868b
add tests
emmauss bb68d7b
move border container implementation up to decorator
emmauss 2f310a4
move container query demo to ControlCatalog
emmauss 9d88917
make QueryProvider internal
emmauss 74164b9
update container behavior in toplevelRename Query to StyleQuery and m…
emmauss b748d37
fix comment typos
emmauss 7be4f47
Merge remote-tracking branch 'origin/master' into feat-container-queries
emmauss 79d4f8f
Merge remote-tracking branch 'origin/master' into feat-container-queries
emmauss 5d4c48d
remove unused usings
emmauss 950ec5a
isolate container tests
emmauss 5cc65f9
Merge branch 'master' into feat-container-queries
emmauss 6da194b
Merge branch 'master' into feat-container-queries
emmauss e55de92
Merge remote-tracking branch 'origin/master' into feat-container-queries
emmauss 29213a8
update api
emmauss ca91718
fix tests
emmauss b941172
fix no-selector styles in containers being applied all the time
emmauss 9dc68ae
simplify container search
emmauss d8bfb02
Merge branch 'master' into feat-container-queries
emmauss 2a398f1
add docs to container properties
emmauss c190a3b
Merge branch 'master' into feat-container-queries
emmauss 4f46814
Merge remote-tracking branch 'origin/master' into feat-container-queries
emmauss a38db7b
Merge branch 'master' into feat-container-queries
emmauss 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
This file contains 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,110 @@ | ||
<UserControl x:Class="ControlCatalog.Pages.ContainerQueryPage" | ||
xmlns="https://github.com/avaloniaui" | ||
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:viewModels="using:ControlCatalog.ViewModels" | ||
d:DesignHeight="800" | ||
d:DesignWidth="400" | ||
mc:Ignorable="d"> | ||
<StackPanel Spacing="10"> | ||
<StackPanel.Styles> | ||
<ContainerQuery Name="UniformGrid" | ||
Query="max-width:400"> | ||
<Style Selector="UniformGrid#ContentGrid"> | ||
<Setter Property="Columns" | ||
Value="1"/> | ||
</Style> | ||
</ContainerQuery> | ||
<ContainerQuery Name="UniformGrid" | ||
Query="min-width:400"> | ||
<Style Selector="UniformGrid#ContentGrid"> | ||
<Setter Property="Columns" | ||
Value="2"/> | ||
</Style> | ||
</ContainerQuery> | ||
<ContainerQuery Name="UniformGrid" | ||
Query="min-width:800"> | ||
<Style Selector="UniformGrid#ContentGrid"> | ||
<Setter Property="Columns" | ||
Value="3"/> | ||
</Style> | ||
</ContainerQuery> | ||
<ContainerQuery Name="UniformGrid" | ||
Query="min-width:1200"> | ||
<Style Selector="UniformGrid#ContentGrid"> | ||
<Setter Property="Columns" | ||
Value="4"/> | ||
</Style> | ||
</ContainerQuery> | ||
</StackPanel.Styles> | ||
<TextBlock Text="Dynamically change properties of controls based on the size of a parent container."/> | ||
<Border Container.Name="UniformGrid" | ||
VerticalAlignment="Stretch" | ||
HorizontalAlignment="Stretch" | ||
Container.Sizing="Width"> | ||
<ScrollViewer VerticalScrollBarVisibility="Auto" | ||
HorizontalScrollBarVisibility="Disabled"> | ||
<Grid RowDefinitions="Auto,*"> | ||
<UniformGrid Name="ContentGrid"> | ||
<Border Margin="10" | ||
HorizontalAlignment="Stretch" | ||
CornerRadius="20" | ||
ClipToBounds="True"> | ||
<Image Stretch="Uniform" | ||
HorizontalAlignment="Stretch" | ||
Source="/Assets/image1.jpg"/> | ||
</Border> | ||
<Border Margin="10" | ||
HorizontalAlignment="Stretch" | ||
CornerRadius="20" | ||
ClipToBounds="True"> | ||
<Image Stretch="Uniform" | ||
HorizontalAlignment="Stretch" | ||
Source="/Assets/image2.jpg"/> | ||
</Border> | ||
<Border Margin="10" | ||
HorizontalAlignment="Stretch" | ||
CornerRadius="20" | ||
ClipToBounds="True"> | ||
<Image Stretch="Uniform" | ||
HorizontalAlignment="Stretch" | ||
Source="/Assets/image3.jpg"/> | ||
</Border> | ||
<Border Margin="10" | ||
HorizontalAlignment="Stretch" | ||
CornerRadius="20" | ||
ClipToBounds="True"> | ||
<Image Stretch="Uniform" | ||
HorizontalAlignment="Stretch" | ||
Source="/Assets/image4.jpg"/> | ||
</Border> | ||
<Border Margin="10" | ||
HorizontalAlignment="Stretch" | ||
CornerRadius="20" | ||
ClipToBounds="True"> | ||
<Image Stretch="Uniform" | ||
HorizontalAlignment="Stretch" | ||
Source="/Assets/image5.jpg"/> | ||
</Border> | ||
<Border Margin="10" | ||
HorizontalAlignment="Stretch" | ||
CornerRadius="20" | ||
ClipToBounds="True"> | ||
<Image Stretch="Uniform" | ||
HorizontalAlignment="Stretch" | ||
Source="/Assets/image6.jpg"/> | ||
</Border> | ||
<Border HorizontalAlignment="Stretch" | ||
CornerRadius="20" | ||
ClipToBounds="True"> | ||
<Image Stretch="Uniform" | ||
HorizontalAlignment="Stretch" | ||
Source="/Assets/image7.jpg"/> | ||
</Border> | ||
</UniformGrid> | ||
</Grid> | ||
</ScrollViewer> | ||
</Border> | ||
</StackPanel> | ||
</UserControl> |
This file contains 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,18 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace ControlCatalog.Pages | ||
{ | ||
public class ContainerQueryPage : UserControl | ||
{ | ||
public ContainerQueryPage() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} | ||
} |
This file contains 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,28 @@ | ||
namespace Avalonia.Layout | ||
{ | ||
/// <summary> | ||
/// Defines how a container is queried. | ||
/// </summary> | ||
public enum ContainerSizing | ||
{ | ||
/// <summary> | ||
/// The container is not included in any size queries. | ||
/// </summary> | ||
Normal, | ||
|
||
/// <summary> | ||
/// The container size can be queried for width. | ||
/// </summary> | ||
Width, | ||
|
||
/// <summary> | ||
/// The container size can be queried for height. | ||
/// </summary> | ||
Height, | ||
|
||
/// <summary> | ||
/// The container size can be queried for width and height. | ||
/// </summary> | ||
WidthAndHeight | ||
} | ||
} |
This file contains 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
This file contains 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,37 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Avalonia.Styling; | ||
|
||
namespace Avalonia.Platform | ||
{ | ||
internal class VisualQueryProvider | ||
{ | ||
private readonly Visual _visual; | ||
|
||
public double Width { get; private set; } = double.PositiveInfinity; | ||
|
||
public double Height { get; private set; } = double.PositiveInfinity; | ||
|
||
public VisualQueryProvider(Visual visual) | ||
{ | ||
_visual = visual; | ||
} | ||
|
||
public event EventHandler? WidthChanged; | ||
public event EventHandler? HeightChanged; | ||
|
||
public virtual void SetSize(double width, double height, Layout.ContainerSizing containerType) | ||
{ | ||
var currentWidth = Width; | ||
var currentHeight = Height; | ||
|
||
Width = width; | ||
Height = height; | ||
|
||
if (currentWidth != Width && (containerType == Layout.ContainerSizing.Width || containerType == Layout.ContainerSizing.WidthAndHeight)) | ||
WidthChanged?.Invoke(this, EventArgs.Empty); | ||
if (currentHeight != Height && (containerType == Layout.ContainerSizing.Height || containerType == Layout.ContainerSizing.WidthAndHeight)) | ||
HeightChanged?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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,69 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Avalonia.Styling.Activators | ||
{ | ||
/// <summary> | ||
/// An aggregate <see cref="ContainerQueryActivatorBase"/> which is active when all of its inputs are | ||
/// active. | ||
/// </summary> | ||
internal class AndQueryActivator : ContainerQueryActivatorBase, IStyleActivatorSink | ||
{ | ||
private List<IStyleActivator>? _sources; | ||
|
||
public AndQueryActivator(Visual visual) : base(visual) | ||
{ | ||
} | ||
|
||
public int Count => _sources?.Count ?? 0; | ||
|
||
public void Add(IStyleActivator activator) | ||
{ | ||
if (IsSubscribed) | ||
throw new AvaloniaInternalException("AndActivator is already subscribed."); | ||
_sources ??= new List<IStyleActivator>(); | ||
_sources.Add(activator); | ||
} | ||
|
||
void IStyleActivatorSink.OnNext(bool value) => ReevaluateIsActive(); | ||
|
||
protected override bool EvaluateIsActive() | ||
{ | ||
if (_sources is null || _sources.Count == 0) | ||
return true; | ||
|
||
var count = _sources.Count; | ||
var mask = (1ul << count) - 1; | ||
var flags = 0UL; | ||
|
||
for (var i = 0; i < count; ++i) | ||
{ | ||
if (_sources[i].GetIsActive()) | ||
flags |= 1ul << i; | ||
} | ||
|
||
return flags == mask; | ||
} | ||
|
||
protected override void Initialize() | ||
{ | ||
if (_sources is object) | ||
{ | ||
foreach (var source in _sources) | ||
{ | ||
source.Subscribe(this); | ||
} | ||
} | ||
} | ||
|
||
protected override void Deinitialize() | ||
{ | ||
if (_sources is object) | ||
{ | ||
foreach (var source in _sources) | ||
{ | ||
source.Unsubscribe(this); | ||
} | ||
} | ||
} | ||
} | ||
} |
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.
I believe that this logic should be bypassed for TopLevels and TopLevel should always implicitly be a SizeAndHeight container.