feat: add placement.
This commit is contained in:
@@ -22,6 +22,14 @@
|
|||||||
Data="{StaticResource iconGlyph}" />
|
Data="{StaticResource iconGlyph}" />
|
||||||
</u:IconButton.Icon>
|
</u:IconButton.Icon>
|
||||||
</u:IconButton>
|
</u:IconButton>
|
||||||
|
<u:IconButton Content="GitHub" IsLoading="{Binding #loading.IsChecked}" IconPlacement="Right">
|
||||||
|
<u:IconButton.Icon>
|
||||||
|
<PathIcon
|
||||||
|
Width="14"
|
||||||
|
Height="14"
|
||||||
|
Data="{StaticResource iconGlyph}" />
|
||||||
|
</u:IconButton.Icon>
|
||||||
|
</u:IconButton>
|
||||||
<u:IconButton
|
<u:IconButton
|
||||||
Width="150"
|
Width="150"
|
||||||
Content="GitHub"
|
Content="GitHub"
|
||||||
|
|||||||
@@ -33,12 +33,13 @@
|
|||||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
ColumnDefinitions="Auto, Auto">
|
ColumnDefinitions="Auto, Auto">
|
||||||
<Panel Grid.Column="0" Margin="0,0,4,0">
|
<Panel
|
||||||
|
Name="PART_IconRoot"
|
||||||
|
Grid.Column="0"
|
||||||
|
Margin="0,0,8,0">
|
||||||
<Panel.IsVisible>
|
<Panel.IsVisible>
|
||||||
<MultiBinding Converter="{x:Static BoolConverters.Or}">
|
<MultiBinding Converter="{x:Static BoolConverters.Or}">
|
||||||
<Binding
|
<Binding Path="IsLoading" RelativeSource="{RelativeSource TemplatedParent}" />
|
||||||
Path="IsLoading"
|
|
||||||
RelativeSource="{RelativeSource TemplatedParent}" />
|
|
||||||
<Binding
|
<Binding
|
||||||
Converter="{x:Static ObjectConverters.IsNotNull}"
|
Converter="{x:Static ObjectConverters.IsNotNull}"
|
||||||
Path="Icon"
|
Path="Icon"
|
||||||
@@ -54,7 +55,10 @@
|
|||||||
Foreground="{TemplateBinding Foreground}"
|
Foreground="{TemplateBinding Foreground}"
|
||||||
IsVisible="{TemplateBinding IsLoading}" />
|
IsVisible="{TemplateBinding IsLoading}" />
|
||||||
</Panel>
|
</Panel>
|
||||||
<ContentPresenter Grid.Column="1" Content="{TemplateBinding Content}" />
|
<ContentPresenter
|
||||||
|
Name="PART_ContentPresenter"
|
||||||
|
Grid.Column="1"
|
||||||
|
Content="{TemplateBinding Content}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
@@ -99,6 +103,16 @@
|
|||||||
<Setter Property="Foreground" Value="{DynamicResource ButtonDefaultDisabledForeground}" />
|
<Setter Property="Foreground" Value="{DynamicResource ButtonDefaultDisabledForeground}" />
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="^:right">
|
||||||
|
<Style Selector="^ /template/ Panel#PART_IconRoot">
|
||||||
|
<Setter Property="Grid.Column" Value="1" />
|
||||||
|
<Setter Property="Margin" Value="8 0 0 0" />
|
||||||
|
</Style>
|
||||||
|
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
|
||||||
|
<Setter Property="Grid.Column" Value="0" />
|
||||||
|
</Style>
|
||||||
|
</Style>
|
||||||
|
|
||||||
<Style Selector="^.Large">
|
<Style Selector="^.Large">
|
||||||
<Setter Property="Padding" Value="{DynamicResource ButtonLargePadding}" />
|
<Setter Property="Padding" Value="{DynamicResource ButtonLargePadding}" />
|
||||||
</Style>
|
</Style>
|
||||||
|
|||||||
7
src/Ursa/Common/IconPlacement.cs
Normal file
7
src/Ursa/Common/IconPlacement.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Ursa.Common;
|
||||||
|
|
||||||
|
public enum IconPlacement
|
||||||
|
{
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
}
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Metadata;
|
||||||
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Controls.Templates;
|
using Avalonia.Controls.Templates;
|
||||||
|
using Ursa.Common;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
[PseudoClasses(PC_Right)]
|
||||||
public class IconButton: Button
|
public class IconButton: Button
|
||||||
{
|
{
|
||||||
|
public const string PC_Right = ":right";
|
||||||
|
|
||||||
public static readonly StyledProperty<object?> IconProperty = AvaloniaProperty.Register<IconButton, object?>(
|
public static readonly StyledProperty<object?> IconProperty = AvaloniaProperty.Register<IconButton, object?>(
|
||||||
nameof(Icon));
|
nameof(Icon));
|
||||||
|
|
||||||
@@ -32,4 +38,32 @@ public class IconButton: Button
|
|||||||
get => GetValue(IsLoadingProperty);
|
get => GetValue(IsLoadingProperty);
|
||||||
set => SetValue(IsLoadingProperty, value);
|
set => SetValue(IsLoadingProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<IconPlacement> IconPlacementProperty = AvaloniaProperty.Register<IconButton, IconPlacement>(
|
||||||
|
nameof(IconPlacement), defaultValue: IconPlacement.Left);
|
||||||
|
|
||||||
|
public IconPlacement IconPlacement
|
||||||
|
{
|
||||||
|
get => GetValue(IconPlacementProperty);
|
||||||
|
set => SetValue(IconPlacementProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static IconButton()
|
||||||
|
{
|
||||||
|
IconPlacementProperty.Changed.AddClassHandler<IconButton, IconPlacement>((o, e) =>
|
||||||
|
{
|
||||||
|
o.SetPlacement(e.NewValue.Value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnApplyTemplate(e);
|
||||||
|
SetPlacement(IconPlacement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetPlacement(IconPlacement placement)
|
||||||
|
{
|
||||||
|
PseudoClasses.Set(PC_Right, placement == IconPlacement.Right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user