Skip to content

Commit

Permalink
Merge pull request #24 from thiagomvas/development
Browse files Browse the repository at this point in the history
1.8 Release
  • Loading branch information
thiagomvas authored Jun 10, 2024
2 parents acf9817 + 4a5b473 commit b688f00
Show file tree
Hide file tree
Showing 19 changed files with 823 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Basalt.Core/Basalt.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>1.7.0</Version>
<Version>1.8.0</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageIcon>BasaltLogoBg.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
2 changes: 1 addition & 1 deletion Basalt.Raylib/Basalt.Raylib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Version>1.7.0</Version>
<Version>1.8.0</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageIcon>BasaltLogoBg.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
42 changes: 14 additions & 28 deletions Basalt.Raylib/Components/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,9 @@ namespace Basalt.Raylib.Components
public class Button : UIComponent
{
/// <summary>
/// Gets or sets the text displayed on the button.
/// Gets the Label displayed on the button.
/// </summary>
public string Text { get; set; }

/// <summary>
/// Gets or sets the font size of the button text.
/// </summary>
public float FontSize { get; set; } = 12f;

/// <summary>
/// Gets or sets the spacing between characters in the button text.
/// </summary>
public float Spacing { get; set; } = 1f;
public Label Label { get; private set; }

/// <summary>
/// Gets or sets the size of the button.
Expand All @@ -47,11 +37,6 @@ public class Button : UIComponent
/// </summary>
public Color OnClickColor { get; set; } = Color.DarkGray;

/// <summary>
/// Gets or sets the color of the button text.
/// </summary>
public Color TextColor { get; set; } = Color.Black;

/// <summary>
/// Gets or sets the action to be performed when the button is clicked.
/// </summary>
Expand All @@ -61,11 +46,19 @@ public class Button : UIComponent
/// Initializes a new instance of the <see cref="Button"/> class.
/// </summary>
/// <param name="entity">The entity that the button belongs to.</param>
public Button(Entity entity) : base(entity)
/// <param name="label">The label containing text data for the button. It cannot be part of another entity or be instantiated.</param>
public Button(Entity entity, Label label) : base(entity)
{
Label = label;
label.Pivot = this.Pivot;
label.Entity = this.Entity;
}


public override void OnStart()
{
Label.Pivot = this.Pivot;
Label.Entity = this.Entity;
}
/// <inheritdoc/>
public override void OnUIRender()
{
Expand All @@ -88,14 +81,7 @@ public override void OnUIRender()
DrawRectanglePro(rect, Size / 2, Rotation, BackgroundColor);
}

DrawTextPro(GetFontDefault(),
Text,
position,
MeasureTextEx(GetFontDefault(), Text, FontSize, Spacing) / 2,
Rotation,
FontSize,
Spacing,
Color.White);
Label.OnUIRender();
}
}
}
}
261 changes: 261 additions & 0 deletions Basalt.Tests/CircularBufferTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
using Basalt.Utility;
using NUnit.Framework;
using System;

