refactor: add helper for generic vertical inputs
This commit is contained in:
parent
98b278a828
commit
bff2975e78
|
@ -152,4 +152,27 @@ internal static class ImGuiHelper {
|
|||
ImGui.BeginDisabled();
|
||||
return new OnDispose(ImGui.EndDisabled);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw an input with the label above it instead of to the side.
|
||||
/// </summary>
|
||||
/// <param name="label">Label for the input</param>
|
||||
/// <param name="drawInput">Function that draws an input and accepts an ID to be passed to the input label</param>
|
||||
/// <param name="appendId">Optional string to be appended to the string passed to <see cref="drawInput"/></param>
|
||||
/// <param name="helpTooltip">Optional string to be shown as a help tooltip next to the label</param>
|
||||
/// <returns></returns>
|
||||
internal static bool VerticalInput(string label, Func<string, bool> drawInput, string? appendId = null, string? helpTooltip = null) {
|
||||
ImGui.TextUnformatted(label);
|
||||
if (helpTooltip != null) {
|
||||
Help(helpTooltip);
|
||||
}
|
||||
|
||||
label = $"##{label}";
|
||||
if (appendId != null) {
|
||||
label += appendId;
|
||||
}
|
||||
|
||||
ImGui.SetNextItemWidth(-1);
|
||||
return drawInput(label);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,9 +124,12 @@ internal class PluginUi : IDisposable {
|
|||
ref this.Plugin.Config.HomeWorld
|
||||
);
|
||||
|
||||
ImGui.TextUnformatted("I started playing FFXIV in (year - enter 0 to omit)");
|
||||
ImGui.SetNextItemWidth(-1);
|
||||
if (ImGui.InputInt("##I started playing FFXIV in", ref this.Plugin.Config.YearStartedPlaying)) {
|
||||
if (
|
||||
ImGuiHelper.VerticalInput(
|
||||
"I started playing FFXIV in (year - enter 0 to omit)",
|
||||
id => ImGui.InputInt(id, ref this.Plugin.Config.YearStartedPlaying)
|
||||
)
|
||||
) {
|
||||
if (this.Plugin.Config.YearStartedPlaying != 0) {
|
||||
this.Plugin.Config.YearStartedPlaying = Math.Clamp(this.Plugin.Config.YearStartedPlaying, 2010, DateTime.UtcNow.Year);
|
||||
}
|
||||
|
@ -134,13 +137,15 @@ internal class PluginUi : IDisposable {
|
|||
anyChanged = true;
|
||||
}
|
||||
|
||||
ImGui.TextUnformatted("The job I most consider to be my \"main\" is");
|
||||
ImGui.SetNextItemWidth(-1);
|
||||
var jobs = this.Plugin.DataManager.GetExcelSheet<ClassJob>()!;
|
||||
var jobPreview = this.Plugin.Config.MainJob == null
|
||||
? "Unspecified"
|
||||
: jobs.GetRow(this.Plugin.Config.MainJob.Value)?.Name.RawString ?? "unknown";
|
||||
if (ImGui.BeginCombo("##main-job", jobPreview)) {
|
||||
if (
|
||||
ImGuiHelper.VerticalInput(
|
||||
"The job I most consider to be my \"main\" is",
|
||||
id => ImGui.BeginCombo(id, jobPreview))
|
||||
) {
|
||||
using var endCombo = new OnDispose(ImGui.EndCombo);
|
||||
|
||||
if (ImGui.Selectable("None", this.Plugin.Config.MainJob == null)) {
|
||||
|
|
Loading…
Reference in New Issue