Browse Source

feat(ControlCatalog): Address rule CA1822

Giuseppe Lippolis 3 years ago
parent
commit
8724514a73

+ 4 - 4
samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml.cs

@@ -32,7 +32,7 @@ namespace ControlCatalog.Pages
             }
             }
         }
         }
 
 
-        private StateData[] BuildAllStates()
+        private static StateData[] BuildAllStates()
         {
         {
             return new StateData[]
             return new StateData[]
             {
             {
@@ -90,7 +90,7 @@ namespace ControlCatalog.Pages
         }
         }
         public StateData[] States { get; private set; }
         public StateData[] States { get; private set; }
         
         
-        private LinkedList<string>[] BuildAllSentences()
+        private static LinkedList<string>[] BuildAllSentences()
         {
         {
             return new string[]
             return new string[]
             {
             {
@@ -108,8 +108,8 @@ namespace ControlCatalog.Pages
         {
         {
             this.InitializeComponent();
             this.InitializeComponent();
 
 
-            States = BuildAllStates();
-            Sentences = BuildAllSentences();
+            States = AutoCompleteBoxPage.BuildAllStates();
+            Sentences = AutoCompleteBoxPage.BuildAllSentences();
 
 
             foreach (AutoCompleteBox box in GetAllAutoCompleteBox().Where(x => x.Name != "CustomAutocompleteBox"))
             foreach (AutoCompleteBox box in GetAllAutoCompleteBox().Where(x => x.Name != "CustomAutocompleteBox"))
             {
             {

+ 2 - 2
samples/ControlCatalog/Pages/CompositionPage.axaml.cs

@@ -22,10 +22,10 @@ public partial class CompositionPage : UserControl
     protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
     protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
     {
     {
         base.OnAttachedToVisualTree(e);
         base.OnAttachedToVisualTree(e);
-        this.Get<ItemsControl>("Items").Items = CreateColorItems();
+        this.Get<ItemsControl>("Items").Items = CompositionPage.CreateColorItems();
     }
     }
 
 
-    private List<CompositionPageColorItem> CreateColorItems()
+    private static List<CompositionPageColorItem> CreateColorItems()
     {
     {
         var list = new List<CompositionPageColorItem>();
         var list = new List<CompositionPageColorItem>();
 
 

+ 2 - 2
samples/ControlCatalog/Pages/ImagePage.xaml.cs

@@ -52,13 +52,13 @@ namespace ControlCatalog.Pages
                 var comboxBox = (ComboBox)sender;
                 var comboxBox = (ComboBox)sender;
                 if (_croppedImage.Source is CroppedBitmap croppedBitmap)
                 if (_croppedImage.Source is CroppedBitmap croppedBitmap)
                 {
                 {
-                    croppedBitmap.SourceRect = GetCropRect(comboxBox.SelectedIndex);
+                    croppedBitmap.SourceRect = ImagePage.GetCropRect(comboxBox.SelectedIndex);
                 }
                 }
                 
                 
             }
             }
         }
         }
 
 
-        private PixelRect GetCropRect(int index)
+        private static PixelRect GetCropRect(int index)
         {
         {
             var bitmapWidth = 640;
             var bitmapWidth = 640;
             var bitmapHeight = 426;
             var bitmapHeight = 426;

+ 11 - 11
samples/ControlCatalog/Pages/OpenGlPage.xaml.cs

@@ -247,7 +247,7 @@ namespace ControlCatalog.Pages
 
 
         }
         }
 
 
-        private void CheckError(GlInterface gl)
+        private static void CheckError(GlInterface gl)
         {
         {
             int err;
             int err;
             while ((err = gl.GetError()) != GL_NO_ERROR)
             while ((err = gl.GetError()) != GL_NO_ERROR)
@@ -256,7 +256,7 @@ namespace ControlCatalog.Pages
 
 
         protected unsafe override void OnOpenGlInit(GlInterface GL, int fb)
         protected unsafe override void OnOpenGlInit(GlInterface GL, int fb)
         {
         {
-            CheckError(GL);
+            OpenGlPageControl.CheckError(GL);
 
 
             Info = $"Renderer: {GL.GetString(GL_RENDERER)} Version: {GL.GetString(GL_VERSION)}";
             Info = $"Renderer: {GL.GetString(GL_RENDERER)} Version: {GL.GetString(GL_VERSION)}";
             
             
@@ -277,13 +277,13 @@ namespace ControlCatalog.Pages
             GL.BindAttribLocationString(_shaderProgram, positionLocation, "aPos");
             GL.BindAttribLocationString(_shaderProgram, positionLocation, "aPos");
             GL.BindAttribLocationString(_shaderProgram, normalLocation, "aNormal");
             GL.BindAttribLocationString(_shaderProgram, normalLocation, "aNormal");
             Console.WriteLine(GL.LinkProgramAndGetError(_shaderProgram));
             Console.WriteLine(GL.LinkProgramAndGetError(_shaderProgram));
-            CheckError(GL);
+            OpenGlPageControl.CheckError(GL);
 
 
             // Create the vertex buffer object (VBO) for the vertex data.
             // Create the vertex buffer object (VBO) for the vertex data.
             _vertexBufferObject = GL.GenBuffer();
             _vertexBufferObject = GL.GenBuffer();
             // Bind the VBO and copy the vertex data into it.
             // Bind the VBO and copy the vertex data into it.
             GL.BindBuffer(GL_ARRAY_BUFFER, _vertexBufferObject);
             GL.BindBuffer(GL_ARRAY_BUFFER, _vertexBufferObject);
-            CheckError(GL);
+            OpenGlPageControl.CheckError(GL);
             var vertexSize = Marshal.SizeOf<Vertex>();
             var vertexSize = Marshal.SizeOf<Vertex>();
             fixed (void* pdata = _points)
             fixed (void* pdata = _points)
                 GL.BufferData(GL_ARRAY_BUFFER, new IntPtr(_points.Length * vertexSize),
                 GL.BufferData(GL_ARRAY_BUFFER, new IntPtr(_points.Length * vertexSize),
@@ -291,21 +291,21 @@ namespace ControlCatalog.Pages
 
 
             _indexBufferObject = GL.GenBuffer();
             _indexBufferObject = GL.GenBuffer();
             GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferObject);
             GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferObject);
-            CheckError(GL);
+            OpenGlPageControl.CheckError(GL);
             fixed (void* pdata = _indices)
             fixed (void* pdata = _indices)
                 GL.BufferData(GL_ELEMENT_ARRAY_BUFFER, new IntPtr(_indices.Length * sizeof(ushort)), new IntPtr(pdata),
                 GL.BufferData(GL_ELEMENT_ARRAY_BUFFER, new IntPtr(_indices.Length * sizeof(ushort)), new IntPtr(pdata),
                     GL_STATIC_DRAW);
                     GL_STATIC_DRAW);
-            CheckError(GL);
+            OpenGlPageControl.CheckError(GL);
             _vertexArrayObject = GL.GenVertexArray();
             _vertexArrayObject = GL.GenVertexArray();
             GL.BindVertexArray(_vertexArrayObject);
             GL.BindVertexArray(_vertexArrayObject);
-            CheckError(GL);
+            OpenGlPageControl.CheckError(GL);
             GL.VertexAttribPointer(positionLocation, 3, GL_FLOAT,
             GL.VertexAttribPointer(positionLocation, 3, GL_FLOAT,
                 0, vertexSize, IntPtr.Zero);
                 0, vertexSize, IntPtr.Zero);
             GL.VertexAttribPointer(normalLocation, 3, GL_FLOAT,
             GL.VertexAttribPointer(normalLocation, 3, GL_FLOAT,
                 0, vertexSize, new IntPtr(12));
                 0, vertexSize, new IntPtr(12));
             GL.EnableVertexAttribArray(positionLocation);
             GL.EnableVertexAttribArray(positionLocation);
             GL.EnableVertexAttribArray(normalLocation);
             GL.EnableVertexAttribArray(normalLocation);
-            CheckError(GL);
+            OpenGlPageControl.CheckError(GL);
 
 
         }
         }
 
 
@@ -339,7 +339,7 @@ namespace ControlCatalog.Pages
             GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferObject);
             GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferObject);
             GL.BindVertexArray(_vertexArrayObject);
             GL.BindVertexArray(_vertexArrayObject);
             GL.UseProgram(_shaderProgram);
             GL.UseProgram(_shaderProgram);
-            CheckError(GL);
+            OpenGlPageControl.CheckError(GL);
             var projection =
             var projection =
                 Matrix4x4.CreatePerspectiveFieldOfView((float)(Math.PI / 4), (float)(Bounds.Width / Bounds.Height),
                 Matrix4x4.CreatePerspectiveFieldOfView((float)(Math.PI / 4), (float)(Bounds.Width / Bounds.Height),
                     0.01f, 1000);
                     0.01f, 1000);
@@ -361,10 +361,10 @@ namespace ControlCatalog.Pages
             GL.Uniform1f(minYLoc, _minY);
             GL.Uniform1f(minYLoc, _minY);
             GL.Uniform1f(timeLoc, (float)St.Elapsed.TotalSeconds);
             GL.Uniform1f(timeLoc, (float)St.Elapsed.TotalSeconds);
             GL.Uniform1f(discoLoc, _disco);
             GL.Uniform1f(discoLoc, _disco);
-            CheckError(GL);
+            OpenGlPageControl.CheckError(GL);
             GL.DrawElements(GL_TRIANGLES, _indices.Length, GL_UNSIGNED_SHORT, IntPtr.Zero);
             GL.DrawElements(GL_TRIANGLES, _indices.Length, GL_UNSIGNED_SHORT, IntPtr.Zero);
 
 
-            CheckError(GL);
+            OpenGlPageControl.CheckError(GL);
             if (_disco > 0.01)
             if (_disco > 0.01)
                 Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Background);
                 Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Background);
         }
         }

+ 6 - 6
samples/ControlCatalog/Pages/ScreenPage.cs

@@ -55,21 +55,21 @@ namespace ControlCatalog.Pages
                     context.DrawRectangle(p, workingAreaRect);
                     context.DrawRectangle(p, workingAreaRect);
 
 
 
 
-                    var formattedText = CreateFormattedText($"Bounds: {screen.Bounds.Width}:{screen.Bounds.Height}");
+                    var formattedText = ScreenPage.CreateFormattedText($"Bounds: {screen.Bounds.Width}:{screen.Bounds.Height}");
                     context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height));
                     context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height));
 
 
                     formattedText =
                     formattedText =
