feat: add component library

This commit is contained in:
goat 2021-04-05 23:54:32 +02:00
parent 7d5680badd
commit 841e452aa2
4 changed files with 100 additions and 0 deletions

View file

@ -0,0 +1,42 @@
using System.Numerics;
using Dalamud.Interface.Windowing;
using ImGuiNET;
namespace Dalamud.Interface.Components
{
internal class ComponentDemoWindow : Window
{
private readonly IComponent[] components =
{
new TestComponent(),
};
public ComponentDemoWindow()
: base("Dalamud Components Demo")
{
this.Size = new Vector2(600, 500);
this.SizeCondition = ImGuiCond.FirstUseEver;
}
public override void Draw()
{
ImGui.BeginChild("comp_scrolling", new Vector2(0, 0), false, ImGuiWindowFlags.AlwaysVerticalScrollbar | ImGuiWindowFlags.HorizontalScrollbar);
ImGui.Text("This is a collection of UI components you can use in your plugin.");
for (var i = 0; i < this.components.Length; i++)
{
var thisComp = this.components[i];
if (ImGui.CollapsingHeader($"{thisComp.Name} ({thisComp.GetType().FullName})###comp{i}"))
{
thisComp.Draw();
}
}
ImGui.EndChild();
}
}
}

View file

@ -0,0 +1,18 @@
namespace Dalamud.Interface.Components
{
/// <summary>
/// Base interface implementing a modular interface component.
/// </summary>
public interface IComponent
{
/// <summary>
/// Gets or sets the name of the component.
/// </summary>
public string Name { get; }
/// <summary>
/// Draw the component via ImGui.
/// </summary>
public void Draw();
}
}

View file

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ImGuiNET;
namespace Dalamud.Interface.Components
{
class TestComponent : IComponent
{
public string Name { get; } = "Test Component";
public void Draw()
{
ImGui.Text("You are viewing the test component. The test was a success.");
}
}
}