Преглед на файлове

Created PageStack Control and miscellaneous converters
Added SelectedIndex to ButtonStrip

Frank van den Bos преди 2 седмици
родител
ревизия
75de373bf4

+ 2 - 0
InABox.Avalonia.Platform.iOS/InABox.Avalonia.Platform.iOS.csproj

@@ -5,6 +5,8 @@
         <ImplicitUsings>enable</ImplicitUsings>
         <Nullable>enable</Nullable>
         <RootNamespace>InABox.Avalonia.Platform.iOS</RootNamespace>
+        <Configurations>Debug;Release;Publish</Configurations>
+        <Platforms>AnyCPU</Platforms>
     </PropertyGroup>
 
     <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

+ 2 - 0
InABox.Avalonia.Platform/InABox.Avalonia.Platform.csproj

@@ -5,6 +5,8 @@
         <ImplicitUsings>enable</ImplicitUsings>
         <Nullable>enable</Nullable>
         <RootNamespace>InABox.Avalonia.Platform</RootNamespace>
+        <Configurations>Debug;Release;Publish</Configurations>
+        <Platforms>AnyCPU</Platforms>
     </PropertyGroup>
 
     <ItemGroup>

+ 22 - 8
InABox.Avalonia/Components/ButtonStrip/ButtonStrip.cs