-                        CreateFormattedText($"WorkArea: {screen.WorkingArea.Width}:{screen.WorkingArea.Height}");
+                        ScreenPage.CreateFormattedText($"WorkArea: {screen.WorkingArea.Width}:{screen.WorkingArea.Height}");
                     context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 20));
                     context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 20));
 
 
-                    formattedText = CreateFormattedText($"Scaling: {screen.PixelDensity * 100}%");
+                    formattedText = ScreenPage.CreateFormattedText($"Scaling: {screen.PixelDensity * 100}%");
                     context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 40));
                     context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 40));
 
 
-                    formattedText = CreateFormattedText($"Primary: {screen.Primary}");
+                    formattedText = ScreenPage.CreateFormattedText($"Primary: {screen.Primary}");
                     context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 60));
                     context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 60));
 
 
                     formattedText =
                     formattedText =
-                        CreateFormattedText(
+                        ScreenPage.CreateFormattedText(
                             $"Current: {screen.Equals(w.Screens.ScreenFromBounds(new PixelRect(w.Position, PixelSize.FromSize(w.Bounds.Size, scaling))))}");
                             $"Current: {screen.Equals(w.Screens.ScreenFromBounds(new PixelRect(w.Position, PixelSize.FromSize(w.Bounds.Size, scaling))))}");
                     context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 80));
                     context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 80));
                 }
                 }
