Browse Source

use a seperate control for stackpanel reversing until we have flow control available.

pull/2453/head
Dan Walmsley 8 years ago
parent
commit
7f21cc426d
  1. 61
      src/Avalonia.Controls/Notifications/ReversibleStackPanel.cs
  2. 17
      src/Avalonia.Controls/StackPanel.cs
  3. 16
      src/Avalonia.Themes.Default/WindowNotificationManager.xaml

61
src/Avalonia.Controls/Notifications/ReversibleStackPanel.cs

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Avalonia.Layout;
using Avalonia.Styling;
namespace Avalonia.Controls
{
public class ReversibleStackPanel : StackPanel
{
/// <summary>
/// Defines the <see cref="ReverseOrder"/> property.
/// </summary>
public static readonly StyledProperty<bool> ReverseOrderProperty =
AvaloniaProperty.Register<ReversibleStackPanel, bool>(nameof(ReverseOrder));
/// <summary>
/// Gets or sets if the child controls will be layed out in reverse order.
/// </summary>
public bool ReverseOrder
{
get => GetValue(ReverseOrderProperty);
set => SetValue(ReverseOrderProperty, value);
}
/// <inheritdoc/>
protected override Size ArrangeOverride(Size finalSize)
{
var orientation = Orientation;
var spacing = Spacing;
var finalRect = new Rect(finalSize);
var pos = 0.0;
var children = ReverseOrder ? Children.Reverse() : Children;
foreach (Control child in children)
{
double childWidth = child.DesiredSize.Width;
double childHeight = child.DesiredSize.Height;
if (orientation == Orientation.Vertical)
{
var rect = new Rect(0, pos, childWidth, childHeight)
.Align(finalRect, child.HorizontalAlignment, VerticalAlignment.Top);
ArrangeChild(child, rect, finalSize, orientation);
pos += childHeight + spacing;
}
else
{
var rect = new Rect(pos, 0, childWidth, childHeight)
.Align(finalRect, HorizontalAlignment.Left, child.VerticalAlignment);
ArrangeChild(child, rect, finalSize, orientation);
pos += childWidth + spacing;
}
}
return finalSize;
}
}
}

17
src/Avalonia.Controls/StackPanel.cs

@ -25,12 +25,6 @@ namespace Avalonia.Controls
public static readonly StyledProperty<Orientation> OrientationProperty =
AvaloniaProperty.Register<StackPanel, Orientation>(nameof(Orientation), Orientation.Vertical);
/// <summary>
/// Defines the <see cref="ReverseOrder"/> property.
/// </summary>
public static readonly StyledProperty<bool> ReverseOrderProperty =
AvaloniaProperty.Register<StackPanel, bool>(nameof(ReverseOrder));
/// <summary>
/// Initializes static members of the <see cref="StackPanel"/> class.
/// </summary>
@ -58,15 +52,6 @@ namespace Avalonia.Controls
set { SetValue(OrientationProperty, value); }
}
/// <summary>
/// Gets or sets if the child controls will be layed out in reverse order.
/// </summary>
public bool ReverseOrder
{
get => GetValue(ReverseOrderProperty);
set => SetValue(ReverseOrderProperty, value);
}
/// <summary>
/// Gets the next control in the specified direction.
/// </summary>
@ -246,7 +231,7 @@ namespace Avalonia.Controls
var finalRect = new Rect(finalSize);
var pos = 0.0;
var children = ReverseOrder ? Children.Reverse() : Children;
var children = Children;
foreach (Control child in children)
{

16
src/Avalonia.Themes.Default/WindowNotificationManager.xaml

@ -4,8 +4,8 @@
<Setter Property="Margin" Value="0 0 8 8"/>
<Setter Property="Template">
<ControlTemplate>
<StackPanel Name="PART_Items">
<StackPanel.DataTemplates>
<ReversibleStackPanel Name="PART_Items">
<ReversibleStackPanel.DataTemplates>
<DataTemplate DataType="INotification">
<StackPanel Spacing="8" Margin="12">
<TextBlock Text="{Binding Title}" FontWeight="Medium" />
@ -15,29 +15,29 @@
<DataTemplate DataType="x:String">
<TextBlock Text="{Binding }" Margin="12" />
</DataTemplate>
</StackPanel.DataTemplates>
</StackPanel>
</ReversibleStackPanel.DataTemplates>
</ReversibleStackPanel>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="WindowNotificationManager:topleft /template/ StackPanel#PART_Items">
<Style Selector="WindowNotificationManager:topleft /template/ ReversibleStackPanel#PART_Items">
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Style>
<Style Selector="WindowNotificationManager:topright /template/ StackPanel#PART_Items">
<Style Selector="WindowNotificationManager:topright /template/ ReversibleStackPanel#PART_Items">
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
<Style Selector="WindowNotificationManager:bottomleft /template/ StackPanel#PART_Items">
<Style Selector="WindowNotificationManager:bottomleft /template/ ReversibleStackPanel#PART_Items">
<Setter Property="ReverseOrder" Value="True"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Style>
<Style Selector="WindowNotificationManager:bottomright /template/ StackPanel#PART_Items">
<Style Selector="WindowNotificationManager:bottomright /template/ ReversibleStackPanel#PART_Items">
<Setter Property="ReverseOrder" Value="True"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="HorizontalAlignment" Value="Right"/>

Loading…
Cancel
Save