Magic the magic happen

This commit is contained in:
Raymond Lynch 2021-07-11 16:32:29 -04:00
parent 84769ae5b7
commit 658eedca37
188 changed files with 10329 additions and 3549 deletions

View file

@ -1,95 +0,0 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing;
using ImGuiNET;
namespace Dalamud.Interface.Components
{
/// <summary>
/// Component Demo Window to view custom ImGui components.
/// </summary>
internal class ComponentDemoWindow : Window
{
private readonly List<KeyValuePair<string, Action>> componentDemos;
private Vector4 defaultColor = ImGuiColors.DalamudOrange;
/// <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.componentDemos = new List<KeyValuePair<string, Action>>
{
Demo("Test", ImGuiComponents.Test),
Demo("HelpMarker", HelpMarkerDemo),
Demo("IconButton", IconButtonDemo),
Demo("TextWithLabel", TextWithLabelDemo),
Demo("ColorPickerWithPalette", this.ColorPickerWithPaletteDemo),
};
}
/// <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.componentDemos.Count; i++)
{
var componentDemo = this.componentDemos[i];
if (ImGui.CollapsingHeader($"{componentDemo.Key}###comp{i}"))
{
componentDemo.Value();
}
}
ImGui.EndChild();
}
private static void HelpMarkerDemo()
{
ImGui.Text("Hover over the icon to learn more.");
ImGuiComponents.HelpMarker("help me!");
}
private static void IconButtonDemo()
{
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 void TextWithLabelDemo()
{
ImGuiComponents.TextWithLabel("Label", "Hover to see more", "more");
}
private static KeyValuePair<string, Action> Demo(string name, Action func)
{
return new KeyValuePair<string, Action>(name, func);
}
private void ColorPickerWithPaletteDemo()
{
ImGui.Text("Click on the color button to use the picker.");
ImGui.SameLine();
this.defaultColor = ImGuiComponents.ColorPickerWithPalette(1, "ColorPickerWithPalette Demo", this.defaultColor);
}
}
}

View file

@ -0,0 +1,76 @@
using System.Numerics;
using ImGuiNET;
namespace Dalamud.Interface.Components
{
/// <summary>
/// Class containing various methods providing ImGui components.
/// </summary>
public static partial class ImGuiComponents
{
/// <summary>
/// Alpha modified IconButton component to use an icon as a button with alpha and color options.
/// </summary>
/// <param name="icon">The icon for the button.</param>
/// <param name="id">The ID of the button.</param>
/// <param name="defaultColor">The default color of the button.</param>
/// <param name="activeColor">The color of the button when active.</param>
/// <param name="hoveredColor">The color of the button when hovered.</param>
/// <param name="alphaMult">A multiplier for the current alpha levels.</param>
/// <returns>Indicator if button is clicked.</returns>
public static bool DisabledButton(FontAwesomeIcon icon, int? id = null, Vector4? defaultColor = null, Vector4? activeColor = null, Vector4? hoveredColor = null, float alphaMult = .5f)
{
ImGui.PushFont(UiBuilder.IconFont);
var text = icon.ToIconString();
if (id.HasValue)
text = $"{text}{id}";
var button = DisabledButton(text, defaultColor, activeColor, hoveredColor, alphaMult);
ImGui.PopFont();
return button;
}
/// <summary>
/// Alpha modified Button component to use as a disabled button with alpha and color options.
/// </summary>
/// <param name="labelWithId">The button label with ID.</param>
/// <param name="defaultColor">The default color of the button.</param>
/// <param name="activeColor">The color of the button when active.</param>
/// <param name="hoveredColor">The color of the button when hovered.</param>
/// <param name="alphaMult">A multiplier for the current alpha levels.</param>
/// <returns>Indicator if button is clicked.</returns>
public static bool DisabledButton(string labelWithId, Vector4? defaultColor = null, Vector4? activeColor = null, Vector4? hoveredColor = null, float alphaMult = .5f)
{
if (defaultColor.HasValue)
ImGui.PushStyleColor(ImGuiCol.Button, defaultColor.Value);
if (activeColor.HasValue)
ImGui.PushStyleColor(ImGuiCol.ButtonActive, activeColor.Value);
if (hoveredColor.HasValue)
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, hoveredColor.Value);
var style = ImGui.GetStyle();
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, style.Alpha * alphaMult);
var button = ImGui.Button(labelWithId);
ImGui.PopStyleVar();
if (defaultColor.HasValue)
ImGui.PopStyleColor();
if (activeColor.HasValue)
ImGui.PopStyleColor();
if (hoveredColor.HasValue)
ImGui.PopStyleColor();
return button;
}
}
}

