mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Merge pull request #297 from kalilistic/icon-help-components
This commit is contained in:
commit
25ce0be268
6 changed files with 189 additions and 13 deletions
|
|
@ -72,6 +72,8 @@ resharper_align_multiline_for_stmt = true
|
|||
resharper_align_multline_type_parameter_constrains = true
|
||||
resharper_align_multline_type_parameter_list = 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_braces_for_ifelse = required_for_multiline
|
||||
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_wrap_after_declaration_lpar = 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_place_accessorholder_attribute_on_same_line = false
|
||||
resharper_place_field_attribute_on_same_line = false
|
||||
|
|
|
|||
|
|
@ -1,32 +1,40 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Components
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Component Demo Window to view custom components.
|
||||
/// </summary>
|
||||
internal class ComponentDemoWindow : Window
|
||||
{
|
||||
private readonly IComponent[] components =
|
||||
{
|
||||
new TestComponent(),
|
||||
};
|
||||
private List<IComponent> components = new List<IComponent>();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ComponentDemoWindow"/> class.
|
||||
/// </summary>
|
||||
public ComponentDemoWindow()
|
||||
: base("Dalamud Components Demo")
|
||||
{
|
||||
this.Size = new Vector2(600, 500);
|
||||
this.SizeCondition = ImGuiCond.FirstUseEver;
|
||||
this.AddComponents();
|
||||
this.SortComponents();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
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++)
|
||||
for (var i = 0; i < this.components.Count; i++)
|
||||
{
|
||||
var thisComp = this.components[i];
|
||||
|
||||
|
|
@ -38,5 +46,22 @@ namespace Dalamud.Interface.Components
|
|||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ namespace Dalamud.Interface.Components
|
|||
public interface IComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the component.
|
||||
/// Gets the name of the component.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
|
|
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,20 @@
|
|||
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
|
||||
/// <summary>
|
||||
/// Test component to demonstrate how ImGui components work.
|
||||
/// </summary>
|
||||
public class TestComponent : IComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets component name.
|
||||
/// </summary>
|
||||
public string Name { get; } = "Test Component";
|
||||
|
||||
/// <summary>
|
||||
/// Draw test component.
|
||||
/// </summary>
|
||||
public void Draw()
|
||||
{
|
||||
ImGui.Text("You are viewing the test component. The test was a success.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue