Browse Source

feat(ControlCatalog): Address rule CA1822

pull/9189/head
Giuseppe Lippolis 4 years ago
parent
commit
8724514a73
  1. 8
      samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml.cs
  2. 4
      samples/ControlCatalog/Pages/CompositionPage.axaml.cs
  3. 4
      samples/ControlCatalog/Pages/ImagePage.xaml.cs
  4. 22
      samples/ControlCatalog/Pages/OpenGlPage.xaml.cs
  5. 12
      samples/ControlCatalog/Pages/ScreenPage.cs
  6. 16
      samples/ControlCatalog/Pages/TabControlPage.xaml.cs

8
samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml.cs

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

4
samples/ControlCatalog/Pages/CompositionPage.axaml.cs

@ -22,10 +22,10 @@ public partial class CompositionPage : UserControl
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs 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>();

4
samples/ControlCatalog/Pages/ImagePage.xaml.cs

@ -52,13 +52,13 @@ namespace ControlCatalog.Pages
var comboxBox = (ComboBox)sender;
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 bitmapHeight = 426;

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

12
samples/ControlCatalog/Pages/ScreenPage.cs

@ -55,21 +55,21 @@ namespace ControlCatalog.Pages
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));
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));
formattedText = CreateFormattedText($"Scaling: {screen.PixelDensity * 100}%");
formattedText = ScreenPage.CreateFormattedText($"Scaling: {screen.PixelDensity * 100}%");
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));
formattedText =
CreateFormattedText(
ScreenPage.CreateFormattedText(
$"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));
}
@ -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));
}
private FormattedText CreateFormattedText(string textToFormat)
private static FormattedText CreateFormattedText(string textToFormat)
{
return new FormattedText(textToFormat, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
Typeface.Default, 12, Brushes.Green);

16
samples/ControlCatalog/Pages/TabControlPage.xaml.cs

@ -14,6 +14,12 @@ namespace ControlCatalog.Pages
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()
{
InitializeComponent();
@ -26,13 +32,13 @@ namespace ControlCatalog.Pages
{
Header = "Arch",
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
{
Header = "Leaf",
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
{
@ -50,12 +56,6 @@ namespace ControlCatalog.Pages
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 Dock _tabPlacement;

Loading…
Cancel
Save