mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-29 20:03:41 +01:00
feat: add component library
This commit is contained in:
parent
7d5680badd
commit
841e452aa2
4 changed files with 100 additions and 0 deletions
42
Dalamud/Interface/Components/ComponentDemoWindow.cs
Normal file
42
Dalamud/Interface/Components/ComponentDemoWindow.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Dalamud/Interface/Components/IComponent.cs
Normal file
18
Dalamud/Interface/Components/IComponent.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Dalamud/Interface/Components/TestComponent.cs
Normal file
19
Dalamud/Interface/Components/TestComponent.cs
Normal 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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
using CheapLoc;
|
using CheapLoc;
|
||||||
|
using Dalamud.Interface.Components;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
|
@ -39,6 +40,7 @@ namespace Dalamud.Interface
|
||||||
private readonly PluginInstallerWindow pluginWindow;
|
private readonly PluginInstallerWindow pluginWindow;
|
||||||
private readonly DalamudPluginStatWindow pluginStatWindow;
|
private readonly DalamudPluginStatWindow pluginStatWindow;
|
||||||
private readonly DalamudChangelogWindow changelogWindow;
|
private readonly DalamudChangelogWindow changelogWindow;
|
||||||
|
private readonly ComponentDemoWindow componentDemoWindow;
|
||||||
|
|
||||||
private readonly WindowSystem windowSystem = new WindowSystem("DalamudCore");
|
private readonly WindowSystem windowSystem = new WindowSystem("DalamudCore");
|
||||||
|
|
||||||
|
|
@ -92,6 +94,12 @@ namespace Dalamud.Interface
|
||||||
};
|
};
|
||||||
this.windowSystem.AddWindow(this.changelogWindow);
|
this.windowSystem.AddWindow(this.changelogWindow);
|
||||||
|
|
||||||
|
this.componentDemoWindow = new ComponentDemoWindow()
|
||||||
|
{
|
||||||
|
IsOpen = false,
|
||||||
|
};
|
||||||
|
this.windowSystem.AddWindow(this.componentDemoWindow);
|
||||||
|
|
||||||
Log.Information("[DUI] Windows added");
|
Log.Information("[DUI] Windows added");
|
||||||
|
|
||||||
if (dalamud.Configuration.LogOpenAtStartup)
|
if (dalamud.Configuration.LogOpenAtStartup)
|
||||||
|
|
@ -195,6 +203,11 @@ namespace Dalamud.Interface
|
||||||
this.OpenChangelog();
|
this.OpenChangelog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui.MenuItem("Open Components Demo"))
|
||||||
|
{
|
||||||
|
this.OpenComponentDemo();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.MenuItem("Draw ImGui demo", string.Empty, ref this.isImguiDrawDemoWindow);
|
ImGui.MenuItem("Draw ImGui demo", string.Empty, ref this.isImguiDrawDemoWindow);
|
||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
|
|
@ -387,6 +400,14 @@ namespace Dalamud.Interface
|
||||||
this.pluginStatWindow.IsOpen ^= true;
|
this.pluginStatWindow.IsOpen ^= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Open the component test window.
|
||||||
|
/// </summary>
|
||||||
|
internal void OpenComponentDemo()
|
||||||
|
{
|
||||||
|
this.componentDemoWindow.IsOpen ^= true;
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
this.windowSystem.RemoveAllWindows();
|
this.windowSystem.RemoveAllWindows();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue