Переглянути джерело

Add qdr.qdr.fnd.core.avalonia to qdr.fnd

- initial version
- add Controls/StickyLabel
Dalibor Votruba 2 роки тому
батько
коміт
3b71c5c0e6

+ 10 - 0
qdr.fnd.core.avalonia/Controls/Common/SideOrientationEnum.cs

@@ -0,0 +1,10 @@
+namespace AvaloniaApplication1.Controls.Common
+{
+    public enum SideOrientationEnum
+    {
+        Top,
+        Left,
+        Right,
+        Down
+    }
+}

+ 40 - 0
qdr.fnd.core.avalonia/Controls/StickyLabel.axaml

@@ -0,0 +1,40 @@
+<Styles xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:controls="using:AvaloniaApplication1.Controls">
+  <Design.PreviewWith>
+    <controls:StickyLabel Text = "fooooooooo" 
+                          Background = "White"
+                          BorderBrush ="Black" 
+                          BorderThickness = "1"
+                          Padding ="5"
+                          SideOrientation = "Right"
+                          CornerSize="150"
+                          Foreground="Black"
+                          Width="200"
+                          Height="40"
+                          FontSize="16"
+                          VerticalAlignment = "Center"
+                          />
+  </Design.PreviewWith> 
+
+  <Style Selector="controls|StickyLabel">
+    <!-- Set Defaults -->
+    <Setter Property="Template">
+      <ControlTemplate>
+              <Border x:Name="PART_StickyLabel" 
+                      Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
+                      BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}"
+                      BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"
+                      Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}}" 
+                      Margin="{Binding Margin, RelativeSource={RelativeSource TemplatedParent}}">
+                  
+                  <TextBlock 
+                      VerticalAlignment = "{Binding VerticalAlignment, RelativeSource={RelativeSource TemplatedParent}}"
+                      HorizontalAlignment = "{Binding HorizontalAlignment, RelativeSource={RelativeSource TemplatedParent}}"
+                      Foreground="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
+                      Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" />
+              </Border>
+      </ControlTemplate>
+    </Setter>
+  </Style>
+</Styles>

+ 120 - 0
qdr.fnd.core.avalonia/Controls/StickyLabel.axaml.cs

@@ -0,0 +1,120 @@
+using System;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Metadata;
+using Avalonia.Controls.Primitives;
+using Avalonia.Media;
+using AvaloniaApplication1.Controls.Common;
+
+namespace AvaloniaApplication1.Controls
+{
+    [TemplatePart(CS_NAME_BORDER, typeof(Border))]
+    public class StickyLabel : TemplatedControl
+    {
+        #region *** Private Filelds ***
+        private Border? _border = null;
+        #endregion
+
+        #region *** Properties ***
+        private const string CS_NAME_BORDER = "PART_StickyLabel";
+
+        public static readonly StyledProperty<string> TextProperty =
+            AvaloniaProperty.Register<StickyLabel, string>(
+                nameof(StickyLabel),
+                defaultValue: string.Empty);
+        public string Text
+        {
+            get => GetValue(TextProperty);
+            set => SetValue(TextProperty, value);
+        }
+
+
+        public static readonly StyledProperty<SideOrientationEnum> SideOrientationProperty =
+            AvaloniaProperty.Register<StickyLabel, SideOrientationEnum>(
+                nameof(StickyLabel),
+                defaultValue: SideOrientationEnum.Right);
+        public SideOrientationEnum SideOrientation
+        {
+            get => GetValue(SideOrientationProperty);
+            set => SetOrientation(value, CornerSize);
+        }
+
+        public static readonly StyledProperty<double> CornerSizeProperty =
+            AvaloniaProperty.Register<StickyLabel, double>(
+                nameof(StickyLabel),
+                defaultValue: 10);
+        public double CornerSize
+        {
+            get => GetValue(CornerSizeProperty);
+            set => SetOrientation(SideOrientation, value);
+        }
+
+        public static readonly StyledProperty<BoxShadows> BoxShadowProperty =
+            AvaloniaProperty.Register<StickyLabel, BoxShadows>(
+                nameof(StickyLabel),
+                defaultValue: BoxShadows.Parse("0 0 0 0 DarkGray"));
+        public BoxShadows BoxShadow
+        {
+            get => GetValue(BoxShadowProperty);
+            set => SetBoxShadow(value);
+        }
+        #endregion
+
+        #region *** Constructors ***
+        public StickyLabel()
+        {
+        }
+        #endregion
+
+        #region *** Overriden Methods ***
+
+        protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
+        {
+            _border = e.NameScope.Find<Border>(CS_NAME_BORDER);
+            SetOrientation(SideOrientation, CornerSize);
+        }
+        #endregion
+
+        #region *** Private Methods ***
+        private void SetBoxShadow(BoxShadows boxShadow)
+        { 
+            SetValue(BoxShadowProperty, boxShadow);
+            if (_border == null) return;
+            _border.BoxShadow = boxShadow;
+        }
+
+
+        private void SetOrientation(SideOrientationEnum? sideOrientation, double? cornerSize)
+        {
+
+            if (sideOrientation != null)
+                SetValue(SideOrientationProperty, sideOrientation);
+            else
+                sideOrientation = SideOrientation;
+            if (cornerSize != null)
+                SetValue(CornerSizeProperty, cornerSize);
+            else
+                cornerSize = CornerSize;
+            if (cornerSize == null) throw new ArgumentNullException(nameof(cornerSize));
+
+            if (_border == null) return;
+
+            switch (sideOrientation)
+            {
+                case SideOrientationEnum.Left:
+                    _border.CornerRadius = new CornerRadius(cornerSize.GetValueOrDefault(), 0, 0, cornerSize.GetValueOrDefault());
+                    break;
+                case SideOrientationEnum.Right:
+                    _border.CornerRadius = new CornerRadius(0, cornerSize.GetValueOrDefault(), cornerSize.GetValueOrDefault(), 0);
+                    break;
+                case SideOrientationEnum.Top:
+                    _border.CornerRadius = new CornerRadius(cornerSize.GetValueOrDefault(), cornerSize.GetValueOrDefault(), 0, 0);
+                    break;
+                case SideOrientationEnum.Down:
+                    _border.CornerRadius = new CornerRadius(0, 0, cornerSize.GetValueOrDefault(), cornerSize.GetValueOrDefault());
+                    break;
+            }
+        }
+        #endregion
+    }
+}

