feat(settings): add Window tab with layout/opacity/resize
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
|
||||
namespace HellionChat.Ui.Components.Settings.Tabs;
|
||||
|
||||
internal sealed class WindowTab
|
||||
{
|
||||
private readonly Plugin _plugin;
|
||||
|
||||
public WindowTab(Plugin plugin)
|
||||
{
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (ImGui.CollapsingHeader("Layout mode", ImGuiTreeNodeFlags.DefaultOpen))
|
||||
{
|
||||
// Sidebar is the v1.7.0 default; TopTabs is a v1.8.0 teaser.
|
||||
ImGui.RadioButton("Sidebar", true);
|
||||
using (ImRaii.Disabled(true))
|
||||
{
|
||||
ImGui.RadioButton("Top tabs (lands in v1.8.0)", false);
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui.CollapsingHeader("Opacity", ImGuiTreeNodeFlags.DefaultOpen))
|
||||
{
|
||||
DrawSlider(
|
||||
"Window opacity",
|
||||
() => Plugin.Config.WindowOpacity,
|
||||
v => Plugin.Config.WindowOpacity = v,
|
||||
0.1f,
|
||||
1f
|
||||
);
|
||||
DrawSlider(
|
||||
"Inactive opacity",
|
||||
() => Plugin.Config.WindowOpacityInactive,
|
||||
v => Plugin.Config.WindowOpacityInactive = v,
|
||||
0.1f,
|
||||
1f
|
||||
);
|
||||
}
|
||||
|
||||
if (ImGui.CollapsingHeader("Resize behavior", ImGuiTreeNodeFlags.DefaultOpen))
|
||||
{
|
||||
DrawToggle(
|
||||
"Allow resize",
|
||||
() => Plugin.Config.CanResize,
|
||||
v => Plugin.Config.CanResize = v
|
||||
);
|
||||
DrawSliderInt(
|
||||
"Sidebar auto-switch threshold (px)",
|
||||
() => Plugin.Config.SidebarAutoSwitchThresholdPx,
|
||||
v => Plugin.Config.SidebarAutoSwitchThresholdPx = v,
|
||||
200,
|
||||
800
|
||||
);
|
||||
}
|
||||
|
||||
if (ImGui.CollapsingHeader("Input preview"))
|
||||
{
|
||||
DrawPreviewPositionCombo();
|
||||
DrawToggle(
|
||||
"Only show preview when typing",
|
||||
() => Plugin.Config.OnlyPreviewIf,
|
||||
v => Plugin.Config.OnlyPreviewIf = v
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPreviewPositionCombo()
|
||||
{
|
||||
var current = Plugin.Config.PreviewPosition;
|
||||
var values = Enum.GetValues<PreviewPosition>();
|
||||
var labels = new string[values.Length];
|
||||
var selected = 0;
|
||||
for (var i = 0; i < values.Length; i++)
|
||||
{
|
||||
labels[i] = values[i].Name();
|
||||
if (values[i] == current)
|
||||
{
|
||||
selected = i;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.SetNextItemWidth(200);
|
||||
if (ImGui.Combo("Preview position", ref selected, labels, labels.Length))
|
||||
{
|
||||
Plugin.Config.PreviewPosition = values[selected];
|
||||
_plugin.SaveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawToggle(string label, Func<bool> get, Action<bool> set)
|
||||
{
|
||||
var current = get();
|
||||
if (ImGui.Checkbox(label, ref current))
|
||||
{
|
||||
set(current);
|
||||
_plugin.SaveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSlider(string label, Func<float> get, Action<float> set, float min, float max)
|
||||
{
|
||||
var current = get();
|
||||
ImGui.SetNextItemWidth(200);
|
||||
if (ImGui.SliderFloat(label, ref current, min, max, "%.2f"))
|
||||
{
|
||||
set(current);
|
||||
_plugin.SaveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSliderInt(string label, Func<int> get, Action<int> set, int min, int max)
|
||||
{
|
||||
var current = get();
|
||||
ImGui.SetNextItemWidth(200);
|
||||
if (ImGui.SliderInt(label, ref current, min, max, "%d"))
|
||||
{
|
||||
set(current);
|
||||
_plugin.SaveConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ internal sealed class SettingsWindow : Window
|
||||
private readonly AppearanceTab _appearance;
|
||||
private readonly GeneralTab _general;
|
||||
private readonly ChatTab _chat;
|
||||
private readonly WindowTab _window;
|
||||
|
||||
public SettingsWindow(
|
||||
Plugin plugin,
|
||||
@@ -33,6 +34,7 @@ internal sealed class SettingsWindow : Window
|
||||
AppearanceTab appearance,
|
||||
GeneralTab general,
|
||||
ChatTab chat,
|
||||
WindowTab window,
|
||||
ILoggerFactory loggerFactory
|
||||
)
|
||||
: base($"{Language.Settings_Title.Format(Plugin.PluginName)}###chat2-settings")
|
||||
@@ -46,6 +48,7 @@ internal sealed class SettingsWindow : Window
|
||||
_appearance = appearance;
|
||||
_general = general;
|
||||
_chat = chat;
|
||||
_window = window;
|
||||
_ = loggerFactory;
|
||||
|
||||
Size = new Vector2(720, 540);
|
||||
@@ -80,6 +83,9 @@ internal sealed class SettingsWindow : Window
|
||||
case "chat":
|
||||
_chat.Draw();
|
||||
break;
|
||||
case "window":
|
||||
_window.Draw();
|
||||
break;
|
||||
case "appearance":
|
||||
_appearance.Draw();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user