feat: add textwithlabel component

This commit is contained in:
kalilistic 2021-04-11 23:17:57 -04:00
parent e5d89b2c32
commit 7d2a900832
2 changed files with 38 additions and 0 deletions

View file

@ -27,6 +27,7 @@ namespace Dalamud.Interface.Components
Demo("Test", ImGuiComponents.Test),
Demo("HelpMarker", HelpMarkerDemo),
Demo("IconButton", IconButtonDemo),
Demo("TextWithLabel", TextWithLabelDemo),
};
}
@ -72,6 +73,11 @@ namespace Dalamud.Interface.Components
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);

View file

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