+ 29 - 0
qdr.fnd.core.avalonia/bootstrap.cmd

@@ -0,0 +1,29 @@
+@echo off
+echo * Bootstrap started to setup environment
+set nuget=D:\Projects\nuget.exe
+set nugetrepo=D:\Projects\quadarax\@nuget.repo
+
+rem ** check if directories exists **
+if not exist "bin" goto err_bin_not_found
+if not exist "%nuget%" goto err_locnuget_not_found
+if not exist "%nugetrepo%" goto err_locnugetrepo_not_found
+
+
+goto done
+
+:err_bin_not_found
+echo ERR: missing 'bin' directory in current location
+goto exit
+
+:err_locnuget_not_found
+echo ERR: cannot find nuget.exe '%nuget%' or path is invalid.
+goto exit
+
+:err_locnugetrepo_not_found
+echo ERR: cannot find nuget repository '%nugetrepo%' or path is invalid.
+goto exit
+
+
+:done
+echo * Bootstrap succesfuly set
+:exit

+ 15 - 0
qdr.fnd.core.avalonia/buildD.cmd

@@ -0,0 +1,15 @@
+@echo off
+call bootstrap.cmd
+
+rem ** cleanup **
+rmdir /s /q bin\debug
+
+rem ** build **
+dotnet build -c Debug
+
+
+goto done
+
+:done
+echo *** DONE ***
+:exit

+ 15 - 0
qdr.fnd.core.avalonia/buildR.cmd

@@ -0,0 +1,15 @@
+@echo off
+call bootstrap.cmd
+
+rem ** cleanup **
+rmdir /s /q bin\release
+
+rem ** build **
+dotnet build -c Release
+
+
+goto done
+
+:done
+echo *** DONE ***
+:exit

+ 18 - 0
qdr.fnd.core.avalonia/howtouse.md

@@ -0,0 +1,18 @@
+# How to use manual
+
+## Controls
+__App.xaml__
+ensure if following code present inside <Application> node
+
+ <Application.Styles>
+     <FluentTheme />
+     <StyleInclude Source="avares://Quadarax.Foundation.Core.Avalonia/Controls/StickyLabel.axaml" />
+ </Application.Styles>
+ 
+ __SpecificFormOrControl.xaml__
+ ensure if following code presents in <UserControl> or <Window> node
+ 
+  xmlns:qdr-ctrl="clr-namespace:Quadarax.Foundation.Core.Avalonia.Controls" mc:Ignorable="d"
+  
+  
+  then use qdr-ctrl:desired_control

+ 16 - 0
qdr.fnd.core.avalonia/publishD.cmd

@@ -0,0 +1,16 @@
+@echo off
+call bootstrap.cmd
+
+rem ** cleanup **
+rmdir /s /q bin\debug
+
+rem ** build **
+dotnet pack -c Debug 
+
+for %%i in (bin\debug\*.nupkg) do nuget add %%i -source %nugetrepo%
+
+goto done
+
+:done
+echo *** DONE ***
+:exit

