mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: add icon button and help marker components
This commit is contained in:
parent
76fc6e2a8d
commit
1344594b3b
4 changed files with 171 additions and 5 deletions
|
|
@ -72,6 +72,8 @@ resharper_align_multiline_for_stmt = true
|
||||||
resharper_align_multline_type_parameter_constrains = true
|
resharper_align_multline_type_parameter_constrains = true
|
||||||
resharper_align_multline_type_parameter_list = true
|
resharper_align_multline_type_parameter_list = true
|
||||||
resharper_apply_on_completion = true
|
resharper_apply_on_completion = true
|
||||||
|
resharper_auto_property_can_be_made_get_only_global_highlighting = none
|
||||||
|
resharper_auto_property_can_be_made_get_only_local_highlighting = none
|
||||||
resharper_autodetect_indent_settings = true
|
resharper_autodetect_indent_settings = true
|
||||||
resharper_braces_for_ifelse = required_for_multiline
|
resharper_braces_for_ifelse = required_for_multiline
|
||||||
resharper_can_use_global_alias = false
|
resharper_can_use_global_alias = false
|
||||||
|
|
@ -82,6 +84,8 @@ resharper_csharp_int_align_comments = true
|
||||||
resharper_csharp_new_line_before_while = true
|
resharper_csharp_new_line_before_while = true
|
||||||
resharper_csharp_wrap_after_declaration_lpar = true
|
resharper_csharp_wrap_after_declaration_lpar = true
|
||||||
resharper_enforce_line_ending_style = true
|
resharper_enforce_line_ending_style = true
|
||||||
|
resharper_member_can_be_private_global_highlighting = none
|
||||||
|
resharper_member_can_be_private_local_highlighting = none
|
||||||
resharper_new_line_before_finally = false
|
resharper_new_line_before_finally = false
|
||||||
resharper_place_accessorholder_attribute_on_same_line = false
|
resharper_place_accessorholder_attribute_on_same_line = false
|
||||||
resharper_place_field_attribute_on_same_line = false
|
resharper_place_field_attribute_on_same_line = false
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
|
using Dalamud.Plugin;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
|
||||||
namespace Dalamud.Interface.Components
|
namespace Dalamud.Interface.Components
|
||||||
|
|
@ -10,10 +13,7 @@ namespace Dalamud.Interface.Components
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class ComponentDemoWindow : Window
|
internal class ComponentDemoWindow : Window
|
||||||
{
|
{
|
||||||
private readonly IComponent[] components =
|
private List<IComponent> components = new List<IComponent>();
|
||||||
{
|
|
||||||
new TestComponent(),
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ComponentDemoWindow"/> class.
|
/// Initializes a new instance of the <see cref="ComponentDemoWindow"/> class.
|
||||||
|
|
@ -23,6 +23,8 @@ namespace Dalamud.Interface.Components
|
||||||
{
|
{
|
||||||
this.Size = new Vector2(600, 500);
|
this.Size = new Vector2(600, 500);
|
||||||
this.SizeCondition = ImGuiCond.FirstUseEver;
|
this.SizeCondition = ImGuiCond.FirstUseEver;
|
||||||
|
this.AddComponents();
|
||||||
|
this.SortComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
@ -32,7 +34,7 @@ namespace Dalamud.Interface.Components
|
||||||
|
|
||||||
ImGui.Text("This is a collection of UI components you can use in your plugin.");
|
ImGui.Text("This is a collection of UI components you can use in your plugin.");
|
||||||
|
|
||||||
for (var i = 0; i < this.components.Length; i++)
|
for (var i = 0; i < this.components.Count; i++)
|
||||||
{
|
{
|
||||||
var thisComp = this.components[i];
|
var thisComp = this.components[i];
|
||||||
|
|
||||||
|
|
@ -44,5 +46,22 @@ namespace Dalamud.Interface.Components
|
||||||
|
|
||||||
ImGui.EndChild();
|
ImGui.EndChild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddComponents()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SortComponents()
|
||||||
|
{
|
||||||
|
this.components = this.components.OrderBy(component => component.Name).ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
61
Dalamud/Interface/Components/HelpMarkerComponent.cs
Normal file
61
Dalamud/Interface/Components/HelpMarkerComponent.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
using ImGuiNET;
|
||||||
|
|
||||||
|
namespace Dalamud.Interface.Components
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// HelpMarker component to add a help icon with text on hover.
|
||||||
|
/// </summary>
|
||||||
|
public class HelpMarkerComponent : IComponent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="HelpMarkerComponent"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="helpText">The text to display on hover.</param>
|
||||||
|
public HelpMarkerComponent(string helpText)
|
||||||
|
{
|
||||||
|
this.HelpText = helpText;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets component name.
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; } = "HelpMarker Component";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether the help text should display on same line as previous element.
|
||||||
|
/// </summary>
|
||||||
|
public bool SameLine { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the help text.
|
||||||
|
/// </summary>
|
||||||
|
public string HelpText { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the help marker icon.
|
||||||
|
/// </summary>
|
||||||
|
public FontAwesomeIcon HelpIcon { get; set; } = FontAwesomeIcon.InfoCircle;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the help text size modifier.
|
||||||
|
/// </summary>
|
||||||
|
public float HelpTextModifier { get; set; } = 35.0f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draw HelpMarker component.
|
||||||
|
/// </summary>
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
82
Dalamud/Interface/Components/IconButtonComponent.cs
Normal file
82
Dalamud/Interface/Components/IconButtonComponent.cs
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
|
using ImGuiNET;
|
||||||
|
|
||||||
|
namespace Dalamud.Interface.Components
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IconButton component to use an icon as a button.
|
||||||
|
/// </summary>
|
||||||
|
public class IconButtonComponent : IComponent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="IconButtonComponent"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buttonId">The id for the button.</param>
|
||||||
|
/// <param name="buttonIcon">The icon for the button.</param>
|
||||||
|
public IconButtonComponent(int buttonId, FontAwesomeIcon buttonIcon)
|
||||||
|
{
|
||||||
|
this.ButtonId = buttonId;
|
||||||
|
this.ButtonIcon = buttonIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delegate for the <see cref="IconButtonComponent.IsButtonClickedDelegate"/> event that occurs when the button is clicked.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buttonId">The id of the button that was clicked.</param>
|
||||||
|
public delegate void IsButtonClickedDelegate(int buttonId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that occurs when the button is clicked.
|
||||||
|
/// </summary>
|
||||||
|
public event IsButtonClickedDelegate OnButtonClicked;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets component name.
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; } = "IconButton Component";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the id for the button.
|
||||||
|
/// </summary>
|
||||||
|
public int ButtonId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the icon to use for the button.
|
||||||
|
/// </summary>
|
||||||
|
public FontAwesomeIcon ButtonIcon { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the button color.
|
||||||
|
/// </summary>
|
||||||
|
public Vector4 ButtonColor { get; set; } = Vector4.Zero;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the active button color.
|
||||||
|
/// </summary>
|
||||||
|
public Vector4 ButtonColorActive { get; set; } = Vector4.Zero;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the hovered button color.
|
||||||
|
/// </summary>
|
||||||
|
public Vector4 ButtonColorHovered { get; set; } = Vector4.Zero;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draw IconButton component.
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue