diff --git a/Dalamud/Interface/Components/ComponentDemoWindow.cs b/Dalamud/Interface/Components/ComponentDemoWindow.cs
index 082c13550..3751ddffa 100644
--- a/Dalamud/Interface/Components/ComponentDemoWindow.cs
+++ b/Dalamud/Interface/Components/ComponentDemoWindow.cs
@@ -1,19 +1,18 @@
+using System;
using System.Collections.Generic;
-using System.Linq;
using System.Numerics;
using Dalamud.Interface.Windowing;
-using Dalamud.Plugin;
using ImGuiNET;
namespace Dalamud.Interface.Components
{
///
- /// Component Demo Window to view custom components.
+ /// Component Demo Window to view custom ImGui components.
///
internal class ComponentDemoWindow : Window
{
- private List components = new List();
+ private readonly List> componentDemos;
///
/// Initializes a new instance of the class.
@@ -23,45 +22,59 @@ namespace Dalamud.Interface.Components
{
this.Size = new Vector2(600, 500);
this.SizeCondition = ImGuiCond.FirstUseEver;
- this.AddComponents();
- this.SortComponents();
+ this.componentDemos = new List>
+ {
+ Demo("Test", ImGuiComponents.Test),
+ Demo("HelpMarker", HelpMarkerDemo),
+ Demo("IconButton", IconButtonDemo),
+ };
}
///
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.Count; i++)
+ for (var i = 0; i < this.componentDemos.Count; i++)
{
- var thisComp = this.components[i];
+ var componentDemo = this.componentDemos[i];
- if (ImGui.CollapsingHeader($"{thisComp.Name} ({thisComp.GetType().FullName})###comp{i}"))
+ if (ImGui.CollapsingHeader($"{componentDemo.Key}###comp{i}"))
{
- thisComp.Draw();
+ componentDemo.Value();
}
}
ImGui.EndChild();
}
- private void AddComponents()
+ private static void HelpMarkerDemo()
{
- this.components.Add(new TestComponent());
- this.components.Add(new HelpMarkerComponent("help me!")
- {
- SameLine = false,
- });
- var iconButtonComponent = new IconButtonComponent(1, FontAwesomeIcon.Carrot);
- iconButtonComponent.OnButtonClicked += id => PluginLog.Log("Button#{0} clicked!", id);
- this.components.Add(iconButtonComponent);
+ ImGui.Text("Hover over the icon to learn more.");
+ ImGuiComponents.HelpMarker("help me!");
}
- private void SortComponents()
+ private static void IconButtonDemo()
{
- this.components = this.components.OrderBy(component => component.Name).ToList();
+ ImGui.Text("Click on the icon to use as a button.");
+ ImGui.SameLine();
+ if (ImGuiComponents.IconButton(1, FontAwesomeIcon.Carrot))
+ {
+ ImGui.OpenPopup("IconButtonDemoPopup");
+ }
+
+ if (ImGui.BeginPopup("IconButtonDemoPopup"))
+ {
+ ImGui.Text("You clicked!");
+ }
+
+ ImGui.EndPopup();
+ }
+
+ private static KeyValuePair Demo(string name, Action func)
+ {
+ return new KeyValuePair(name, func);
}
}
}
diff --git a/Dalamud/Interface/Components/HelpMarkerComponent.cs b/Dalamud/Interface/Components/HelpMarkerComponent.cs
deleted file mode 100644
index f559c8ef2..000000000
--- a/Dalamud/Interface/Components/HelpMarkerComponent.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using ImGuiNET;
-
-namespace Dalamud.Interface.Components
-{
- ///
- /// HelpMarker component to add a help icon with text on hover.
- ///
- public class HelpMarkerComponent : IComponent
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The text to display on hover.
- public HelpMarkerComponent(string helpText)
- {
- this.HelpText = helpText;
- }
-
- ///
- /// Gets component name.
- ///
- public string Name { get; } = "HelpMarker Component";
-
- ///
- /// Gets or sets a value indicating whether the help text should display on same line as previous element.
- ///
- public bool SameLine { get; set; } = true;
-
- ///
- /// Gets or sets the help text.
- ///
- public string HelpText { get; set; }
-
- ///
- /// Gets or sets the help marker icon.
- ///
- public FontAwesomeIcon HelpIcon { get; set; } = FontAwesomeIcon.InfoCircle;
-
- ///
- /// Gets or sets the help text size modifier.
- ///
- public float HelpTextModifier { get; set; } = 35.0f;
-
- ///
- /// Draw HelpMarker component.
- ///
- public void Draw()
- {
- if (this.SameLine) ImGui.SameLine();
- ImGui.PushFont(UiBuilder.IconFont);
- ImGui.TextDisabled(this.HelpIcon.ToIconString());
- ImGui.PopFont();
- if (!ImGui.IsItemHovered()) return;
- ImGui.BeginTooltip();
- ImGui.PushTextWrapPos(ImGui.GetFontSize() * this.HelpTextModifier);
- ImGui.TextUnformatted(this.HelpText);
- ImGui.PopTextWrapPos();
- ImGui.EndTooltip();
- }
- }
-}
diff --git a/Dalamud/Interface/Components/IComponent.cs b/Dalamud/Interface/Components/IComponent.cs
deleted file mode 100644
index 9a7ac55b6..000000000
--- a/Dalamud/Interface/Components/IComponent.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace Dalamud.Interface.Components
-{
- ///
- /// Base interface implementing a modular interface component.
- ///
- public interface IComponent
- {
- ///
- /// Gets the name of the component.
- ///
- public string Name { get; }
-
- ///
- /// Draw the component via ImGui.
- ///
- public void Draw();
- }
-}
diff --git a/Dalamud/Interface/Components/IconButtonComponent.cs b/Dalamud/Interface/Components/IconButtonComponent.cs
deleted file mode 100644
index 7faa4623c..000000000
--- a/Dalamud/Interface/Components/IconButtonComponent.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-using System.Numerics;
-
-using ImGuiNET;
-
-namespace Dalamud.Interface.Components
-{
- ///
- /// IconButton component to use an icon as a button.
- ///
- public class IconButtonComponent : IComponent
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The id for the button.
- /// The icon for the button.
- public IconButtonComponent(int buttonId, FontAwesomeIcon buttonIcon)
- {
- this.ButtonId = buttonId;
- this.ButtonIcon = buttonIcon;
- }
-
- ///
- /// Delegate for the event that occurs when the button is clicked.
- ///
- /// The id of the button that was clicked.
- public delegate void IsButtonClickedDelegate(int buttonId);
-
- ///
- /// Event that occurs when the button is clicked.
- ///
- public event IsButtonClickedDelegate OnButtonClicked;
-
- ///
- /// Gets component name.
- ///
- public string Name { get; } = "IconButton Component";
-
- ///
- /// Gets or sets the id for the button.
- ///
- public int ButtonId { get; set; }
-
- ///
- /// Gets or sets the icon to use for the button.
- ///
- public FontAwesomeIcon ButtonIcon { get; set; }
-
- ///
- /// Gets or sets the button color.
- ///
- public Vector4 ButtonColor { get; set; } = Vector4.Zero;
-
- ///
- /// Gets or sets the active button color.
- ///
- public Vector4 ButtonColorActive { get; set; } = Vector4.Zero;
-
- ///
- /// Gets or sets the hovered button color.
- ///
- public Vector4 ButtonColorHovered { get; set; } = Vector4.Zero;
-
- ///
- /// Draw IconButton component.
- ///
- public void Draw()
- {
- ImGui.PushStyleColor(ImGuiCol.Button, this.ButtonColor);
- ImGui.PushStyleColor(ImGuiCol.ButtonActive, this.ButtonColorActive);
- ImGui.PushStyleColor(ImGuiCol.ButtonHovered, this.ButtonColorHovered);
- ImGui.PushFont(UiBuilder.IconFont);
- if (ImGui.Button($"{this.ButtonIcon.ToIconString()}{this.ButtonId}"))
- {
- this.OnButtonClicked?.Invoke(this.ButtonId);
- }
-
- ImGui.PopFont();
- ImGui.PopStyleColor(3);
- }
- }
-}
diff --git a/Dalamud/Interface/Components/ImGuiComponents.HelpMarker.cs b/Dalamud/Interface/Components/ImGuiComponents.HelpMarker.cs
new file mode 100644
index 000000000..dfb86cf79
--- /dev/null
+++ b/Dalamud/Interface/Components/ImGuiComponents.HelpMarker.cs
@@ -0,0 +1,28 @@
+using ImGuiNET;
+
+namespace Dalamud.Interface.Components
+{
+ ///
+ /// Class containing various methods providing ImGui components.
+ ///
+ public static partial class ImGuiComponents
+ {
+ ///
+ /// HelpMarker component to add a help icon with text on hover.
+ ///
+ /// The text to display on hover.
+ public static void HelpMarker(string helpText)
+ {
+ ImGui.SameLine();
+ ImGui.PushFont(UiBuilder.IconFont);
+ ImGui.TextDisabled(FontAwesomeIcon.InfoCircle.ToIconString());
+ ImGui.PopFont();
+ if (!ImGui.IsItemHovered()) return;
+ ImGui.BeginTooltip();
+ ImGui.PushTextWrapPos(ImGui.GetFontSize() * 35.0f);
+ ImGui.TextUnformatted(helpText);
+ ImGui.PopTextWrapPos();
+ ImGui.EndTooltip();
+ }
+ }
+}
diff --git a/Dalamud/Interface/Components/ImGuiComponents.IconButton.cs b/Dalamud/Interface/Components/ImGuiComponents.IconButton.cs
new file mode 100644
index 000000000..3b6f8f213
--- /dev/null
+++ b/Dalamud/Interface/Components/ImGuiComponents.IconButton.cs
@@ -0,0 +1,51 @@
+using System.Numerics;
+
+using ImGuiNET;
+
+namespace Dalamud.Interface.Components
+{
+ ///
+ /// Class containing various methods providing ImGui components.
+ ///
+ public static partial class ImGuiComponents
+ {
+ ///
+ /// IconButton component to use an icon as a button.
+ ///
+ /// The ID of the button.
+ /// The icon for the button.
+ /// Indicator if button is clicked.
+ public static bool IconButton(int id, FontAwesomeIcon icon)
+ {
+ ImGui.PushStyleColor(ImGuiCol.Button, Vector4.Zero);
+ ImGui.PushStyleColor(ImGuiCol.ButtonActive, Vector4.Zero);
+ ImGui.PushStyleColor(ImGuiCol.ButtonHovered, Vector4.Zero);
+ ImGui.PushFont(UiBuilder.IconFont);
+ var button = ImGui.Button($"{icon.ToIconString()}{id}");
+ ImGui.PopFont();
+ ImGui.PopStyleColor(3);
+ return button;
+ }
+
+ ///
+ /// IconButton component to use an icon as a button with color options.
+ ///
+ /// The ID of the button.
+ /// The icon for the button.
+ /// The default color of the button.
+ /// The color of the button when active.
+ /// The color of the button when hovered.
+ /// Indicator if button is clicked.
+ public static bool IconButton(int id, FontAwesomeIcon icon, Vector4 defaultColor, Vector4 activeColor, Vector4 hoveredColor)
+ {
+ ImGui.PushStyleColor(ImGuiCol.Button, defaultColor);
+ ImGui.PushStyleColor(ImGuiCol.ButtonActive, activeColor);
+ ImGui.PushStyleColor(ImGuiCol.ButtonHovered, hoveredColor);
+ ImGui.PushFont(UiBuilder.IconFont);
+ var button = ImGui.Button($"{icon.ToIconString()}{id}");
+ ImGui.PopFont();
+ ImGui.PopStyleColor(3);
+ return button;
+ }
+ }
+}
diff --git a/Dalamud/Interface/Components/ImGuiComponents.Test.cs b/Dalamud/Interface/Components/ImGuiComponents.Test.cs
new file mode 100644
index 000000000..54026b379
--- /dev/null
+++ b/Dalamud/Interface/Components/ImGuiComponents.Test.cs
@@ -0,0 +1,18 @@
+using ImGuiNET;
+
+namespace Dalamud.Interface.Components
+{
+ ///
+ /// Class containing various methods providing ImGui components.
+ ///
+ public static partial class ImGuiComponents
+ {
+ ///
+ /// Test component to demonstrate how ImGui components work.
+ ///
+ public static void Test()
+ {
+ ImGui.Text("You are viewing the test component. The test was a success.");
+ }
+ }
+}
diff --git a/Dalamud/Interface/Components/ImGuiComponents.cs b/Dalamud/Interface/Components/ImGuiComponents.cs
new file mode 100644
index 000000000..60d6a0e06
--- /dev/null
+++ b/Dalamud/Interface/Components/ImGuiComponents.cs
@@ -0,0 +1,9 @@
+namespace Dalamud.Interface.Components
+{
+ ///
+ /// Class containing various methods providing ImGui components.
+ ///
+ public static partial class ImGuiComponents
+ {
+ }
+}
diff --git a/Dalamud/Interface/Components/TestComponent.cs b/Dalamud/Interface/Components/TestComponent.cs
deleted file mode 100644
index 30412be8b..000000000
--- a/Dalamud/Interface/Components/TestComponent.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using ImGuiNET;
-
-namespace Dalamud.Interface.Components
-{
- ///
- /// Test component to demonstrate how ImGui components work.
- ///
- public class TestComponent : IComponent
- {
- ///
- /// Gets component name.
- ///
- public string Name { get; } = "Test Component";
-
- ///
- /// Draw test component.
- ///
- public void Draw()
- {
- ImGui.Text("You are viewing the test component. The test was a success.");
- }
- }
-}