+ 16 - 0
qdr.fnd.core.avalonia/publishR.cmd

@@ -0,0 +1,16 @@
+@echo off
+call bootstrap.cmd
+
+rem ** cleanup **
+rmdir /s /q bin\release
+
+rem ** build **
+dotnet pack -c Release
+
+for %%i in (bin\release\*.nupkg) do nuget add %%i -source %nugetrepo%
+
+goto done
+
+:done
+echo *** DONE ***
+:exit

+ 51 - 0
qdr.fnd.core.avalonia/qdr.fnd.core.avalonia.csproj

@@ -0,0 +1,51 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net7.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+	<SignAssembly>true</SignAssembly>
+    <AssemblyOriginatorKeyFile>..\bo_strong_key_pair.snk</AssemblyOriginatorKeyFile>
+    <DelaySign>false</DelaySign>
+    <RootNamespace>Quadarax.Foundation.Core.Avalonia</RootNamespace>
+	<ApplicationIcon>..\quadarax_dll.ico</ApplicationIcon>
+    <Title>Quadarax.Foundation.Core.Avalonia</Title>
+    <Authors>Dalibor Votruba</Authors>
+    <Company>Quadarax</Company>
+    <Product>Quadarax.Foundation</Product>
+    <Description>Core library with extension for Avalonia UI (controls, styles, base patterns)</Description>
+    <Copyright>Copyright © 2023 Quadarax</Copyright>
+    <PackageIcon>quadarax_dll.png</PackageIcon>
+    <PackageTags>QDR;FND;CORE;AVALONIA</PackageTags>
+    <AssemblyVersion>0.0.1.0</AssemblyVersion>
+    <FileVersion>0.0.1.0</FileVersion>
+    <Version>0.0.1.0-alpha</Version>
+    <PackageReleaseNotes>Date:28.10.2023
+      - initial version
+	  - add Controls/StickyLabel</PackageReleaseNotes>
+    <PackageReadmeFile>releasenotes.md</PackageReadmeFile>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <None Include="..\quadarax_dll.png">
+      <Pack>True</Pack>
+      <PackagePath>\</PackagePath>
+    </None>
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Avalonia" Version="11.0.5" />
+    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.5" />
+    <PackageReference Include="Avalonia.ReactiveUI" Version="11.0.5" />
+    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.5" />
+    <PackageReference Include="qdr.fnd.core" Version="0.0.2-alpha" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <None Update="releasenotes.md">
+      <Pack>True</Pack>
+      <PackagePath>\</PackagePath>
+    </None>
+  </ItemGroup>
+
+</Project>

+ 9 - 0
qdr.fnd.core.avalonia/releasenotes.md

@@ -0,0 +1,9 @@
+# Quadarax.Foundation.Core.Avalonia * Release notes
+Ordered by version descending
+
+## 0.0.1.0
+Date:__28.10.2023__
+- initial version
+- add Controls/StickyLabel
+---
+---

+ 7 - 1
qdr.fnd.sln

@@ -17,10 +17,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "qdr.fnd.core.qconsole", "qd
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "qdr.fnd.core.web", "qdr.fnd.core.web\qdr.fnd.core.web.csproj", "{E409FF71-FAC0-492A-9C9C-2DCCB52055D9}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "qdr.fnd.core.test", "qdr.fnd.core.test\qdr.fnd.core.test.csproj", "{B172BF70-17B7-4B8D-8649-EF79254182AB}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "qdr.fnd.core.test", "qdr.fnd.core.test\qdr.fnd.core.test.csproj", "{B172BF70-17B7-4B8D-8649-EF79254182AB}"
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{62EEC894-61DC-4D39-83F6-28FF82F6E758}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "qdr.fnd.core.avalonia", "qdr.fnd.core.avalonia\qdr.fnd.core.avalonia.csproj", "{FAFED9DA-5D56-4B77-A107-6929A79B1A75}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -59,6 +61,10 @@ Global
 		{B172BF70-17B7-4B8D-8649-EF79254182AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{B172BF70-17B7-4B8D-8649-EF79254182AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{B172BF70-17B7-4B8D-8649-EF79254182AB}.Release|Any CPU.Build.0 = Release|Any CPU
+		{FAFED9DA-5D56-4B77-A107-6929A79B1A75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{FAFED9DA-5D56-4B77-A107-6929A79B1A75}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{FAFED9DA-5D56-4B77-A107-6929A79B1A75}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{FAFED9DA-5D56-4B77-A107-6929A79B1A75}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE