committed by
GitHub
402 changed files with 18211 additions and 3257 deletions
@ -0,0 +1,5 @@ |
|||||
|
<ProjectConfiguration> |
||||
|
<Settings> |
||||
|
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely> |
||||
|
</Settings> |
||||
|
</ProjectConfiguration> |
||||
@ -1,5 +1,5 @@ |
|||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<ItemGroup> |
<ItemGroup> |
||||
<PackageReference Include="Moq" Version="4.7.99" /> |
<PackageReference Include="Moq" Version="4.14.1" /> |
||||
</ItemGroup> |
</ItemGroup> |
||||
</Project> |
</Project> |
||||
|
|||||
@ -1,7 +0,0 @@ |
|||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
||||
<ItemGroup> |
|
||||
<PackageReference Include="Serilog" Version="2.5.0" /> |
|
||||
<PackageReference Include="Serilog.Sinks.Trace" Version="2.1.0" /> |
|
||||
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.0" /> |
|
||||
</ItemGroup> |
|
||||
</Project> |
|
||||
@ -0,0 +1,160 @@ |
|||||
|
#include "common.h" |
||||
|
|
||||
|
|
||||
|
IAvnNativeControlHostTopLevelAttachment* CreateAttachment(); |
||||
|
|
||||
|
class AvnNativeControlHost : |
||||
|
public ComSingleObject<IAvnNativeControlHost, &IID_IAvnNativeControlHost> |
||||
|
{ |
||||
|
public: |
||||
|
FORWARD_IUNKNOWN(); |
||||
|
NSView* View; |
||||
|
AvnNativeControlHost(NSView* view) |
||||
|
{ |
||||
|
View = view; |
||||
|
} |
||||
|
|
||||
|
virtual HRESULT CreateDefaultChild(void* parent, void** retOut) override |
||||
|
{ |
||||
|
NSView* view = [NSView new]; |
||||
|
[view setWantsLayer: true]; |
||||
|
|
||||
|
*retOut = (__bridge_retained void*)view; |
||||
|
return S_OK; |
||||
|
}; |
||||
|
|
||||
|
virtual IAvnNativeControlHostTopLevelAttachment* CreateAttachment() override |
||||
|
{ |
||||
|
return ::CreateAttachment(); |
||||
|
}; |
||||
|
|
||||
|
virtual void DestroyDefaultChild(void* child) override |
||||
|
{ |
||||
|
// ARC will release the object for us |
||||
|
(__bridge_transfer NSView*) child; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
class AvnNativeControlHostTopLevelAttachment : |
||||
|
public ComSingleObject<IAvnNativeControlHostTopLevelAttachment, &IID_IAvnNativeControlHostTopLevelAttachment> |
||||
|
{ |
||||
|
NSView* _holder; |
||||
|
NSView* _child; |
||||
|
public: |
||||
|
FORWARD_IUNKNOWN(); |
||||
|
|
||||
|
AvnNativeControlHostTopLevelAttachment() |
||||
|
{ |
||||
|
_holder = [NSView new]; |
||||
|
[_holder setWantsLayer:true]; |
||||
|
} |
||||
|
|
||||
|
virtual ~AvnNativeControlHostTopLevelAttachment() |
||||
|
{ |
||||
|
if(_child != nil && [_child superview] == _holder) |
||||
|
{ |
||||
|
[_child removeFromSuperview]; |
||||
|
} |
||||
|
|
||||
|
if([_holder superview] != nil) |
||||
|
{ |
||||
|
[_holder removeFromSuperview]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
virtual void* GetParentHandle() override |
||||
|
{ |
||||
|
return (__bridge void*)_holder; |
||||
|
}; |
||||
|
|
||||
|
virtual HRESULT InitializeWithChildHandle(void* child) override |
||||
|
{ |
||||
|
if(_child != nil) |
||||
|
return E_FAIL; |
||||
|
_child = (__bridge NSView*)child; |
||||
|
if(_child == nil) |
||||
|
return E_FAIL; |
||||
|
[_holder addSubview:_child]; |
||||
|
[_child setHidden: false]; |
||||
|
return S_OK; |
||||
|
}; |
||||
|
|
||||
|
virtual HRESULT AttachTo(IAvnNativeControlHost* host) override |
||||
|
{ |
||||
|
if(host == nil) |
||||
|
{ |
||||
|
[_holder removeFromSuperview]; |
||||
|
[_holder setHidden: true]; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
AvnNativeControlHost* chost = dynamic_cast<AvnNativeControlHost*>(host); |
||||
|
if(chost == nil || chost->View == nil) |
||||
|
return E_FAIL; |
||||
|
[_holder setHidden:true]; |
||||
|
[chost->View addSubview:_holder]; |
||||
|
} |
||||
|
return S_OK; |
||||
|
}; |
||||
|
|
||||
|
virtual void ShowInBounds(float x, float y, float width, float height) override |
||||
|
{ |
||||
|
if(_child == nil) |
||||
|
return; |
||||
|
if(AvnInsidePotentialDeadlock::IsInside()) |
||||
|
{ |
||||
|
IAvnNativeControlHostTopLevelAttachment* slf = this; |
||||
|
slf->AddRef(); |
||||
|
dispatch_async(dispatch_get_main_queue(), ^{ |
||||
|
slf->ShowInBounds(x, y, width, height); |
||||
|
slf->Release(); |
||||
|
}); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
NSRect childFrame = {0, 0, width, height}; |
||||
|
NSRect holderFrame = {x, y, width, height}; |
||||
|
|
||||
|
[_child setFrame: childFrame]; |
||||
|
[_holder setFrame: holderFrame]; |
||||
|
[_holder setHidden: false]; |
||||
|
if([_holder superview] != nil) |
||||
|
[[_holder superview] setNeedsDisplay:true]; |
||||
|
} |
||||
|
|
||||
|
virtual void HideWithSize(float width, float height) override |
||||
|
{ |
||||
|
if(_child == nil) |
||||
|
return; |
||||
|
if(AvnInsidePotentialDeadlock::IsInside()) |
||||
|
{ |
||||
|
IAvnNativeControlHostTopLevelAttachment* slf = this; |
||||
|
slf->AddRef(); |
||||
|
dispatch_async(dispatch_get_main_queue(), ^{ |
||||
|
slf->HideWithSize(width, height); |
||||
|
slf->Release(); |
||||
|
}); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
NSRect frame = {0, 0, width, height}; |
||||
|
[_holder setHidden: true]; |
||||
|
[_child setFrame: frame]; |
||||
|
} |
||||
|
|
||||
|
virtual void ReleaseChild() override |
||||
|
{ |
||||
|
[_child removeFromSuperview]; |
||||
|
_child = nil; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
IAvnNativeControlHostTopLevelAttachment* CreateAttachment() |
||||
|
{ |
||||
|
return new AvnNativeControlHostTopLevelAttachment(); |
||||
|
} |
||||
|
|
||||
|
extern IAvnNativeControlHost* CreateNativeControlHost(NSView* parent) |
||||
|
{ |
||||
|
return new AvnNativeControlHost(parent); |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
#include "common.h" |
||||
|
|
||||
|
static int Counter = 0; |
||||
|
AvnInsidePotentialDeadlock::AvnInsidePotentialDeadlock() |
||||
|
{ |
||||
|
Counter++; |
||||
|
} |
||||
|
|
||||
|
AvnInsidePotentialDeadlock::~AvnInsidePotentialDeadlock() |
||||
|
{ |
||||
|
Counter--; |
||||
|
} |
||||
|
|
||||
|
bool AvnInsidePotentialDeadlock::IsInside() |
||||
|
{ |
||||
|
return Counter!=0; |
||||
|
} |
||||
@ -1 +1 @@ |
|||||
Subproject commit 4464343aef5c8ab7a42fcb20a483a6058199f8b8 |
Subproject commit aef10ae67dc55c95f49b52a505a0be33bfa297a5 |
||||
@ -1,3 +1,11 @@ |
|||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<ItemGroup> |
||||
|
<AvailableItemName Include="AvaloniaXaml" /> |
||||
|
<AvailableItemName Include="AvaloniaResource" /> |
||||
|
<PropertyPageSchema Include="$(MSBuildThisFileDirectory)AvaloniaItemSchema.xaml" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup Condition="'$(EnableDefaultItems)'=='True'"> |
||||
|
<AvaloniaXaml Include="**\*.axaml" SubType="Designer" /> |
||||
|
<AvaloniaXaml Include="**\*.paml" SubType="Designer" /> |
||||
|
</ItemGroup> |
||||
</Project> |
</Project> |
||||
|
|||||
@ -0,0 +1,18 @@ |
|||||
|
<ProjectSchemaDefinitions xmlns="http://schemas.microsoft.com/build/2009/properties"> |
||||
|
<ContentType |
||||
|
Name="AvaloniaXaml" |
||||
|
DisplayName="Avalonia XAML" |
||||
|
ItemType="AvaloniaXaml"> |
||||
|
<NameValuePair Name="DependentFileExtensions" Value=".cs" /> |
||||
|
<NameValuePair Name="DefaultMetadata_SubType" Value="Designer" /> |
||||
|
</ContentType> |
||||
|
|
||||
|
<ItemType Name="AvaloniaXaml" DisplayName="Avalonia XAML" /> |
||||
|
<FileExtension Name=".axaml" ContentType="AvaloniaXaml" /> |
||||
|
<FileExtension Name=".paml" ContentType="AvaloniaXaml" /> |
||||
|
<ContentType |
||||
|
Name="AvaloniaResource" |
||||
|
DisplayName="Avalonia Resource" |
||||
|
ItemType="AvaloniaResource" |
||||
|
/> |
||||
|
</ProjectSchemaDefinitions> |
||||
@ -0,0 +1,123 @@ |
|||||
|
<UserControl 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" |
||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" |
||||
|
x:Class="ControlCatalog.Pages.DateTimePickerPage"> |
||||
|
<StackPanel Orientation="Vertical" Spacing="4" HorizontalAlignment="Stretch"> |
||||
|
<TextBlock Classes="h1">DatePicker and TimePicker</TextBlock> |
||||
|
<TextBlock Name="DatePickerDesc" Classes="h2" TextWrapping="Wrap"/> |
||||
|
<TextBlock Name="TimePickerDesc" Classes="h2" TextWrapping="Wrap"/> |
||||
|
|
||||
|
<StackPanel Orientation="Vertical" |
||||
|
Margin="16" |
||||
|
HorizontalAlignment="Stretch" |
||||
|
Spacing="16"> |
||||
|
<TextBlock FontSize="18">A simple DatePicker with a header</TextBlock> |
||||
|
<StackPanel Orientation="Vertical"> |
||||
|
<Border BorderBrush="{DynamicResource SystemControlHighlightBaseLowBrush}" |
||||
|
BorderThickness="1" Padding="15"> |
||||
|
<DatePicker Header="Pick a date" /> |
||||
|
</Border> |
||||
|
<Panel Background="{DynamicResource SystemControlBackgroundBaseLowBrush}"> |
||||
|
<TextBlock Padding="15"> |
||||
|
<TextBlock.Text> |
||||
|
<x:String> |
||||
|
<DatePicker Header="Pick a date" /> |
||||
|
</x:String> |
||||
|
</TextBlock.Text> |
||||
|
</TextBlock> |
||||
|
</Panel> |
||||
|
</StackPanel> |
||||
|
|
||||
|
<TextBlock FontSize="18">A DatePicker with day formatted and year hidden.</TextBlock> |
||||
|
<StackPanel Orientation="Vertical"> |
||||
|
<Border BorderBrush="{DynamicResource SystemControlHighlightBaseLowBrush}" |
||||
|
BorderThickness="1" Padding="15"> |
||||
|
<DatePicker x:Name="Control2" DayFormat="d (ddd)" |
||||
|
YearVisible="False" /> |
||||
|
</Border> |
||||
|
<Panel Background="{DynamicResource SystemControlBackgroundBaseLowBrush}"> |
||||
|
<TextBlock Padding="15"> |
||||
|
<TextBlock.Text> |
||||
|
<x:String> |
||||
|
<DatePicker DayFormat="d (ddd)" YearVisible="False" /> |
||||
|
</x:String> |
||||
|
</TextBlock.Text> |
||||
|
</TextBlock> |
||||
|
</Panel> |
||||
|
</StackPanel> |
||||
|
|
||||
|
<Border Background="{DynamicResource SystemControlHighlightBaseLowBrush}" BorderThickness="1" Margin="15" /> |
||||
|
|
||||
|
<TextBlock FontSize="18">A simple TimePicker.</TextBlock> |
||||
|
<StackPanel Orientation="Vertical"> |
||||
|
<Border BorderBrush="{DynamicResource SystemControlHighlightBaseLowBrush}" |
||||
|
BorderThickness="1" Padding="15"> |
||||
|
<TimePicker /> |
||||
|
</Border> |
||||
|
<Panel Background="{DynamicResource SystemControlBackgroundBaseLowBrush}"> |
||||
|
<TextBlock Padding="15"> |
||||
|
<TextBlock.Text> |
||||
|
<x:String> |
||||
|
<TimePicker /> |
||||
|
</x:String> |
||||
|
</TextBlock.Text> |
||||
|
</TextBlock> |
||||
|
</Panel> |
||||
|
</StackPanel> |
||||
|
|
||||
|
<TextBlock FontSize="18">A TimePicker with a header and minute increments specified.</TextBlock> |
||||
|
<StackPanel Orientation="Vertical"> |
||||
|
<Border BorderBrush="{DynamicResource SystemControlHighlightBaseLowBrush}" |
||||
|
BorderThickness="1" Padding="15"> |
||||
|
<TimePicker Header="Arrival time" MinuteIncrement="15" /> |
||||
|
</Border> |
||||
|
<Panel Background="{DynamicResource SystemControlBackgroundBaseLowBrush}"> |
||||
|
<TextBlock Padding="15"> |
||||
|
<TextBlock.Text> |
||||
|
<x:String> |
||||
|
<TimePicker Header="Arrival time" MinuteIncrement="15" /> |
||||
|
</x:String> |
||||
|
</TextBlock.Text> |
||||
|
</TextBlock> |
||||
|
</Panel> |
||||
|
</StackPanel> |
||||
|
|
||||
|
<TextBlock FontSize="18">A TimePicker using a 12-hour clock.</TextBlock> |
||||
|
<StackPanel Orientation="Vertical"> |
||||
|
<Border BorderBrush="{DynamicResource SystemControlHighlightBaseLowBrush}" |
||||
|
BorderThickness="1" Padding="15"> |
||||
|
<TimePicker ClockIdentifier="12HourClock" Header="12 hour clock" /> |
||||
|
</Border> |
||||
|
<Panel Background="{DynamicResource SystemControlBackgroundBaseLowBrush}"> |
||||
|
<TextBlock Padding="15"> |
||||
|
<TextBlock.Text> |
||||
|
<x:String> |
||||
|
<TimePicker ClockIdentifier="12HourClock" Header="12 hour clock" /> |
||||
|
</x:String> |
||||
|
</TextBlock.Text> |
||||
|
</TextBlock> |
||||
|
</Panel> |
||||
|
</StackPanel> |
||||
|
|
||||
|
<TextBlock FontSize="18">A TimePicker using a 24-hour clock.</TextBlock> |
||||
|
<StackPanel Orientation="Vertical"> |
||||
|
<Border BorderBrush="{DynamicResource SystemControlHighlightBaseLowBrush}" |
||||
|
BorderThickness="1" Padding="15"> |
||||
|
<TimePicker ClockIdentifier="24HourClock" Header="24 hour clock" /> |
||||
|
</Border> |
||||
|
<Panel Background="{DynamicResource SystemControlBackgroundBaseLowBrush}"> |
||||
|
<TextBlock Padding="15"> |
||||
|
<TextBlock.Text> |
||||
|
<x:String> |
||||
|
<TimePicker ClockIdentifier="24HourClock" Header="24 hour clock" /> |
||||
|
</x:String> |
||||
|
</TextBlock.Text> |
||||
|
</TextBlock> |
||||
|
</Panel> |
||||
|
</StackPanel> |
||||
|
|
||||
|
</StackPanel> |
||||
|
</StackPanel> |
||||
|
</UserControl> |
||||
@ -0,0 +1,30 @@ |
|||||
|
using Avalonia; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
|
||||
|
namespace ControlCatalog.Pages |
||||
|
{ |
||||
|
public class DateTimePickerPage : UserControl |
||||
|
{ |
||||
|
public DateTimePickerPage() |
||||
|
{ |
||||
|
this.InitializeComponent(); |
||||
|
this.FindControl<TextBlock>("DatePickerDesc").Text = "Use a DatePicker to let users set a date in your app, " + |
||||
|
"for example to schedule an appointment. The DatePicker displays three controls for month, day, and year. " + |
||||
|
"These controls are easy to use with touch or mouse, and they can be styled and configured in several different ways. " + |
||||
|
"Order of month, day, and year is dynamically set based on user date settings"; |
||||
|
|
||||
|
this.FindControl<TextBlock>("TimePickerDesc").Text = "Use a TimePicker to let users set a time in your app, for example " + |
||||
|
"to set a reminder. The TimePicker displays three controls for hour, minute, and AM / PM(if necessary).These controls " + |
||||
|
"are easy to use with touch or mouse, and they can be styled and configured in several different ways. " + |
||||
|
"12 - hour or 24 - hour clock and visiblility of AM / PM is dynamically set based on user time settings, or can be overridden."; |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
<UserControl xmlns="https://github.com/avaloniaui" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
x:Class="ControlCatalog.Pages.ScrollViewerPage"> |
||||
|
<StackPanel Orientation="Vertical" Spacing="4"> |
||||
|
<TextBlock Classes="h1">ScrollViewer</TextBlock> |
||||
|
<TextBlock Classes="h2">Allows for horizontal and vertical content scrolling.</TextBlock> |
||||
|
|
||||
|
<Grid ColumnDefinitions="Auto, *"> |
||||
|
<StackPanel Orientation="Vertical" Spacing="4"> |
||||
|
<ToggleSwitch IsChecked="{Binding AllowAutoHide}" Content="Allow auto hide" /> |
||||
|
|
||||
|
<StackPanel Orientation="Vertical" Spacing="4"> |
||||
|
<TextBlock Text="Horizontal Scroll" /> |
||||
|
<ComboBox Items="{Binding AvailableVisibility}" SelectedItem="{Binding HorizontalScrollVisibility}" /> |
||||
|
</StackPanel> |
||||
|
|
||||
|
<StackPanel Orientation="Vertical" Spacing="4"> |
||||
|
<TextBlock Text="Vertical Scroll" /> |
||||
|
<ComboBox Items="{Binding AvailableVisibility}" SelectedItem="{Binding VerticalScrollVisibility}" /> |
||||
|
</StackPanel> |
||||
|
</StackPanel> |
||||
|
|
||||
|
<ScrollViewer x:Name="ScrollViewer" |
||||
|
Grid.Column="1" |
||||
|
Width="400" Height="400" |
||||
|
AllowAutoHide="{Binding AllowAutoHide}" |
||||
|
HorizontalScrollBarVisibility="{Binding HorizontalScrollVisibility}" |
||||
|
VerticalScrollBarVisibility="{Binding VerticalScrollVisibility}"> |
||||
|
<Image Width="800" Height="800" Stretch="UniformToFill" |
||||
|
Source="/Assets/delicate-arch-896885_640.jpg" /> |
||||
|
</ScrollViewer> |
||||
|
</Grid> |
||||
|
|
||||
|
</StackPanel> |
||||
|
</UserControl> |
||||
@ -0,0 +1,65 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Controls.Primitives; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
using ReactiveUI; |
||||
|
|
||||
|
namespace ControlCatalog.Pages |
||||
|
{ |
||||
|
public class ScrollViewerPageViewModel : ReactiveObject |
||||
|
{ |
||||
|
private bool _allowAutoHide; |
||||
|
private ScrollBarVisibility _horizontalScrollVisibility; |
||||
|
private ScrollBarVisibility _verticalScrollVisibility; |
||||
|
|
||||
|
public ScrollViewerPageViewModel() |
||||
|
{ |
||||
|
AvailableVisibility = new List<ScrollBarVisibility> |
||||
|
{ |
||||
|
ScrollBarVisibility.Auto, |
||||
|
ScrollBarVisibility.Visible, |
||||
|
ScrollBarVisibility.Hidden, |
||||
|
ScrollBarVisibility.Disabled, |
||||
|
}; |
||||
|
|
||||
|
HorizontalScrollVisibility = ScrollBarVisibility.Auto; |
||||
|
VerticalScrollVisibility = ScrollBarVisibility.Auto; |
||||
|
AllowAutoHide = true; |
||||
|
} |
||||
|
|
||||
|
public bool AllowAutoHide |
||||
|
{ |
||||
|
get => _allowAutoHide; |
||||
|
set => this.RaiseAndSetIfChanged(ref _allowAutoHide, value); |
||||
|
} |
||||
|
|
||||
|
public ScrollBarVisibility HorizontalScrollVisibility |
||||
|
{ |
||||
|
get => _horizontalScrollVisibility; |
||||
|
set => this.RaiseAndSetIfChanged(ref _horizontalScrollVisibility, value); |
||||
|
} |
||||
|
|
||||
|
public ScrollBarVisibility VerticalScrollVisibility |
||||
|
{ |
||||
|
get => _verticalScrollVisibility; |
||||
|
set => this.RaiseAndSetIfChanged(ref _verticalScrollVisibility, value); |
||||
|
} |
||||
|
|
||||
|
public List<ScrollBarVisibility> AvailableVisibility { get; } |
||||
|
} |
||||
|
|
||||
|
public class ScrollViewerPage : UserControl |
||||
|
{ |
||||
|
public ScrollViewerPage() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
|
||||
|
DataContext = new ScrollViewerPageViewModel(); |
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,97 @@ |
|||||
|
<UserControl 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" |
||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" |
||||
|
x:Class="ControlCatalog.Pages.SplitViewPage"> |
||||
|
|
||||
|
<Border> |
||||
|
|
||||
|
<Grid ColumnDefinitions="*,225"> |
||||
|
|
||||
|
<StackPanel Grid.Column="1" Orientation="Vertical" Spacing="4" Margin="5"> |
||||
|
<ToggleButton Name="PaneOpenButton" |
||||
|
Content="IsPaneOpen" |
||||
|
IsChecked="{Binding IsPaneOpen, ElementName=SplitView}" /> |
||||
|
|
||||
|
<ToggleButton Name="UseLightDismissOverlayModeButton" |
||||
|
Content="UseLightDismissOverlayMode" |
||||
|
IsChecked="{Binding UseLightDismissOverlayMode, ElementName=SplitView}" /> |
||||
|
|
||||
|
<ToggleSwitch OffContent="Left" OnContent="Right" Content="Placement" IsChecked="{Binding !IsLeft}" /> |
||||
|
|
||||
|
<TextBlock Text="DisplayMode" /> |
||||
|
<ComboBox Name="DisplayModeSelector" Width="170" Margin="10" SelectedIndex="{Binding DisplayMode}"> |
||||
|
<ComboBoxItem>Inline</ComboBoxItem> |
||||
|
<ComboBoxItem>CompactInline</ComboBoxItem> |
||||
|
<ComboBoxItem>Overlay</ComboBoxItem> |
||||
|
<ComboBoxItem>CompactOverlay</ComboBoxItem> |
||||
|
</ComboBox> |
||||
|
|
||||
|
<TextBlock Text="PaneBackground" /> |
||||
|
<ComboBox Name="PaneBackgroundSelector" SelectedIndex="0" Width="170" Margin="10"> |
||||
|
<ComboBoxItem Tag="{DynamicResource SystemControlBackgroundChromeMediumLowBrush}">SystemControlBackgroundChromeMediumLowBrush</ComboBoxItem> |
||||
|
<ComboBoxItem Tag="Red">Red</ComboBoxItem> |
||||
|
<ComboBoxItem Tag="Blue">Blue</ComboBoxItem> |
||||
|
<ComboBoxItem Tag="Green">Green</ComboBoxItem> |
||||
|
</ComboBox> |
||||
|
|
||||
|
<TextBlock Text="{Binding Value, ElementName=OpenPaneLengthSlider, StringFormat='{}OpenPaneLength: {0}'}" /> |
||||
|
<Slider Name="OpenPaneLengthSlider" Value="256" Minimum="128" Maximum="500" |
||||
|
Width="150" /> |
||||
|
|
||||
|
<TextBlock Text="{Binding Value, ElementName=CompactPaneLengthSlider, StringFormat='{}CompactPaneLength: {0}'}" /> |
||||
|
<Slider Name="CompactPaneLengthSlider" Value="48" Minimum="24" Maximum="128" |
||||
|
Width="150" /> |
||||
|
|
||||
|
</StackPanel> |
||||
|
|
||||
|
<Border BorderBrush="{DynamicResource SystemControlHighlightBaseLowBrush}" |
||||
|
BorderThickness="1"> |
||||
|
<!--{Binding SelectedItem.Tag, ElementName=PaneBackgroundSelector}--> |
||||
|
<SplitView Name="SplitView" |
||||
|
PanePlacement="{Binding PanePlacement}" |
||||
|
PaneBackground="{Binding SelectedItem.Tag, ElementName=PaneBackgroundSelector}" |
||||
|
OpenPaneLength="{Binding Value, ElementName=OpenPaneLengthSlider}" |
||||
|
CompactPaneLength="{Binding Value, ElementName=CompactPaneLengthSlider}" |
||||
|
DisplayMode="{Binding CurrentDisplayMode}"> |
||||
|
<SplitView.Pane> |
||||
|
<Grid> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition Height="Auto" /> |
||||
|
<RowDefinition Height="*" /> |
||||
|
<RowDefinition Height="Auto" /> |
||||
|
</Grid.RowDefinitions> |
||||
|
<TextBlock Text="PANE CONTENT" FontWeight="Bold" Name="PaneHeader" Margin="5,12,0,0" /> |
||||
|
<ListBoxItem Grid.Row="1" VerticalAlignment="Top" Margin="0 10"> |
||||
|
<StackPanel Orientation="Horizontal"> |
||||
|
<!--Path glyph from materialdesignicons.com--> |
||||
|
<Border Width="48"> |
||||
|
<Viewbox Width="24" Height="24" HorizontalAlignment="Left"> |
||||
|
<Canvas Width="24" Height="24"> |
||||
|
<Path Fill="{DynamicResource SystemControlForegroundBaseHighBrush}" Data="M16 17V19H2V17S2 13 9 13 16 17 16 17M12.5 7.5A3.5 3.5 0 1 0 9 11A3.5 3.5 0 0 0 12.5 7.5M15.94 13A5.32 5.32 0 0 1 18 17V19H22V17S22 13.37 15.94 13M15 4A3.39 3.39 0 0 0 13.07 4.59A5 5 0 0 1 13.07 10.41A3.39 3.39 0 0 0 15 11A3.5 3.5 0 0 0 15 4Z" /> |
||||
|
</Canvas> |
||||
|
</Viewbox> |
||||
|
</Border> |
||||
|
<TextBlock Text="People" VerticalAlignment="Center" /> |
||||
|
</StackPanel> |
||||
|
</ListBoxItem> |
||||
|
<TextBlock Grid.Row="2" Text="Item at bottom" Margin="60,12" /> |
||||
|
</Grid> |
||||
|
</SplitView.Pane> |
||||
|
|
||||
|
<Grid> |
||||
|
<TextBlock FontSize="14" FontWeight="700" Text="SplitViewContent" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}" /> |
||||
|
<TextBlock FontSize="14" FontWeight="700" Text="SplitViewContent" TextAlignment="Left" Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}" /> |
||||
|
<TextBlock FontSize="14" FontWeight="700" Text="SplitViewContent" HorizontalAlignment="Right" TextAlignment="Left" Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}" /> |
||||
|
<TextBlock FontSize="14" FontWeight="700" Text="SplitViewContent" VerticalAlignment="Bottom" TextAlignment="Left" Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}" /> |
||||
|
<TextBlock FontSize="14" FontWeight="700" Text="SplitViewContent" VerticalAlignment="Bottom" HorizontalAlignment="Right" TextAlignment="Left" Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}" /> |
||||
|
</Grid> |
||||
|
|
||||
|
</SplitView> |
||||
|
</Border> |
||||
|
|
||||
|
</Grid> |
||||
|
</Border> |
||||
|
|
||||
|
</UserControl> |
||||
@ -0,0 +1,21 @@ |
|||||
|
using Avalonia; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
using ControlCatalog.ViewModels; |
||||
|
|
||||
|
namespace ControlCatalog.Pages |
||||
|
{ |
||||
|
public class SplitViewPage : UserControl |
||||
|
{ |
||||
|
public SplitViewPage() |
||||
|
{ |
||||
|
this.InitializeComponent(); |
||||
|
DataContext = new SplitViewPageViewModel(); |
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,79 @@ |
|||||
|
<UserControl xmlns="https://github.com/avaloniaui" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
x:Class="ControlCatalog.Pages.ToggleSwitchPage" Margin="5"> |
||||
|
<StackPanel Width="500" HorizontalAlignment="Center"> |
||||
|
<TextBlock Text="Simple ToggleSwitch" Classes="header"/> |
||||
|
<Border Classes="Thin"> |
||||
|
<StackPanel> |
||||
|
<ToggleSwitch Margin="10"/> |
||||
|
<TextBox Text="<ToggleSwitch/>" Classes="CodeBox"/> |
||||
|
</StackPanel> |
||||
|
</Border> |
||||
|
|
||||
|
<TextBlock Text="headered ToggleSwitch" Classes="header"/> |
||||
|
|
||||
|
<Border Classes="Thin"> |
||||
|
<StackPanel> |
||||
|
<ToggleSwitch Content="headered" IsChecked="true" Margin="10"/> |
||||
|
<TextBox Classes="CodeBox" |
||||
|
Text="<ToggleSwitch>headered</ToggleSwitch>"/> |
||||
|
</StackPanel> |
||||
|
</Border> |
||||
|
|
||||
|
<TextBlock Text="Custom content ToggleSwitch" Classes="header"/> |
||||
|
|
||||
|
<Border Classes="Thin"> |
||||
|
<StackPanel> |
||||
|
<ToggleSwitch Content="Custom" |
||||
|
OnContent="On" |
||||
|
OffContent="Off" |
||||
|
Margin="10"/> |
||||
|
|
||||
|
<TextBox Text="<ToggleSwitch Content="Custom" |
||||
|
ContentOn="On" |
||||
|
ContentOff="Off" />" |
||||
|
Classes="CodeBox"/> |
||||
|
</StackPanel> |
||||
|
</Border> |
||||
|
|
||||
|
<TextBlock Text="Image content ToggleSwitch" Classes="header"/> |
||||
|
|
||||
|
<Border Classes="Thin"> |
||||
|
<StackPanel> |
||||
|
<ToggleSwitch Content="Just Click!" Margin="10"> |
||||
|
<ToggleSwitch.OnContent> |
||||
|
<Image Source="/Assets/hirsch-899118_640.jpg" Height="32"/> |
||||
|
</ToggleSwitch.OnContent> |
||||
|
|
||||
|
<ToggleSwitch.OffContent> |
||||
|
<Image Source="/Assets/delicate-arch-896885_640.jpg" Height="32"/> |
||||
|
</ToggleSwitch.OffContent> |
||||
|
|
||||
|
</ToggleSwitch> |
||||
|
</StackPanel> |
||||
|
</Border> |
||||
|
</StackPanel> |
||||
|
|
||||
|
<UserControl.Styles > |
||||
|
<Style Selector="TextBox.CodeBox" > |
||||
|
<Setter Property="Padding" Value="10"/> |
||||
|
<Setter Property="IsReadOnly" Value="True"/> |
||||
|
<Setter Property="BorderBrush" Value="Transparent"/> |
||||
|
<Setter Property="FontSize" Value="14"/> |
||||
|
<Setter Property="IsEnabled" Value="true"/> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="TextBlock.header"> |
||||
|
<Setter Property="FontSize" Value="18"/> |
||||
|
<Setter Property="Margin" Value="0 20 0 20"/> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="Border.Thin"> |
||||
|
<Setter Property="BorderBrush" Value="Gray"/> |
||||
|
<Setter Property="BorderThickness" Value="0.5"/> |
||||
|
<Setter Property="CornerRadius" Value="2"/> |
||||
|
</Style> |
||||
|
|
||||
|
</UserControl.Styles> |
||||
|
</UserControl> |
||||
|
|
||||
@ -0,0 +1,19 @@ |
|||||
|
using Avalonia; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
|
||||
|
namespace ControlCatalog.Pages |
||||
|
{ |
||||
|
public class ToggleSwitchPage : UserControl |
||||
|
{ |
||||
|
public ToggleSwitchPage() |
||||
|
{ |
||||
|
this.InitializeComponent(); |
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
using System; |
||||
|
using Avalonia.Controls; |
||||
|
using ReactiveUI; |
||||
|
|
||||
|
namespace ControlCatalog.ViewModels |
||||
|
{ |
||||
|
public class SplitViewPageViewModel : ReactiveObject |
||||
|
{ |
||||
|
private bool _isLeft = true; |
||||
|
private int _displayMode = 3; //CompactOverlay
|
||||
|
|
||||
|
public bool IsLeft |
||||
|
{ |
||||
|
get => _isLeft; |
||||
|
set |
||||
|
{ |
||||
|
this.RaiseAndSetIfChanged(ref _isLeft, value); |
||||
|
this.RaisePropertyChanged(nameof(PanePlacement)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public int DisplayMode |
||||
|
{ |
||||
|
get => _displayMode; |
||||
|
set |
||||
|
{ |
||||
|
this.RaiseAndSetIfChanged(ref _displayMode, value); |
||||
|
this.RaisePropertyChanged(nameof(CurrentDisplayMode)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public SplitViewPanePlacement PanePlacement => _isLeft ? SplitViewPanePlacement.Left : SplitViewPanePlacement.Right; |
||||
|
|
||||
|
public SplitViewDisplayMode CurrentDisplayMode |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
if (Enum.IsDefined(typeof(SplitViewDisplayMode), _displayMode)) |
||||
|
{ |
||||
|
return (SplitViewDisplayMode)_displayMode; |
||||
|
} |
||||
|
return SplitViewDisplayMode.CompactOverlay; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,115 @@ |
|||||
|
<UserControl |
||||
|
xmlns="https://github.com/avaloniaui" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
x:Class="RenderDemo.Pages.TransitionsPage"> |
||||
|
<UserControl.Styles> |
||||
|
<Styles> |
||||
|
<Styles.Resources> |
||||
|
<Template x:Key="Acorn"> |
||||
|
<Path Fill="White" Stretch="Uniform" |
||||
|
Data="F1 M 16.6309,18.6563C 17.1309, |
||||
|
8.15625 29.8809,14.1563 29.8809, |
||||
|
14.1563C 30.8809,11.1563 34.1308, |
||||
|
11.4063 34.1308,11.4063C 33.5,12 |
||||
|
34.6309,13.1563 34.6309,13.1563C |
||||
|
32.1309,13.1562 31.1309,14.9062 |
||||
|
31.1309,14.9062C 41.1309,23.9062 |
||||
|
32.6309,27.9063 32.6309,27.9062C |
||||
|
24.6309,24.9063 21.1309,22.1562 |
||||
|
16.6309,18.6563 Z M 16.6309,19.9063C |
||||
|
21.6309,24.1563 25.1309,26.1562 |
||||
|
31.6309,28.6562C 31.6309,28.6562 |
||||
|
26.3809,39.1562 18.3809,36.1563C |
||||
|
18.3809,36.1563 18,38 16.3809,36.9063C |
||||
|
15,36 16.3809,34.9063 16.3809,34.9063C |
||||
|
16.3809,34.9063 10.1309,30.9062 16.6309,19.9063 Z"/> |
||||
|
</Template> |
||||
|
<Template x:Key="Heart"> |
||||
|
<Path Fill="Red" Stretch="Uniform" Data=" |
||||
|
M 272.70141,238.71731 |
||||
|
C 206.46141,238.71731 152.70146,292.4773 152.70146,358.71731 |
||||
|
C 152.70146,493.47282 288.63461,528.80461 381.26391,662.02535 |
||||
|
C 468.83815,529.62199 609.82641,489.17075 609.82641,358.71731 |
||||
|
C 609.82641,292.47731 556.06651,238.7173 489.82641,238.71731 |
||||
|
C 441.77851,238.71731 400.42481,267.08774 381.26391,307.90481 |
||||
|
C 362.10311,267.08773 320.74941,238.7173 272.70141,238.71731 z "/> |
||||
|
</Template> |
||||
|
</Styles.Resources> |
||||
|
|
||||
|
<Style Selector="Border.Test"> |
||||
|
<Setter Property="Margin" Value="15"/> |
||||
|
<Setter Property="Width" Value="100"/> |
||||
|
<Setter Property="Height" Value="100"/> |
||||
|
<Setter Property="Child" Value="{StaticResource Acorn}"/> |
||||
|
<Setter Property="Transitions"> |
||||
|
<Transitions> |
||||
|
<TransformOperationsTransition Property="RenderTransform" Duration="0:0:1" /> |
||||
|
</Transitions> |
||||
|
</Setter> |
||||
|
<Setter Property="RenderTransform" Value="none" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="Border.Rect1:pointerover"> |
||||
|
<Setter Property="RenderTransform" Value="rotate(120deg) scale(1.5)" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="Border.Rect2:pointerover"> |
||||
|
<Setter Property="RenderTransform" Value="scale(0.8)" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="Border.Rect3"> |
||||
|
<Setter Property="Child" Value="{StaticResource Heart}"/> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="Border.Rect3:pointerover"> |
||||
|
<Setter Property="RenderTransform" Value="rotate(1turn)" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="Border.Rect4:pointerover"> |
||||
|
<Setter Property="RenderTransform" Value="translateY(-100px)" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="Border.Rect5:pointerover"> |
||||
|
<Setter Property="RenderTransform" Value="skewX(-20deg)" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="Border.Rect5:pointerover"> |
||||
|
<Setter Property="RenderTransform" Value="skewX(-20deg)" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="Border.Rect6"> |
||||
|
<Setter Property="Transitions"> |
||||
|
<Transitions> |
||||
|
<TransformOperationsTransition Property="RenderTransform" Duration="0:0:0.5" Delay="0:0:1"/> |
||||
|
</Transitions> |
||||
|
</Setter> |
||||
|
<Setter Property="RenderTransform" Value="scale(0.8)" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="Border.Rect6:pointerover"> |
||||
|
<Setter Property="RenderTransform" Value="none" /> |
||||
|
</Style> |
||||
|
|
||||
|
</Styles> |
||||
|
</UserControl.Styles> |
||||
|
|
||||
|
<Grid> |
||||
|
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" ClipToBounds="False"> |
||||
|
<StackPanel.Clock> |
||||
|
<Clock /> |
||||
|
</StackPanel.Clock> |
||||
|
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"> |
||||
|
<TextBlock VerticalAlignment="Center">Hover to activate Transform Keyframe Animations.</TextBlock> |
||||
|
<Button Content="{Binding PlayStateText}" Command="{Binding TogglePlayState}" Click="ToggleClock" /> |
||||
|
</StackPanel> |
||||
|
<WrapPanel ClipToBounds="False"> |
||||
|
<Border Classes="Test Rect1" Background="DarkRed"/> |
||||
|
<Border Classes="Test Rect2" Background="Magenta"/> |
||||
|
<Border Classes="Test Rect3"/> |
||||
|
<Border Classes="Test Rect4" Background="Navy"/> |
||||
|
<Border Classes="Test Rect5" Background="SeaGreen"/> |
||||
|
<Border Classes="Test Rect6" Background="Orange"/> |
||||
|
</WrapPanel> |
||||
|
</StackPanel> |
||||
|
</Grid> |
||||
|
</UserControl> |
||||
@ -0,0 +1,37 @@ |
|||||
|
using Avalonia.Animation; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Interactivity; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
using RenderDemo.ViewModels; |
||||
|
|
||||
|
namespace RenderDemo.Pages |
||||
|
{ |
||||
|
public class TransitionsPage : UserControl |
||||
|
{ |
||||
|
public TransitionsPage() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
this.DataContext = new AnimationsPageViewModel(); |
||||
|
} |
||||
|
|
||||
|
private void InitializeComponent() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
|
||||
|
private void ToggleClock(object sender, RoutedEventArgs args) |
||||
|
{ |
||||
|
var button = sender as Button; |
||||
|
var clock = button.Clock; |
||||
|
|
||||
|
if (clock.PlayState == PlayState.Run) |
||||
|
{ |
||||
|
clock.PlayState = PlayState.Pause; |
||||
|
} |
||||
|
else if (clock.PlayState == PlayState.Pause) |
||||
|
{ |
||||
|
clock.PlayState = PlayState.Run; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
<Application xmlns="https://github.com/avaloniaui" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
x:Class="NativeEmbedSample.App"> |
||||
|
<Application.Styles> |
||||
|
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/> |
||||
|
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/> |
||||
|
</Application.Styles> |
||||
|
</Application> |
||||
@ -0,0 +1,22 @@ |
|||||
|
using Avalonia; |
||||
|
using Avalonia.Controls.ApplicationLifetimes; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
|
||||
|
namespace NativeEmbedSample |
||||
|
{ |
||||
|
public class App : Application |
||||
|
{ |
||||
|
public override void Initialize() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
} |
||||
|
|
||||
|
public override void OnFrameworkInitializationCompleted() |
||||
|
{ |
||||
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime) |
||||
|
desktopLifetime.MainWindow = new MainWindow(); |
||||
|
|
||||
|
base.OnFrameworkInitializationCompleted(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,121 @@ |
|||||
|
using System; |
||||
|
using System.Diagnostics; |
||||
|
using System.IO; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Platform; |
||||
|
using Avalonia.Threading; |
||||
|
using MonoMac.AppKit; |
||||
|
using MonoMac.Foundation; |
||||
|
using MonoMac.WebKit; |
||||
|
using Encoding = SharpDX.Text.Encoding; |
||||
|
|
||||
|
namespace NativeEmbedSample |
||||
|
{ |
||||
|
public class EmbedSample : NativeControlHost |
||||
|
{ |
||||
|
public bool IsSecond { get; set; } |
||||
|
private Process _mplayer; |
||||
|
|
||||
|
IPlatformHandle CreateLinux(IPlatformHandle parent) |
||||
|
{ |
||||
|
if (IsSecond) |
||||
|
{ |
||||
|
var chooser = GtkHelper.CreateGtkFileChooser(parent.Handle); |
||||
|
if (chooser != null) |
||||
|
return chooser; |
||||
|
} |
||||
|
|
||||
|
var control = base.CreateNativeControlCore(parent); |
||||
|
var nodes = Path.GetFullPath(Path.Combine(typeof(EmbedSample).Assembly.GetModules()[0].FullyQualifiedName, |
||||
|
"..", |
||||
|
"nodes.mp4")); |
||||
|
_mplayer = Process.Start(new ProcessStartInfo("mplayer", |
||||
|
$"-vo x11 -zoom -loop 0 -wid {control.Handle.ToInt64()} \"{nodes}\"") |
||||
|
{ |
||||
|
UseShellExecute = false, |
||||
|
|
||||
|
}); |
||||
|
return control; |
||||
|
} |
||||
|
|
||||
|
void DestroyLinux(IPlatformHandle handle) |
||||
|
{ |
||||
|
_mplayer?.Kill(); |
||||
|
_mplayer = null; |
||||
|
base.DestroyNativeControlCore(handle); |
||||
|
} |
||||
|
|
||||
|
private const string RichText = |
||||
|
@"{\rtf1\ansi\ansicpg1251\deff0\nouicompat\deflang1049{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
|
||||
|
{\colortbl ;\red255\green0\blue0;\red0\green77\blue187;\red0\green176\blue80;\red155\green0\blue211;\red247\green150\blue70;\red75\green172\blue198;} |
||||
|
{\*\generator Riched20 6.3.9600}\viewkind4\uc1 |
||||
|
\pard\sa200\sl276\slmult1\f0\fs22\lang9 <PREFIX>I \i am\i0 a \cf1\b Rich Text \cf0\b0\fs24 control\cf2\fs28 !\cf3\fs32 !\cf4\fs36 !\cf1\fs40 !\cf5\fs44 !\cf6\fs48 !\cf0\fs44\par |
||||
|
}";
|
||||
|
|
||||
|
IPlatformHandle CreateWin32(IPlatformHandle parent) |
||||
|
{ |
||||
|
WinApi.LoadLibrary("Msftedit.dll"); |
||||
|
var handle = WinApi.CreateWindowEx(0, "RICHEDIT50W", |
||||
|
@"Rich Edit", |
||||
|
0x800000 | 0x10000000 | 0x40000000 | 0x800000 | 0x10000 | 0x0004, 0, 0, 1, 1, parent.Handle, |
||||
|
IntPtr.Zero, WinApi.GetModuleHandle(null), IntPtr.Zero); |
||||
|
var st = new WinApi.SETTEXTEX { Codepage = 65001, Flags = 0x00000008 }; |
||||
|
var text = RichText.Replace("<PREFIX>", IsSecond ? "\\qr " : ""); |
||||
|
var bytes = Encoding.UTF8.GetBytes(text); |
||||
|
WinApi.SendMessage(handle, 0x0400 + 97, ref st, bytes); |
||||
|
return new PlatformHandle(handle, "HWND"); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void DestroyWin32(IPlatformHandle handle) |
||||
|
{ |
||||
|
WinApi.DestroyWindow(handle.Handle); |
||||
|
} |
||||
|
|
||||
|
IPlatformHandle CreateOSX(IPlatformHandle parent) |
||||
|
{ |
||||
|
// Note: We are using MonoMac for example purposes
|
||||
|
// It shouldn't be used in production apps
|
||||
|
MacHelper.EnsureInitialized(); |
||||
|
|
||||
|
var webView = new WebView(); |
||||
|
Dispatcher.UIThread.Post(() => |
||||
|
{ |
||||
|
webView.MainFrame.LoadRequest(new NSUrlRequest(new NSUrl( |
||||
|
IsSecond ? "https://bing.com": "https://google.com/"))); |
||||
|
}); |
||||
|
return new MacOSViewHandle(webView); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void DestroyOSX(IPlatformHandle handle) |
||||
|
{ |
||||
|
((MacOSViewHandle)handle).Dispose(); |
||||
|
} |
||||
|
|
||||
|
protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent) |
||||
|
{ |
||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) |
||||
|
return CreateLinux(parent); |
||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
||||
|
return CreateWin32(parent); |
||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) |
||||
|
return CreateOSX(parent); |
||||
|
return base.CreateNativeControlCore(parent); |
||||
|
} |
||||
|
|
||||
|
protected override void DestroyNativeControlCore(IPlatformHandle control) |
||||
|
{ |
||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) |
||||
|
DestroyLinux(control); |
||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
||||
|
DestroyWin32(control); |
||||
|
else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) |
||||
|
DestroyOSX(control); |
||||
|
else |
||||
|
base.DestroyNativeControlCore(control); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Avalonia.Controls.Platform; |
||||
|
using Avalonia.Platform; |
||||
|
using Avalonia.Platform.Interop; |
||||
|
using Avalonia.X11.NativeDialogs; |
||||
|
using static Avalonia.X11.NativeDialogs.Gtk; |
||||
|
using static Avalonia.X11.NativeDialogs.Glib; |
||||
|
namespace NativeEmbedSample |
||||
|
{ |
||||
|
public class GtkHelper |
||||
|
{ |
||||
|
private static Task<bool> s_gtkTask; |
||||
|
class FileChooser : INativeControlHostDestroyableControlHandle |
||||
|
{ |
||||
|
private readonly IntPtr _widget; |
||||
|
|
||||
|
public FileChooser(IntPtr widget, IntPtr xid) |
||||
|
{ |
||||
|
_widget = widget; |
||||
|
Handle = xid; |
||||
|
} |
||||
|
|
||||
|
public IntPtr Handle { get; } |
||||
|
public string HandleDescriptor => "XID"; |
||||
|
public void Destroy() |
||||
|
{ |
||||
|
RunOnGlibThread(() => |
||||
|
{ |
||||
|
gtk_widget_destroy(_widget); |
||||
|
return 0; |
||||
|
}).Wait(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
public static IPlatformHandle CreateGtkFileChooser(IntPtr parentXid) |
||||
|
{ |
||||
|
if (s_gtkTask == null) |
||||
|
s_gtkTask = StartGtk(); |
||||
|
if (!s_gtkTask.Result) |
||||
|
return null; |
||||
|
return RunOnGlibThread(() => |
||||
|
{ |
||||
|
using (var title = new Utf8Buffer("Embedded")) |
||||
|
{ |
||||
|
var widget = gtk_file_chooser_dialog_new(title, IntPtr.Zero, GtkFileChooserAction.SelectFolder, |
||||
|
IntPtr.Zero); |
||||
|
gtk_widget_realize(widget); |
||||
|
var xid = gdk_x11_window_get_xid(gtk_widget_get_window(widget)); |
||||
|
gtk_window_present(widget); |
||||
|
return new FileChooser(widget, xid); |
||||
|
} |
||||
|
}).Result; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
using System; |
||||
|
using Avalonia.Platform; |
||||
|
using MonoMac.AppKit; |
||||
|
|
||||
|
namespace NativeEmbedSample |
||||
|
{ |
||||
|
public class MacHelper |
||||
|
{ |
||||
|
private static bool _isInitialized; |
||||
|
|
||||
|
public static void EnsureInitialized() |
||||
|
{ |
||||
|
if (_isInitialized) |
||||
|
return; |
||||
|
_isInitialized = true; |
||||
|
NSApplication.Init(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
class MacOSViewHandle : IPlatformHandle, IDisposable |
||||
|
{ |
||||
|
private NSView _view; |
||||
|
|
||||
|
public MacOSViewHandle(NSView view) |
||||
|
{ |
||||
|
_view = view; |
||||
|
} |
||||
|
|
||||
|
public IntPtr Handle => _view?.Handle ?? IntPtr.Zero; |
||||
|
public string HandleDescriptor => "NSView"; |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
_view.Dispose(); |
||||
|
_view = null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
<Window xmlns="https://github.com/avaloniaui" MinWidth="500" MinHeight="300" |
||||
|
Width="1024" Height="800" |
||||
|
Title="Native embedding sample" |
||||
|
xmlns:local="clr-namespace:NativeEmbedSample" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
x:Class="NativeEmbedSample.MainWindow"> |
||||
|
<DockPanel> |
||||
|
<Menu DockPanel.Dock="Top"> |
||||
|
<MenuItem Header="Test"> |
||||
|
<MenuItem Header="SubMenu"> |
||||
|
<MenuItem Header="Item 1"/> |
||||
|
<MenuItem Header="Item 2"/> |
||||
|
<MenuItem Header="Item 3"/> |
||||
|
</MenuItem> |
||||
|
<MenuItem Header="Item 1"/> |
||||
|
<MenuItem Header="Item 2"/> |
||||
|
<MenuItem Header="Item 3"/> |
||||
|
</MenuItem> |
||||
|
</Menu> |
||||
|
<DockPanel DockPanel.Dock="Top"> |
||||
|
<Button DockPanel.Dock="Right" Click="ShowPopupDelay">Show popup (delay)</Button> |
||||
|
<Button DockPanel.Dock="Right" Click="ShowPopup">Show popup</Button> |
||||
|
<Border DockPanel.Dock="Right" Background="#c0c0c0"> |
||||
|
<ToolTip.Tip> |
||||
|
<ToolTip> |
||||
|
<TextBlock>Text</TextBlock> |
||||
|
</ToolTip> |
||||
|
</ToolTip.Tip> |
||||
|
<TextBlock>Tooltip</TextBlock> |
||||
|
</Border> |
||||
|
<TextBox Text="Lorem ipsum dolor sit amet"/> |
||||
|
|
||||
|
</DockPanel> |
||||
|
<Grid ColumnDefinitions="*,5,*"> |
||||
|
<DockPanel> |
||||
|
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top"> |
||||
|
<CheckBox x:Name="firstVisible" IsChecked="True"/> |
||||
|
<TextBlock>Visible</TextBlock> |
||||
|
</StackPanel> |
||||
|
<local:EmbedSample IsVisible="{Binding #firstVisible.IsChecked}"/> |
||||
|
</DockPanel> |
||||
|
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" /> |
||||
|
<DockPanel Grid.Column="2"> |
||||
|
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top"> |
||||
|
<CheckBox x:Name="secondVisible" IsChecked="True"/> |
||||
|
<TextBlock>Visible</TextBlock> |
||||
|
</StackPanel> |
||||
|
<local:EmbedSample IsSecond="True" IsVisible="{Binding #secondVisible.IsChecked}"/> |
||||
|
</DockPanel> |
||||
|
</Grid> |
||||
|
</DockPanel> |
||||
|
</Window> |
||||
@ -0,0 +1,36 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Avalonia; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Interactivity; |
||||
|
using Avalonia.Markup.Xaml; |
||||
|
|
||||
|
namespace NativeEmbedSample |
||||
|
{ |
||||
|
public class MainWindow : Window |
||||
|
{ |
||||
|
public MainWindow() |
||||
|
{ |
||||
|
AvaloniaXamlLoader.Load(this); |
||||
|
this.AttachDevTools(); |
||||
|
} |
||||
|
|
||||
|
public async void ShowPopupDelay(object sender, RoutedEventArgs args) |
||||
|
{ |
||||
|
await Task.Delay(3000); |
||||
|
ShowPopup(sender, args); |
||||
|
} |
||||
|
|
||||
|
public void ShowPopup(object sender, RoutedEventArgs args) |
||||
|
{ |
||||
|
|
||||
|
new ContextMenu() |
||||
|
{ |
||||
|
Items = new List<MenuItem> |
||||
|
{ |
||||
|
new MenuItem() { Header = "Test" }, new MenuItem() { Header = "Test" } |
||||
|
} |
||||
|
}.Open((Control)sender); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<OutputType>Exe</OutputType> |
||||
|
<TargetFramework>netcoreapp2.0</TargetFramework> |
||||
|
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> |
||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="MonoMac.NetStandard" Version="0.0.4" /> |
||||
|
<ProjectReference Include="..\..\..\src\Avalonia.Desktop\Avalonia.Desktop.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\src\Avalonia.Diagnostics\Avalonia.Diagnostics.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\src\Avalonia.X11\Avalonia.X11.csproj" /> |
||||
|
<PackageReference Include="Avalonia.Angle.Windows.Natives" Version="2.1.0.2019013001" /> |
||||
|
|
||||
|
<AvaloniaResource Include="**\*.xaml"> |
||||
|
<SubType>Designer</SubType> |
||||
|
</AvaloniaResource> |
||||
|
<None Remove="nodes.mp4" /> |
||||
|
<Content Include="nodes.mp4"> |
||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
||||
|
</Content> |
||||
|
<Compile Include="..\..\..\src\Avalonia.X11\NativeDialogs\Gtk.cs" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<Import Project="..\..\..\build\SampleApp.props" /> |
||||
|
<Import Project="..\..\..\build\BuildTargets.targets" /> |
||||
|
<Import Project="..\..\..\build\ReferenceCoreLibraries.props" /> |
||||
|
</Project> |
||||
@ -0,0 +1,17 @@ |
|||||
|
using Avalonia; |
||||
|
|
||||
|
namespace NativeEmbedSample |
||||
|
{ |
||||
|
class Program |
||||
|
{ |
||||
|
static int Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); |
||||
|
|
||||
|
public static AppBuilder BuildAvaloniaApp() |
||||
|
=> AppBuilder.Configure<App>() |
||||
|
.With(new AvaloniaNativePlatformOptions() |
||||
|
{ |
||||
|
}) |
||||
|
.UsePlatformDetect(); |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,74 @@ |
|||||
|
using System; |
||||
|
using System.Runtime.InteropServices; |
||||
|
|
||||
|
namespace NativeEmbedSample |
||||
|
{ |
||||
|
public unsafe class WinApi |
||||
|
{ |
||||
|
public enum CommonControls : uint |
||||
|
{ |
||||
|
ICC_LISTVIEW_CLASSES = 0x00000001, // listview, header
|
||||
|
ICC_TREEVIEW_CLASSES = 0x00000002, // treeview, tooltips
|
||||
|
ICC_BAR_CLASSES = 0x00000004, // toolbar, statusbar, trackbar, tooltips
|
||||
|
ICC_TAB_CLASSES = 0x00000008, // tab, tooltips
|
||||
|
ICC_UPDOWN_CLASS = 0x00000010, // updown
|
||||
|
ICC_PROGRESS_CLASS = 0x00000020, // progress
|
||||
|
ICC_HOTKEY_CLASS = 0x00000040, // hotkey
|
||||
|
ICC_ANIMATE_CLASS = 0x00000080, // animate
|
||||
|
ICC_WIN95_CLASSES = 0x000000FF, |
||||
|
ICC_DATE_CLASSES = 0x00000100, // month picker, date picker, time picker, updown
|
||||
|
ICC_USEREX_CLASSES = 0x00000200, // comboex
|
||||
|
ICC_COOL_CLASSES = 0x00000400, // rebar (coolbar) control
|
||||
|
ICC_INTERNET_CLASSES = 0x00000800, |
||||
|
ICC_PAGESCROLLER_CLASS = 0x00001000, // page scroller
|
||||
|
ICC_NATIVEFNTCTL_CLASS = 0x00002000, // native font control
|
||||
|
ICC_STANDARD_CLASSES = 0x00004000, |
||||
|
ICC_LINK_CLASS = 0x00008000 |
||||
|
} |
||||
|
|
||||
|
[StructLayout(LayoutKind.Sequential)] |
||||
|
public struct INITCOMMONCONTROLSEX |
||||
|
{ |
||||
|
public int dwSize; |
||||
|
public uint dwICC; |
||||
|
} |
||||
|
|
||||
|
[DllImport("Comctl32.dll")] |
||||
|
public static extern void InitCommonControlsEx(ref INITCOMMONCONTROLSEX init); |
||||
|
|
||||
|
[DllImport("user32.dll", SetLastError = true)] |
||||
|
public static extern bool DestroyWindow(IntPtr hwnd); |
||||
|
|
||||
|
[DllImport("kernel32.dll")] |
||||
|
public static extern IntPtr LoadLibrary(string lib); |
||||
|
|
||||
|
|
||||
|
[DllImport("kernel32.dll")] |
||||
|
public static extern IntPtr GetModuleHandle(string lpModuleName); |
||||
|
|
||||
|
[DllImport("user32.dll", SetLastError = true)] |
||||
|
public static extern IntPtr CreateWindowEx( |
||||
|
int dwExStyle, |
||||
|
string lpClassName, |
||||
|
string lpWindowName, |
||||
|
uint dwStyle, |
||||
|
int x, |
||||
|
int y, |
||||
|
int nWidth, |
||||
|
int nHeight, |
||||
|
IntPtr hWndParent, |
||||
|
IntPtr hMenu, |
||||
|
IntPtr hInstance, |
||||
|
IntPtr lpParam); |
||||
|
|
||||
|
[StructLayout(LayoutKind.Sequential)] |
||||
|
public struct SETTEXTEX |
||||
|
{ |
||||
|
public uint Flags; |
||||
|
public uint Codepage; |
||||
|
} |
||||
|
|
||||
|
[DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "SendMessageW")] |
||||
|
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, ref SETTEXTEX wParam, byte[] lParam); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1 @@ |
|||||
|
nodes.mp4 by beeple is licensed under the creative commons license, downloaded from https://vimeo.com/9936271 |
||||
Binary file not shown.
@ -0,0 +1,85 @@ |
|||||
|
namespace Avalonia.Animation.Easings |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Eases a <see cref="double"/> value
|
||||
|
/// using a user-defined cubic bezier curve.
|
||||
|
/// Good for custom easing functions that doesn't quite
|
||||
|
/// fit with the built-in ones.
|
||||
|
/// </summary>
|
||||
|
public class SplineEasing : Easing |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// X coordinate of the first control point
|
||||
|
/// </summary>
|
||||
|
public double X1 |
||||
|
{ |
||||
|
get => _internalKeySpline.ControlPointX1; |
||||
|
set |
||||
|
{ |
||||
|
_internalKeySpline.ControlPointX1 = value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Y coordinate of the first control point
|
||||
|
/// </summary>
|
||||
|
public double Y1 |
||||
|
{ |
||||
|
get => _internalKeySpline.ControlPointY1; |
||||
|
set |
||||
|
{ |
||||
|
_internalKeySpline.ControlPointY1 = value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// X coordinate of the second control point
|
||||
|
/// </summary>
|
||||
|
public double X2 |
||||
|
{ |
||||
|
get => _internalKeySpline.ControlPointX2; |
||||
|
set |
||||
|
{ |
||||
|
_internalKeySpline.ControlPointX2 = value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Y coordinate of the second control point
|
||||
|
/// </summary>
|
||||
|
public double Y2 |
||||
|
{ |
||||
|
get => _internalKeySpline.ControlPointY2; |
||||
|
set |
||||
|
{ |
||||
|
_internalKeySpline.ControlPointY2 = value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private readonly KeySpline _internalKeySpline; |
||||
|
|
||||
|
public SplineEasing(double x1 = 0d, double y1 = 0d, double x2 = 1d, double y2 = 1d) |
||||
|
{ |
||||
|
_internalKeySpline = new KeySpline(); |
||||
|
|
||||
|
this.X1 = x1; |
||||
|
this.Y1 = y1; |
||||
|
this.X2 = x2; |
||||
|
this.Y1 = y2; |
||||
|
} |
||||
|
|
||||
|
public SplineEasing(KeySpline keySpline) |
||||
|
{ |
||||
|
_internalKeySpline = keySpline; |
||||
|
} |
||||
|
|
||||
|
public SplineEasing() |
||||
|
{ |
||||
|
_internalKeySpline = new KeySpline(); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override double Ease(double progress) => |
||||
|
_internalKeySpline.GetSplineProgress(progress); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel; |
||||
|
using System.Globalization; |
||||
|
|
||||
|
// Ported from WPF open-source code.
|
||||
|
// https://github.com/dotnet/wpf/blob/ae1790531c3b993b56eba8b1f0dd395a3ed7de75/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySpline.cs
|
||||
|
|
||||
|
namespace Avalonia.Animation |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Converts string values to <see cref="KeySpline"/> values
|
||||
|
/// </summary>
|
||||
|
public class KeySplineTypeConverter : TypeConverter |
||||
|
{ |
||||
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) |
||||
|
{ |
||||
|
return sourceType == typeof(string); |
||||
|
} |
||||
|
|
||||
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) |
||||
|
{ |
||||
|
return KeySpline.Parse((string)value, culture); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,179 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Diagnostics; |
||||
|
using System.Text; |
||||
|
using Avalonia.Utilities; |
||||
|
|
||||
|
namespace Avalonia.Logging |
||||
|
{ |
||||
|
public class DebugLogSink : ILogSink |
||||
|
{ |
||||
|
private readonly LogEventLevel _level; |
||||
|
private readonly IList<string> _areas; |
||||
|
|
||||
|
public DebugLogSink( |
||||
|
LogEventLevel minimumLevel, |
||||
|
IList<string> areas = null) |
||||
|
{ |
||||
|
_level = minimumLevel; |
||||
|
_areas = areas?.Count > 0 ? areas : null; |
||||
|
} |
||||
|
|
||||
|
public bool IsEnabled(LogEventLevel level, string area) |
||||
|
{ |
||||
|
return level >= _level && (_areas?.Contains(area) ?? true); |
||||
|
} |
||||
|
|
||||
|
public void Log(LogEventLevel level, string area, object source, string messageTemplate) |
||||
|
{ |
||||
|
if (IsEnabled(level, area)) |
||||
|
{ |
||||
|
Debug.WriteLine(Format<object, object, object>(area, messageTemplate, source)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Log<T0>(LogEventLevel level, string area, object source, string messageTemplate, T0 propertyValue0) |
||||
|
{ |
||||
|
if (IsEnabled(level, area)) |
||||
|
{ |
||||
|
Debug.WriteLine(Format<T0, object, object>(area, messageTemplate, source, propertyValue0)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Log<T0, T1>(LogEventLevel level, string area, object source, string messageTemplate, T0 propertyValue0, T1 propertyValue1) |
||||
|
{ |
||||
|
if (IsEnabled(level, area)) |
||||
|
{ |
||||
|
Debug.WriteLine(Format<T0, T1, object>(area, messageTemplate, source, propertyValue0, propertyValue1)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Log<T0, T1, T2>(LogEventLevel level, string area, object source, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) |
||||
|
{ |
||||
|
if (IsEnabled(level, area)) |
||||
|
{ |
||||
|
Debug.WriteLine(Format(area, messageTemplate, source, propertyValue0, propertyValue1, propertyValue2)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Log(LogEventLevel level, string area, object source, string messageTemplate, params object[] propertyValues) |
||||
|
{ |
||||
|
if (IsEnabled(level, area)) |
||||
|
{ |
||||
|
Debug.WriteLine(Format(area, messageTemplate, source, propertyValues)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static string Format<T0, T1, T2>( |
||||
|
string area, |
||||
|
string template, |
||||
|
object source, |
||||
|
T0 v0 = default, |
||||
|
T1 v1 = default, |
||||
|
T2 v2 = default) |
||||
|
{ |
||||
|
var result = new StringBuilder(template.Length); |
||||
|
var r = new CharacterReader(template.AsSpan()); |
||||
|
var i = 0; |
||||
|
|
||||
|
result.Append('['); |
||||
|
result.Append(area); |
||||
|
result.Append("] "); |
||||
|
|
||||
|
while (!r.End) |
||||
|
{ |
||||
|
var c = r.Take(); |
||||
|
|
||||
|
if (c != '{') |
||||
|
{ |
||||
|
result.Append(c); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
if (r.Peek != '{') |
||||
|
{ |
||||
|
result.Append('\''); |
||||
|
result.Append(i++ switch |
||||
|
{ |
||||
|
0 => v0, |
||||
|
1 => v1, |
||||
|
2 => v2, |
||||
|
_ => null |
||||
|
}); |
||||
|
result.Append('\''); |
||||
|
r.TakeUntil('}'); |
||||
|
r.Take(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
result.Append('{'); |
||||
|
r.Take(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (source is object) |
||||
|
{ |
||||
|
result.Append(" ("); |
||||
|
result.Append(source.GetType().Name); |
||||
|
result.Append(" #"); |
||||
|
result.Append(source.GetHashCode()); |
||||
|
result.Append(')'); |
||||
|
} |
||||
|
|
||||
|
return result.ToString(); |
||||
|
} |
||||
|
|
||||
|
private static string Format( |
||||
|
string area, |
||||
|
string template, |
||||
|
object source, |
||||
|
object[] v) |
||||
|
{ |
||||
|
var result = new StringBuilder(template.Length); |
||||
|
var r = new CharacterReader(template.AsSpan()); |
||||
|
var i = 0; |
||||
|
|
||||
|
result.Append('['); |
||||
|
result.Append(area); |
||||
|
result.Append(']'); |
||||
|
|
||||
|
while (!r.End) |
||||
|
{ |
||||
|
var c = r.Take(); |
||||
|
|
||||
|
if (c != '{') |
||||
|
{ |
||||
|
result.Append(c); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
if (r.Peek != '{') |
||||
|
{ |
||||
|
result.Append('\''); |
||||
|
result.Append(i < v.Length ? v[i++] : null); |
||||
|
result.Append('\''); |
||||
|
r.TakeUntil('}'); |
||||
|
r.Take(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
result.Append('{'); |
||||
|
r.Take(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (source is object) |
||||
|
{ |
||||
|
result.Append('('); |
||||
|
result.Append(source.GetType().Name); |
||||
|
result.Append(" #"); |
||||
|
result.Append(source.GetHashCode()); |
||||
|
result.Append(')'); |
||||
|
} |
||||
|
|
||||
|
return result.ToString(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue