diff --git a/Dalamud/Interface/Components/ComponentDemoWindow.cs b/Dalamud/Interface/Components/ComponentDemoWindow.cs new file mode 100644 index 000000000..244a43222 --- /dev/null +++ b/Dalamud/Interface/Components/ComponentDemoWindow.cs @@ -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(); + } + } +} diff --git a/Dalamud/Interface/Components/IComponent.cs b/Dalamud/Interface/Components/IComponent.cs new file mode 100644 index 000000000..02784000c --- /dev/null +++ b/Dalamud/Interface/Components/IComponent.cs @@ -0,0 +1,18 @@ +namespace Dalamud.Interface.Components +{ + /// + /// Base interface implementing a modular interface component. + /// + public interface IComponent + { + /// + /// Gets or sets the name of the component. + /// + public string Name { get; } + + /// + /// Draw the component via ImGui. + /// + public void Draw(); + } +} diff --git a/Dalamud/Interface/Components/TestComponent.cs b/Dalamud/Interface/Components/TestComponent.cs new file mode 100644 index 000000000..587f3757a --- /dev/null +++ b/Dalamud/Interface/Components/TestComponent.cs @@ -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."); + } + } +} diff --git a/Dalamud/Interface/DalamudInterface.cs b/Dalamud/Interface/DalamudInterface.cs index ba254fe03..fe7e6c5c2 100644 --- a/Dalamud/Interface/DalamudInterface.cs +++ b/Dalamud/Interface/DalamudInterface.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using CheapLoc; +using Dalamud.Interface.Components; using Dalamud.Interface.Windowing; using Dalamud.Plugin; using ImGuiNET; @@ -39,6 +40,7 @@ namespace Dalamud.Interface private readonly PluginInstallerWindow pluginWindow; private readonly DalamudPluginStatWindow pluginStatWindow; private readonly DalamudChangelogWindow changelogWindow; + private readonly ComponentDemoWindow componentDemoWindow; private readonly WindowSystem windowSystem = new WindowSystem("DalamudCore"); @@ -92,6 +94,12 @@ namespace Dalamud.Interface }; this.windowSystem.AddWindow(this.changelogWindow); + this.componentDemoWindow = new ComponentDemoWindow() + { + IsOpen = false, + }; + this.windowSystem.AddWindow(this.componentDemoWindow); + Log.Information("[DUI] Windows added"); if (dalamud.Configuration.LogOpenAtStartup) @@ -195,6 +203,11 @@ namespace Dalamud.Interface this.OpenChangelog(); } + if (ImGui.MenuItem("Open Components Demo")) + { + this.OpenComponentDemo(); + } + ImGui.MenuItem("Draw ImGui demo", string.Empty, ref this.isImguiDrawDemoWindow); ImGui.Separator(); @@ -387,6 +400,14 @@ namespace Dalamud.Interface this.pluginStatWindow.IsOpen ^= true; } + /// + /// Open the component test window. + /// + internal void OpenComponentDemo() + { + this.componentDemoWindow.IsOpen ^= true; + } + public void Dispose() { this.windowSystem.RemoveAllWindows();