namespace Basalt.Tests
{
public class CircularBufferTests
{
[Test]
public void CircularBuffer_Length_ReturnsSize()
{
// Arrange
int size = 5;
var buffer = new CircularBuffer<int>(size);

// Act
int length = buffer.Length;

// Assert
Assert.That(length, Is.EqualTo(size));
}

[Test]
public void CircularBuffer_Indexer_Get_ReturnsValue()
{
// Arrange
var buffer = new CircularBuffer<int>(5);
buffer[0] = 10;
buffer[1] = 20;

// Act
int value1 = buffer[0];
int value2 = buffer[1];

// Assert
Assert.That(value1, Is.EqualTo(10));
Assert.That(value2, Is.EqualTo(20));
}

[Test]
public void CircularBuffer_Indexer_Set_SetsValue()
{
// Arrange
var buffer = new CircularBuffer<int>(5);

// Act
buffer[0] = 10;
buffer[1] = 20;

// Assert
Assert.That(buffer[0], Is.EqualTo(10));
Assert.That(buffer[1], Is.EqualTo(20));
}

[Test]
public void CircularBuffer_Next_ReturnsNextValue()
{
// Arrange
var buffer = new CircularBuffer<int>(3);
buffer[0] = 10;
buffer[1] = 20;
buffer[2] = 30;

// Act
int value1 = buffer.Next();
int value2 = buffer.Next();
int value3 = buffer.Next();

// Assert
Assert.That(value1, Is.EqualTo(10));
Assert.That(value2, Is.EqualTo(20));
Assert.That(value3, Is.EqualTo(30));
}

[Test]
public void CircularBuffer_Next_WrapsAround()
{
// Arrange
var buffer = new CircularBuffer<int>(3);
buffer[0] = 10;
buffer[1] = 20;
buffer[2] = 30;

// Act

// Assert
Assert.That(buffer.Next(), Is.EqualTo(10));
Assert.That(buffer.Next(), Is.EqualTo(20));
Assert.That(buffer.Next(), Is.EqualTo(30));
Assert.That(buffer.Next(), Is.EqualTo(10));
Assert.That(buffer.Next(), Is.EqualTo(20));
Assert.That(buffer.Next(), Is.EqualTo(30));
}

[Test]
public void CircularBuffer_Previous_WrapsAround()
{
// Arrange
var buffer = new CircularBuffer<int>(3);
buffer[0] = 10;
buffer[1] = 20;
buffer[2] = 30;

// Act

// Assert
Assert.That(buffer.Previous(), Is.EqualTo(30));
Assert.That(buffer.Previous(), Is.EqualTo(20));
Assert.That(buffer.Previous(), Is.EqualTo(10));
Assert.That(buffer.Previous(), Is.EqualTo(30));
Assert.That(buffer.Previous(), Is.EqualTo(20));
Assert.That(buffer.Previous(), Is.EqualTo(10));
}

[Test]
public void CircularBuffer_Previous_ReturnsPreviousValue()
{
// Arrange
var buffer = new CircularBuffer<int>(3);
buffer[0] = 10;
buffer[1] = 20;
buffer[2] = 30;

// Act

// Assert
Assert.That(buffer.Previous(), Is.EqualTo(30));
Assert.That(buffer.Previous(), Is.EqualTo(20));
Assert.That(buffer.Previous(), Is.EqualTo(10));
}

[Test]
public void CircularBuffer_Clear_SetsAllValuesToDefault()
{
// Arrange
var buffer = new CircularBuffer<int>(3);
buffer[0] = 10;
buffer[1] = 20;
buffer[2] = 30;

// Act
buffer.Clear();

// Assert
Assert.That(buffer[0], Is.EqualTo(0));
Assert.That(buffer[1], Is.EqualTo(0));
Assert.That(buffer[2], Is.EqualTo(0));
}

[Test]
public void CircularBuffer_FillWithValue_SetsAllValuesToGivenValue()
{
// Arrange
var buffer = new CircularBuffer<int>(3);

// Act
buffer.Fill(10);

// Assert
Assert.That(buffer[0], Is.EqualTo(10));
Assert.That(buffer[1], Is.EqualTo(10));
Assert.That(buffer[2], Is.EqualTo(10));
}

[Test]
public void CircularBuffer_FillWithArray_SetsValuesFromGivenArray()
{
// Arrange
var buffer = new CircularBuffer<int>(4);
int[] values = { 10, 20, 30 };

// Act
buffer.Fill(values);

// Assert
Assert.That(buffer[0], Is.EqualTo(10));
Assert.That(buffer[1], Is.EqualTo(20));
Assert.That(buffer[2], Is.EqualTo(30));
Assert.That(buffer[3], Is.EqualTo(10));
}

[Test]
public void CircularBuffer_FillWithArrayAndOffset_SetsValuesFromGivenArrayWithOffset()
{
// Arrange
var buffer = new CircularBuffer<int>(4);
int[] values = { 10, 20, 30 };

// Act
buffer.Fill(values, 1);

// Assert
Assert.That(buffer[0], Is.EqualTo(20));
Assert.That(buffer[1], Is.EqualTo(30));
Assert.That(buffer[2], Is.EqualTo(10));
Assert.That(buffer[3], Is.EqualTo(20));
}

[Test]
public void CircularBuffer_Constructor_WithBufferArray()
{
// Arrange
int[] values = { 10, 20, 30 };

// Act
var buffer = new CircularBuffer<int>(values);

// Assert
Assert.That(buffer[0], Is.EqualTo(10));
Assert.That(buffer[1], Is.EqualTo(20));
Assert.That(buffer[2], Is.EqualTo(30));
Assert.That(buffer.Next(), Is.EqualTo(10));
Assert.That(buffer.Next(), Is.EqualTo(20));
Assert.That(buffer.Next(), Is.EqualTo(30));
}

[Test]
public void CircularBuffer_Constructor_WithBufferArrayAndIndex()
{
// Arrange
int[] values = { 10, 20, 30 };

// Act
var buffer = new CircularBuffer<int>(values, 1);

// Assert
Assert.That(buffer.Next(), Is.EqualTo(20));
Assert.That(buffer.Next(), Is.EqualTo(30));
Assert.That(buffer.Next(), Is.EqualTo(10));
}

[Test]
public void CircularBuffer_Constructor_WithGeneratorIntT()
{
// Arrange

// Act
var buffer = new CircularBuffer<int>(3, i => i * 2);

// Assert
Assert.That(buffer.Next(), Is.EqualTo(0));
Assert.That(buffer.Next(), Is.EqualTo(2));
Assert.That(buffer.Next(), Is.EqualTo(4));
}

[Test]
public void CircularBuffer_Constructor_WithGeneratorT()
{
// Arrange

// Act
var buffer = new CircularBuffer<int>(3, () => 1);

// Assert
Assert.That(buffer.Next(), Is.EqualTo(1));
Assert.That(buffer.Next(), Is.EqualTo(1));
Assert.That(buffer.Next(), Is.EqualTo(1));
}

}
}
Loading

0 comments on commit b688f00

Please sign in to comment.