From 7d2a9008328ec1a5ba6b3ad49f715ca4d1a8ee71 Mon Sep 17 00:00:00 2001 From: kalilistic <35899782+kalilistic@users.noreply.github.com> Date: Sun, 11 Apr 2021 23:17:57 -0400 Subject: [PATCH] feat: add textwithlabel component --- .../Components/ComponentDemoWindow.cs | 6 ++++ .../ImGuiComponents.TextWithLabel.cs | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Dalamud/Interface/Components/ImGuiComponents.TextWithLabel.cs diff --git a/Dalamud/Interface/Components/ComponentDemoWindow.cs b/Dalamud/Interface/Components/ComponentDemoWindow.cs index 3751ddffa..6d5618bbd 100644 --- a/Dalamud/Interface/Components/ComponentDemoWindow.cs +++ b/Dalamud/Interface/Components/ComponentDemoWindow.cs @@ -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 Demo(string name, Action func) { return new KeyValuePair(name, func); diff --git a/Dalamud/Interface/Components/ImGuiComponents.TextWithLabel.cs b/Dalamud/Interface/Components/ImGuiComponents.TextWithLabel.cs new file mode 100644 index 000000000..feb127d2a --- /dev/null +++ b/Dalamud/Interface/Components/ImGuiComponents.TextWithLabel.cs @@ -0,0 +1,32 @@ +using ImGuiNET; + +namespace Dalamud.Interface.Components +{ + /// + /// Class containing various methods providing ImGui components. + /// + public static partial class ImGuiComponents + { + /// + /// TextWithLabel component to show labeled text. + /// + /// The label for text. + /// The text value. + /// The hint to show on hover. + 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); + } + } + } +}