@@ -21,19 +21,27 @@ namespace InABox.Avalonia.Components;
 
 public partial class ButtonStrip : TemplatedControl
 {
-    public static StyledProperty<IBrush?> SelectedBackgroundProperty = AvaloniaProperty.Register<ButtonStripItem, IBrush?>(
+    public static readonly StyledProperty<IBrush?> SelectedBackgroundProperty = AvaloniaProperty.Register<ButtonStripItem, IBrush?>(
         nameof(SelectedBackground));
-    public static StyledProperty<IBrush?> SelectedForegroundProperty = AvaloniaProperty.Register<ButtonStripItem, IBrush?>(
+    
+    public static readonly StyledProperty<IBrush?> SelectedForegroundProperty = AvaloniaProperty.Register<ButtonStripItem, IBrush?>(
         nameof(SelectedForeground));
-    public static StyledProperty<double> ItemSpacingProperty = AvaloniaProperty.Register<ButtonStripItem, double>(
+    
+    public static readonly StyledProperty<double> ItemSpacingProperty = AvaloniaProperty.Register<ButtonStripItem, double>(
         nameof(ItemSpacing));
-    public static StyledProperty<ObservableCollection<ButtonStripItem>> ItemsProperty =
+   
+    public static readonly StyledProperty<ObservableCollection<ButtonStripItem>> ItemsProperty =
         AvaloniaProperty.Register<ButtonStripItem, ObservableCollection<ButtonStripItem>>(nameof(Items));
-    public static StyledProperty<IEnumerable?> ItemsSourceProperty =
+    
+    public static readonly StyledProperty<IEnumerable?> ItemsSourceProperty =
         AvaloniaProperty.Register<ButtonStripItem, IEnumerable?>(nameof(ItemsSource));
-    public static StyledProperty<ICommand> SelectedCommandProperty = AvaloniaProperty.Register<ButtonStrip, ICommand>(nameof(SelectedCommand));
-    public static StyledProperty<object?> SelectedItemProperty = AvaloniaProperty.Register<ButtonStrip, object?>(nameof(SelectedItem));
-
+    
+    public static readonly StyledProperty<ICommand> SelectedCommandProperty = 
+        AvaloniaProperty.Register<ButtonStrip, ICommand>(nameof(SelectedCommand));
+    
+    public static readonly StyledProperty<object?> SelectedItemProperty = 
+        AvaloniaProperty.Register<ButtonStrip, object?>(nameof(SelectedItem));
+    
     public IBrush? SelectedBackground
     {
         get => GetValue(SelectedBackgroundProperty);
@@ -87,6 +95,12 @@ public partial class ButtonStrip : TemplatedControl
         set => SetValue(SelectedItemProperty, value);
     }
 
+    public int SelectedIndex
+    {
+        get => SelectedButton != null ? Items.IndexOf(SelectedButton) : -1;
+        set => SelectedButton = Items[value];
+    }
+
     public event EventHandler? SelectionChanged;
 
     static ButtonStrip()

+ 83 - 0
InABox.Avalonia/Components/PageStack/PageStack.cs

@@ -0,0 +1,83 @@
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Metadata;
+using Avalonia.Threading;
+
+namespace InABox.Avalonia.Components;
+
+public class PageStack : ContentControl
+{
+    
+    private static readonly StyledProperty<PageStackItem?> SelectedItemProperty = 
+        AvaloniaProperty.Register<PageStack,PageStackItem?>(nameof(SelectedItem));
+    
+    private static readonly StyledProperty<int> SelectedIndexProperty = 
+        AvaloniaProperty.Register<PageStack, int>(nameof(SelectedIndex), -1);
+    
+    static PageStack()
+    {
+        
+        SelectedIndexProperty.Changed.AddClassHandler<PageStack>((stack,args) =>
+            stack?.SelectPage((int)(args.NewValue ?? -1)));
+        
+        SelectedItemProperty.Changed.AddClassHandler<PageStack>((stack,args) =>
+            stack?.SelectPage(args.NewValue as PageStackItem));
+    }
+    
+    public PageStack()
+    {
+        var items = new ObservableCollection<PageStackItem>();
+        items.CollectionChanged += ItemsChanged;
+        Items = items;
+    }
+    
+    [Content]
+    public IList<PageStackItem> Items { get; private set; }
+    
+    public void SelectPage(int page)
+    {
+        SelectPage((page > -1) && (page < Items.Count) ? Items[page] : null);
+    }
+
+    private PageStackItem? _current;
+    public void SelectPage(PageStackItem? page)
+    {
+        if (_current != null)
+            _current.DoDisappearing();
+        _current = page;
+        Content = _current?.Content;
+        _current?.DoAppearing();
+        SelectionChanged?.Invoke(this, EventArgs.Empty);
+    }
+    
+    public int SelectedIndex
+    {
+        get => GetValue(SelectedIndexProperty);
+        set => SetValue(SelectedIndexProperty, value);
+    }
+    
+    public PageStackItem? SelectedItem 
+    {
+        get => GetValue(SelectedItemProperty);
+        set => SetValue(SelectedItemProperty, value);
+    }
+    
+    public event EventHandler SelectionChanged;
+
+    public void DoSelectionChanged()
+    {
+        SelectionChanged?.Invoke(this, EventArgs.Empty);
+    }
+    
+    private void ItemsChanged(object? sender, NotifyCollectionChangedEventArgs? e)
+    {
+        Dispatcher.UIThread.Post(() =>
+        {
+            SelectedItem ??= Items.FirstOrDefault();
+        });
+    }
+    
+}

+ 24 - 0
InABox.Avalonia/Components/PageStack/PageStackItem.cs

@@ -0,0 +1,24 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Metadata;
+
+namespace InABox.Avalonia.Components;
+
+public class PageStackItem : AvaloniaObject
+{
+    private static readonly StyledProperty<Control> ContentProperty = 
+        AvaloniaProperty.Register<PageStackItem, Control>(nameof(Content));
+    
+    [Content]
+    public Control Content 
+    { 
+        get => GetValue(ContentProperty); 
+        set => SetValue(ContentProperty, value); 
+    }
+        
+    public event EventHandler? Appearing;
+    public void DoAppearing() => Appearing?.Invoke(this, EventArgs.Empty);
+        
+    public event EventHandler? Disappearing;
+    public void DoDisappearing() => Disappearing?.Invoke(this, EventArgs.Empty);
+}

+ 13 - 0
InABox.Avalonia/Converters/BooleanToBooleanConverter.cs

@@ -0,0 +1,13 @@
+namespace InABox.Avalonia.Converters
+{
+    public class BooleanToBooleanConverter: AbstractConverter<bool,bool>
+    {
+        
+        public bool Invert { get; set; }
+
+        protected override bool Convert(bool value, object? parameter = null)
+        {
+            return Invert ? !value : value; 
+        }
+    }
+}

+ 23 - 0
InABox.Avalonia/Converters/BooleanToGridLengthConverter.cs

@@ -0,0 +1,23 @@
+using System.Globalization;
+using Avalonia.Controls;
+
+namespace InABox.Avalonia.Converters
+{
+    public class BooleanToGridLengthConverter : AbstractConverter<bool,GridLength>
+    {
+        public GridLength TrueValue { get; set; }
+        public GridLength FalseValue { get; set; }
+
+        protected override GridLength Convert(bool value, object parameter = null)
+        {
+            return value ? TrueValue : FalseValue;
+        }
+
+        public BooleanToGridLengthConverter()
+        {
+            TrueValue = GridLength.Star;
+            FalseValue = new GridLength(0);
+        }
+        
+    }
+}

+ 20 - 0
InABox.Avalonia/Converters/BooleanToIntegerConverter.cs

@@ -0,0 +1,20 @@
+namespace InABox.Avalonia.Converters
+{
+    public class BoolToIntegerConverter : AbstractConverter<bool,int>
+    {
+        public int TrueValue { get; set; }
+        public int FalseValue { get; set; }
+
+        protected override int Convert(bool value, object parameter = null)
+        {
+            return value ? TrueValue : FalseValue;
+        }
+
+        public BoolToIntegerConverter()
+        {
+            TrueValue = 1;
+            FalseValue = 0;
+        }
+        
+    }
+}

+ 4 - 1
InABox.Avalonia/InABox.Avalonia.csproj

@@ -6,7 +6,8 @@
         <Nullable>enable</Nullable>
         <RootNamespace>InABox.Avalonia</RootNamespace>
         <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
-        <Configurations>Debug;Release</Configurations>
+        <Configurations>Debug;Release;Publish</Configurations>
+        <Platforms>AnyCPU</Platforms>
     </PropertyGroup>
 
     <ItemGroup>
@@ -26,6 +27,8 @@
       <PackageReference Include="Avalonia" Version="11.2.2" />
       <PackageReference Include="Avalonia.Controls.ColorPicker" Version="11.2.2" />
       <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.2.2" />
+      <PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.2" />
+      <PackageReference Include="Avalonia.Skia" Version="11.2.2" />
       <PackageReference Include="Avalonia.Svg.Skia" Version="11.2.0.2" />
       <PackageReference Include="AvaloniaDialogs" Version="3.6.1" />
       <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />

+ 2 - 1
InABox.Client.RPC/InABox.Client.RPC.csproj

@@ -4,6 +4,8 @@
         <OutputType>Library</OutputType>
         <Nullable>enable</Nullable>
         <TargetFrameworks>netstandard2.1;net8.0</TargetFrameworks>
+        <Configurations>Debug;Release;Publish</Configurations>
+        <Platforms>AnyCPU</Platforms>
     </PropertyGroup>
 
     <ItemGroup>
@@ -13,7 +15,6 @@
 
     <ItemGroup>
       <PackageReference Include="H.Formatters" Version="15.0.0" />
-      <PackageReference Include="H.Formatters.MessagePack" Version="15.0.0" />
       <PackageReference Include="H.Pipes" Version="15.0.0" />
       <PackageReference Include="WebSocket4Net" Version="0.15.2" />
     </ItemGroup>

+ 2 - 0
InABox.Core/InABox.Core.csproj

@@ -4,6 +4,8 @@
         <OutputType>Library</OutputType>
 		<Nullable>enable</Nullable>
         <TargetFramework>netstandard2.1</TargetFramework>
+        <Configurations>Debug;Release;Publish</Configurations>
+        <Platforms>AnyCPU</Platforms>
 	</PropertyGroup>
 
 	<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

+ 2 - 0
InABox.Integration/InABox.Integration.csproj

@@ -3,6 +3,8 @@
     <PropertyGroup>
         <OutputType>Library</OutputType>
         <TargetFramework>netstandard2.0</TargetFramework>
+        <Configurations>Debug;Release;Publish</Configurations>
+        <Platforms>AnyCPU</Platforms>
     </PropertyGroup>
 
 </Project>

+ 2 - 4
InABox.RPC.Shared/InABox.RPC.Shared.csproj

@@ -4,12 +4,10 @@
         <OutputType>Library</OutputType>
         <Nullable>enable</Nullable>
         <TargetFrameworks>netstandard2.1;net8.0</TargetFrameworks>
+        <Configurations>Debug;Release;Publish</Configurations>
+        <Platforms>AnyCPU</Platforms>
     </PropertyGroup>
 
-    <ItemGroup>
-      <PackageReference Include="MessagePack.Annotations" Version="2.5.192" />
-    </ItemGroup>
-
     <ItemGroup>
       <ProjectReference Include="..\InABox.Core\InABox.Core.csproj" />
       <ProjectReference Include="..\InABox.Formatters.Core\InABox.Formatters.Core.csproj" />

+ 0 - 1
InABox.RPC.Shared/RPCMessage.cs

@@ -1,7 +1,6 @@
 using System;
 using System.IO;
 using InABox.Core;
-using MessagePack;
 
 namespace InABox.Rpc
 {

+ 2 - 0
inabox.logging.shared/InABox.Logging.Shared.csproj

@@ -4,6 +4,8 @@
         <OutputType>Library</OutputType>
         <Nullable>enable</Nullable>
         <TargetFramework>netstandard2.1</TargetFramework>
+        <Configurations>Debug;Release;Publish</Configurations>
+        <Platforms>AnyCPU</Platforms>
     </PropertyGroup>
 
     <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">