Revert "refactor(Dalamud): switch to file-scoped namespaces"

This reverts commit b5f34c3199.
This commit is contained in:
goat 2021-11-18 15:23:40 +01:00
parent d473826247
commit 1561fbac00
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5
325 changed files with 45549 additions and 45209 deletions

View file

@ -2,68 +2,69 @@ using System.Numerics;
using ImGuiNET;
namespace Dalamud.Interface.Components;
/// <summary>
/// Class containing various methods providing ImGui components.
/// </summary>
public static partial class ImGuiComponents
namespace Dalamud.Interface.Components
{
/// <summary>
/// ColorPicker with palette.
/// Class containing various methods providing ImGui components.
/// </summary>
/// <param name="id">Id for the color picker.</param>
/// <param name="description">The description of the color picker.</param>
/// <param name="originalColor">The current color.</param>
/// <returns>Selected color.</returns>
public static Vector4 ColorPickerWithPalette(int id, string description, Vector4 originalColor)
public static partial class ImGuiComponents
{
const ImGuiColorEditFlags flags = ImGuiColorEditFlags.NoSidePreview | ImGuiColorEditFlags.NoSmallPreview;
return ColorPickerWithPalette(id, description, originalColor, flags);
}
/// <summary>
/// ColorPicker with palette with color picker options.
/// </summary>
/// <param name="id">Id for the color picker.</param>
/// <param name="description">The description of the color picker.</param>
/// <param name="originalColor">The current color.</param>
/// <param name="flags">Flags to customize color picker.</param>
/// <returns>Selected color.</returns>
public static Vector4 ColorPickerWithPalette(int id, string description, Vector4 originalColor, ImGuiColorEditFlags flags)
{
var existingColor = originalColor;
var selectedColor = originalColor;
var colorPalette = ImGuiHelpers.DefaultColorPalette(36);
if (ImGui.ColorButton($"{description}###ColorPickerButton{id}", originalColor))
/// <summary>
/// ColorPicker with palette.
/// </summary>
/// <param name="id">Id for the color picker.</param>
/// <param name="description">The description of the color picker.</param>
/// <param name="originalColor">The current color.</param>
/// <returns>Selected color.</returns>
public static Vector4 ColorPickerWithPalette(int id, string description, Vector4 originalColor)
{
ImGui.OpenPopup($"###ColorPickerPopup{id}");
const ImGuiColorEditFlags flags = ImGuiColorEditFlags.NoSidePreview | ImGuiColorEditFlags.NoSmallPreview;
return ColorPickerWithPalette(id, description, originalColor, flags);
}
if (ImGui.BeginPopup($"###ColorPickerPopup{id}"))
/// <summary>
/// ColorPicker with palette with color picker options.
/// </summary>
/// <param name="id">Id for the color picker.</param>
/// <param name="description">The description of the color picker.</param>
/// <param name="originalColor">The current color.</param>
/// <param name="flags">Flags to customize color picker.</param>
/// <returns>Selected color.</returns>
public static Vector4 ColorPickerWithPalette(int id, string description, Vector4 originalColor, ImGuiColorEditFlags flags)
{
if (ImGui.ColorPicker4($"###ColorPicker{id}", ref existingColor, flags))
var existingColor = originalColor;
var selectedColor = originalColor;
var colorPalette = ImGuiHelpers.DefaultColorPalette(36);
if (ImGui.ColorButton($"{description}###ColorPickerButton{id}", originalColor))
{
selectedColor = existingColor;
ImGui.OpenPopup($"###ColorPickerPopup{id}");
}
for (var i = 0; i < 4; i++)
if (ImGui.BeginPopup($"###ColorPickerPopup{id}"))
{
ImGui.Spacing();
for (var j = i * 9; j < (i * 9) + 9; j++)
if (ImGui.ColorPicker4($"###ColorPicker{id}", ref existingColor, flags))
{
if (ImGui.ColorButton($"###ColorPickerSwatch{id}{i}{j}", colorPalette[j]))
{
selectedColor = colorPalette[j];
}
ImGui.SameLine();
selectedColor = existingColor;
}
for (var i = 0; i < 4; i++)
{
ImGui.Spacing();
for (var j = i * 9; j < (i * 9) + 9; j++)
{
if (ImGui.ColorButton($"###ColorPickerSwatch{id}{i}{j}", colorPalette[j]))
{
selectedColor = colorPalette[j];
}
ImGui.SameLine();
}
}
ImGui.EndPopup();
}
ImGui.EndPopup();
return selectedColor;
}
return selectedColor;
}
}

View file