@@ -77,7 +77,7 @@ namespace ControlCatalog.Pages
             context.DrawRectangle(p, new Rect(w.Position.X / 10f + Math.Abs(_leftMost), w.Position.Y / 10f, w.Bounds.Width / 10, w.Bounds.Height / 10));
             context.DrawRectangle(p, new Rect(w.Position.X / 10f + Math.Abs(_leftMost), w.Position.Y / 10f, w.Bounds.Width / 10, w.Bounds.Height / 10));
         }
         }
 
 
-        private FormattedText CreateFormattedText(string textToFormat)
+        private static FormattedText CreateFormattedText(string textToFormat)
         {
         {
             return new FormattedText(textToFormat, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
             return new FormattedText(textToFormat, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                 Typeface.Default, 12, Brushes.Green);
                 Typeface.Default, 12, Brushes.Green);

+ 8 - 8
samples/ControlCatalog/Pages/TabControlPage.xaml.cs

@@ -14,6 +14,12 @@ namespace ControlCatalog.Pages
 
 
     public class TabControlPage : UserControl
     public class TabControlPage : UserControl
     {
     {
+        private static IBitmap LoadBitmap(string uri)
+        {
+            var assets = AvaloniaLocator.Current!.GetService<IAssetLoader>()!;
+            return new Bitmap(assets.Open(new Uri(uri)));
+        }
+
         public TabControlPage()
         public TabControlPage()
         {
         {
             InitializeComponent();
             InitializeComponent();
@@ -26,13 +32,13 @@ namespace ControlCatalog.Pages
                     {
                     {
                         Header = "Arch",
                         Header = "Arch",
                         Text = "This is the first templated tab page.",
                         Text = "This is the first templated tab page.",
-                        Image = LoadBitmap("avares://ControlCatalog/Assets/delicate-arch-896885_640.jpg"),
+                        Image = TabControlPage.LoadBitmap("avares://ControlCatalog/Assets/delicate-arch-896885_640.jpg"),
                     },
                     },
                     new TabItemViewModel
                     new TabItemViewModel
                     {
                     {
                         Header = "Leaf",
                         Header = "Leaf",
                         Text = "This is the second templated tab page.",
                         Text = "This is the second templated tab page.",
-                        Image = LoadBitmap("avares://ControlCatalog/Assets/maple-leaf-888807_640.jpg"),
+                        Image = TabControlPage.LoadBitmap("avares://ControlCatalog/Assets/maple-leaf-888807_640.jpg"),
                     },
                     },
                     new TabItemViewModel
                     new TabItemViewModel
                     {
                     {
@@ -50,12 +56,6 @@ namespace ControlCatalog.Pages
             AvaloniaXamlLoader.Load(this);
             AvaloniaXamlLoader.Load(this);
         }
         }
 
 
-        private IBitmap LoadBitmap(string uri)
-        {
-            var assets = AvaloniaLocator.Current!.GetService<IAssetLoader>()!;
-            return new Bitmap(assets.Open(new Uri(uri)));
-        }
-
         private class PageViewModel : ViewModelBase
         private class PageViewModel : ViewModelBase
         {
         {
             private Dock _tabPlacement;
             private Dock _tabPlacement;