View file

@ -9,6 +9,14 @@ namespace Dalamud.Interface.Components
/// </summary>
public static partial class ImGuiComponents
{
/// <summary>
/// IconButton component to use an icon as a button.
/// </summary>
/// <param name="icon">The icon for the button.</param>
/// <returns>Indicator if button is clicked.</returns>
public static bool IconButton(FontAwesomeIcon icon)
=> IconButton(icon, null, null, null);
/// <summary>
/// IconButton component to use an icon as a button.
/// </summary>
@ -16,16 +24,26 @@ namespace Dalamud.Interface.Components
/// <param name="icon">The icon for the button.</param>
/// <returns>Indicator if button is clicked.</returns>
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(id, icon, null, null, null);
/// <summary>
/// IconButton component to use an icon as a button.
/// </summary>
/// <param name="iconText">Text already containing the icon string.</param>
/// <returns>Indicator if button is clicked.</returns>
public static bool IconButton(string iconText)
=> IconButton(iconText, null, null, null);
/// <summary>
/// IconButton component to use an icon as a button.
/// </summary>
/// <param name="icon">The icon for the button.</param>
/// <param name="defaultColor">The default color of the button.</param>
/// <param name="activeColor">The color of the button when active.</param>
/// <param name="hoveredColor">The color of the button when hovered.</param>
/// <returns>Indicator if button is clicked.</returns>
public static bool IconButton(FontAwesomeIcon icon, Vector4? defaultColor = null, Vector4? activeColor = null, Vector4? hoveredColor = null)
=> IconButton($"{icon.ToIconString()}", defaultColor, activeColor, hoveredColor);
/// <summary>
/// IconButton component to use an icon as a button with color options.
@ -36,15 +54,48 @@ namespace Dalamud.Interface.Components
/// <param name="activeColor">The color of the button when active.</param>
/// <param name="hoveredColor">The color of the button when hovered.</param>
/// <returns>Indicator if button is clicked.</returns>
public static bool IconButton(int id, FontAwesomeIcon icon, Vector4 defaultColor, Vector4 activeColor, Vector4 hoveredColor)
public static bool IconButton(int id, FontAwesomeIcon icon, Vector4? defaultColor = null, Vector4? activeColor = null, Vector4? hoveredColor = null)
=> IconButton($"{icon.ToIconString()}{id}", defaultColor, activeColor, hoveredColor);
/// <summary>
/// IconButton component to use an icon as a button with color options.
/// </summary>
/// <param name="iconText">Text already containing the icon string.</param>
/// <param name="defaultColor">The default color of the button.</param>
/// <param name="activeColor">The color of the button when active.</param>
/// <param name="hoveredColor">The color of the button when hovered.</param>
/// <returns>Indicator if button is clicked.</returns>
public static bool IconButton(string iconText, Vector4? defaultColor = null, Vector4? activeColor = null, Vector4? hoveredColor = null)
{
ImGui.PushStyleColor(ImGuiCol.Button, defaultColor);
ImGui.PushStyleColor(ImGuiCol.ButtonActive, activeColor);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, hoveredColor);
var numColors = 0;
if (defaultColor.HasValue)
{
ImGui.PushStyleColor(ImGuiCol.Button, defaultColor.Value);
numColors++;
}
if (activeColor.HasValue)
{
ImGui.PushStyleColor(ImGuiCol.ButtonActive, activeColor.Value);
numColors++;
}
if (hoveredColor.HasValue)
{
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, hoveredColor.Value);
numColors++;
}
ImGui.PushFont(UiBuilder.IconFont);
var button = ImGui.Button($"{icon.ToIconString()}{id}");
var button = ImGui.Button(iconText);
ImGui.PopFont();
ImGui.PopStyleColor(3);
if (numColors > 0)
ImGui.PopStyleColor(numColors);
return button;
}
}

View file

@ -13,8 +13,7 @@ namespace Dalamud.Interface.Components
/// <param name="label">The label for text.</param>
/// <param name="value">The text value.</param>
/// <param name="hint">The hint to show on hover.</param>
public static void TextWithLabel(
string label, string value, string hint = "")
public static void TextWithLabel(string label, string value, string hint = "")
{
ImGui.Text(label + ": ");
ImGui.SameLine();