@ -2,74 +2,75 @@ using System.Numerics;
using ImGuiNET;
namespace Dalamud.Interface.Components;
/// <summary>
/// Class containing various methods providing ImGui components.
/// </summary>
public static partial class ImGuiComponents
namespace Dalamud.Interface.Components
{
/// <summary>
/// Alpha modified IconButton component to use an icon as a button with alpha and color options.
/// Class containing various methods providing ImGui components.
/// </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)
public static partial class ImGuiComponents
{
ImGui.PushFont(UiBuilder.IconFont);
/// <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 text = icon.ToIconString();
if (id.HasValue)
text = $"{text}{id}";
var button = DisabledButton(text, defaultColor, activeColor, hoveredColor, alphaMult);
var button = DisabledButton(text, defaultColor, activeColor, hoveredColor, alphaMult);
ImGui.PopFont();
ImGui.PopFont();
return button;
}
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);
/// <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 (activeColor.HasValue)
ImGui.PushStyleColor(ImGuiCol.ButtonActive, activeColor.Value);
if (hoveredColor.HasValue)
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, hoveredColor.Value);
if (hoveredColor.HasValue)
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, hoveredColor.Value);
var style = ImGui.GetStyle();
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, style.Alpha * alphaMult);
var style = ImGui.GetStyle();
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, style.Alpha * alphaMult);
var button = ImGui.Button(labelWithId);
var button = ImGui.Button(labelWithId);
ImGui.PopStyleVar();
ImGui.PopStyleVar();
if (defaultColor.HasValue)
ImGui.PopStyleColor();
if (defaultColor.HasValue)
ImGui.PopStyleColor();
if (activeColor.HasValue)
ImGui.PopStyleColor();
if (activeColor.HasValue)
ImGui.PopStyleColor();
if (hoveredColor.HasValue)
ImGui.PopStyleColor();
if (hoveredColor.HasValue)
ImGui.PopStyleColor();
return button;
return button;
}
}
}

View file

@ -1,27 +1,28 @@
using ImGuiNET;
namespace Dalamud.Interface.Components;
/// <summary>
/// Class containing various methods providing ImGui components.
/// </summary>
public static partial class ImGuiComponents
namespace Dalamud.Interface.Components
{
/// <summary>
/// HelpMarker component to add a help icon with text on hover.
/// Class containing various methods providing ImGui components.
/// </summary>
/// <param name="helpText">The text to display on hover.</param>
public static void HelpMarker(string helpText)
public static partial class ImGuiComponents
{
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();
/// <summary>
/// HelpMarker component to add a help icon with text on hover.
/// </summary>
/// <param name="helpText">The text to display on hover.</param>
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();
}
}
}

View file

@ -2,100 +2,101 @@ using System.Numerics;
using ImGuiNET;
namespace Dalamud.Interface.Components;
/// <summary>
/// Class containing various methods providing ImGui components.
/// </summary>
public static partial class ImGuiComponents
namespace Dalamud.Interface.Components
{
/// <summary>
/// IconButton component to use an icon as a button.
/// Class containing various methods providing ImGui components.
/// </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>
/// <param name="id">The ID of the button.</param>
/// <param name="icon">The icon for the button.</param>
/// <returns>Indicator if button is clicked.</returns>
public static bool IconButton(int id, FontAwesomeIcon icon)
=> 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.
/// </summary>
/// <param name="id">The ID of the button.</param>
/// <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(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)
public static partial class ImGuiComponents
{
var numColors = 0;
/// <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);
if (defaultColor.HasValue)
/// <summary>
/// IconButton component to use an icon as a button.
/// </summary>
/// <param name="id">The ID of the button.</param>
/// <param name="icon">The icon for the button.</param>
/// <returns>Indicator if button is clicked.</returns>
public static bool IconButton(int id, FontAwesomeIcon icon)
=> 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.
/// </summary>
/// <param name="id">The ID of the button.</param>
/// <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(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.Value);
numColors++;
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(iconText);
ImGui.PopFont();
if (numColors > 0)
ImGui.PopStyleColor(numColors);
return button;
}
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(iconText);
ImGui.PopFont();
if (numColors > 0)
ImGui.PopStyleColor(numColors);
return button;
}
}

View file

@ -1,17 +1,18 @@
using ImGuiNET;
namespace Dalamud.Interface.Components;
/// <summary>
/// Class containing various methods providing ImGui components.
/// </summary>
public static partial class ImGuiComponents
namespace Dalamud.Interface.Components
{
/// <summary>
/// Test component to demonstrate how ImGui components work.
/// Class containing various methods providing ImGui components.
/// </summary>
public static void Test()
public static partial class ImGuiComponents
{
ImGui.Text("You are viewing the test component. The test was a success.");
/// <summary>
/// Test component to demonstrate how ImGui components work.
/// </summary>
public static void Test()
{
ImGui.Text("You are viewing the test component. The test was a success.");
}
}
}

View file

@ -1,30 +1,31 @@
using ImGuiNET;
namespace Dalamud.Interface.Components;
/// <summary>
/// Class containing various methods providing ImGui components.
/// </summary>
public static partial class ImGuiComponents
namespace Dalamud.Interface.Components
{
/// <summary>
/// TextWithLabel component to show labeled text.
/// Class containing various methods providing ImGui components.
/// </summary>
/// <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 partial class ImGuiComponents
{
ImGui.Text(label + ": ");
ImGui.SameLine();
if (string.IsNullOrEmpty(hint))
/// <summary>
/// TextWithLabel component to show labeled text.
/// </summary>
/// <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 = "")
{
ImGui.Text(value);
}
else
{
ImGui.Text(value + "*");
if (ImGui.IsItemHovered()) ImGui.SetTooltip(hint);
ImGui.Text(label + ": ");
ImGui.SameLine();
if (string.IsNullOrEmpty(hint))
{
ImGui.Text(value);
}
else
{
ImGui.Text(value + "*");
if (ImGui.IsItemHovered()) ImGui.SetTooltip(hint);
}
}
}
}

View file

@ -1,8 +1,9 @@
namespace Dalamud.Interface.Components;
/// <summary>
/// Class containing various methods providing ImGui components.
/// </summary>
public static partial class ImGuiComponents
namespace Dalamud.Interface.Components
{
/// <summary>
/// Class containing various methods providing ImGui components.
/// </summary>
public static partial class ImGuiComponents
{
}
}