Skip to content

Commit

Permalink
Add panel
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagomvas committed May 24, 2024
1 parent 59095ba commit 28fd0b6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 0 additions & 2 deletions Basalt.Raylib/Components/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class Label : UIComponent
public string Text { get; set; } = string.Empty;
public float FontSize { get; set; } = 20;
public float Spacing { get; set; } = 1;
public float Rotation { get; set; } = 0;
public Label(Entity entity) : base(entity)
{
}
Expand All @@ -36,7 +35,6 @@ public override void OnUIRender()
FontSize,
Spacing,
Raylib_cs.Color.White);
Engine.Instance.Logger?.LogDebug($"Drawing label at {position}");
}
}
}
30 changes: 30 additions & 0 deletions Basalt.Raylib/Components/Panel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Basalt.Common.Components;
using Basalt.Common.Entities;
using Raylib_cs;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Basalt.Raylib.Components
{
public class Panel : UIComponent
{
public Vector2 Size { get; set; } = Vector2.One;
public Color Color { get; set; } = Color.White;
public Panel(Entity entity) : base(entity)
{
}

public override void OnStart()
{
}

public override void OnUpdate()
{
}

public override void OnUIRender()
{
var position = GetPivotedPosition(new(GetScreenWidth(), GetScreenHeight())) + Offset;
DrawRectanglePro(new Rectangle(position.X - Size.X / 2, position.Y - Size.Y / 2, Size.X, Size.Y), Size / 2, Rotation, Color);
}
}
}
3 changes: 2 additions & 1 deletion Basalt.TestField/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
player.AddComponent(new Basalt.TestField.Components.PlayerController(player));
player.AddComponent(new LightSource(player, "lighting") { Color = Color.Red, Type = LightType.Point });
//player.AddComponent(new TrailRenderer(player) { StartRadius = 0.5f, EndRadius = 0.1f, Color = Color.Red, TrailSegmentCount = 25, Offset = offset, TrailRefreshRate = 0.025f });
player.AddComponent(new Label(player) { Text = "This is a test label ", Pivot = UIPivot.MiddleLeft, Offset = new(100, 25)});
player.AddComponent(new Label(player) { Text = "This is a test label ", Pivot = UIPivot.TopCenter, Offset = new(100, 25)});
player.AddComponent(new Panel(player) { Size = new(100, 200), Color = Color.Blue, Pivot = UIPivot.TopRight, Offset = new(-100, 200), Rotation = 45f });

Engine.CreateEntity(player);

Expand Down
1 change: 1 addition & 0 deletions Basalt/Common/Components/UIComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public abstract class UIComponent : Component
public UIPivot Pivot { get; set; } = UIPivot.TopLeft;
public Vector2 Offset { get; set; }
public float ZIndex { get; set; }
public float Rotation { get; set; }
protected UIComponent(Entity entity) : base(entity)
{
}
Expand Down

0 comments on commit 28fd0b6

Please sign in to comment.