Add draggable mod selector width.

This commit is contained in:
Ottermandias 2025-05-15 17:47:32 +02:00
parent 6ad0b4299a
commit 480942339f
3 changed files with 32 additions and 21 deletions

View file

@ -1,6 +1,7 @@
using Dalamud.Interface.ImGuiNotification; using Dalamud.Interface.ImGuiNotification;
using Newtonsoft.Json; using Newtonsoft.Json;
using OtterGui.Classes; using OtterGui.Classes;
using OtterGui.FileSystem.Selector;
using OtterGui.Services; using OtterGui.Services;
using Penumbra.Api.Enums; using Penumbra.Api.Enums;
using Penumbra.Communication; using Penumbra.Communication;
@ -23,6 +24,10 @@ public class EphemeralConfig : ISavable, IDisposable, IService
[JsonIgnore] [JsonIgnore]
private readonly ModPathChanged _modPathChanged; private readonly ModPathChanged _modPathChanged;
public float CurrentModSelectorWidth { get; set; } = 200f;
public float ModSelectorMinimumScale { get; set; } = 0.1f;
public float ModSelectorMaximumScale { get; set; } = 0.5f;
public int Version { get; set; } = Configuration.Constants.CurrentVersion; public int Version { get; set; } = Configuration.Constants.CurrentVersion;
public int LastSeenVersion { get; set; } = PenumbraChangelog.LastChangelogVersion; public int LastSeenVersion { get; set; } = PenumbraChangelog.LastChangelogVersion;
public bool DebugSeparateWindow { get; set; } = false; public bool DebugSeparateWindow { get; set; } = false;

View file

@ -131,18 +131,41 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
".7z", ".7z",
]; ];
public new void Draw(float width) public new void Draw()
{ {
_dragDrop.CreateImGuiSource("ModDragDrop", m => m.Extensions.Any(e => ValidModExtensions.Contains(e.ToLowerInvariant())), m => _dragDrop.CreateImGuiSource("ModDragDrop", m => m.Extensions.Any(e => ValidModExtensions.Contains(e.ToLowerInvariant())), m =>
{ {
ImUtf8.Text($"Dragging mods for import:\n\t{string.Join("\n\t", m.Files.Select(Path.GetFileName))}"); ImUtf8.Text($"Dragging mods for import:\n\t{string.Join("\n\t", m.Files.Select(Path.GetFileName))}");
return true; return true;
}); });
base.Draw(width); base.Draw();
if (_dragDrop.CreateImGuiTarget("ModDragDrop", out var files, out _)) if (_dragDrop.CreateImGuiTarget("ModDragDrop", out var files, out _))
_modImportManager.AddUnpack(files.Where(f => ValidModExtensions.Contains(Path.GetExtension(f.ToLowerInvariant())))); _modImportManager.AddUnpack(files.Where(f => ValidModExtensions.Contains(Path.GetExtension(f.ToLowerInvariant()))));
} }
protected override float CurrentWidth
=> _config.Ephemeral.CurrentModSelectorWidth * ImUtf8.GlobalScale;
protected override float MinimumAbsoluteRemainder
=> 550 * ImUtf8.GlobalScale;
protected override float MinimumScaling
=> _config.Ephemeral.ModSelectorMinimumScale;
protected override float MaximumScaling
=> _config.Ephemeral.ModSelectorMaximumScale;
protected override void SetSize(Vector2 size)
{
base.SetSize(size);
var adaptedSize = MathF.Round(size.X / ImUtf8.GlobalScale);
if (adaptedSize == _config.Ephemeral.CurrentModSelectorWidth)
return;
_config.Ephemeral.CurrentModSelectorWidth = adaptedSize;
_config.Ephemeral.Save();
}
public override void Dispose() public override void Dispose()
{ {
base.Dispose(); base.Dispose();
@ -651,14 +674,10 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
if (!_stateFilter.HasFlag(ModFilter.Temporary) || !_stateFilter.HasFlag(ModFilter.NotTemporary)) if (!_stateFilter.HasFlag(ModFilter.Temporary) || !_stateFilter.HasFlag(ModFilter.NotTemporary))
{ {
if (settings == null && _stateFilter.HasFlag(ModFilter.Temporary)) if (settings == null && _stateFilter.HasFlag(ModFilter.Temporary))
{
return true; return true;
}
if (settings != null && settings.IsTemporary() != _stateFilter.HasFlag(ModFilter.Temporary)) if (settings != null && settings.IsTemporary() != _stateFilter.HasFlag(ModFilter.Temporary))
{
return true; return true;
}
} }
// Handle Inheritance // Handle Inheritance

View file

@ -53,7 +53,7 @@ public class ModsTab(
{ {
try try
{ {
selector.Draw(GetModSelectorSize(config)); selector.Draw();
ImGui.SameLine(); ImGui.SameLine();
ImGui.SetCursorPosX(MathF.Round(ImGui.GetCursorPosX())); ImGui.SetCursorPosX(MathF.Round(ImGui.GetCursorPosX()));
using var group = ImRaii.Group(); using var group = ImRaii.Group();
@ -86,19 +86,6 @@ public class ModsTab(
} }
} }
/// <summary> Get the correct size for the mod selector based on current config. </summary>
public static float GetModSelectorSize(Configuration config)
{
var absoluteSize = Math.Clamp(config.ModSelectorAbsoluteSize, Configuration.Constants.MinAbsoluteSize,
Math.Min(Configuration.Constants.MaxAbsoluteSize, ImGui.GetContentRegionAvail().X - 100));
var relativeSize = config.ScaleModSelector
? Math.Clamp(config.ModSelectorScaledSize, Configuration.Constants.MinScaledSize, Configuration.Constants.MaxScaledSize)
: 0;
return MathF.Round(config.ScaleModSelector
? Math.Max(absoluteSize, relativeSize * ImGui.GetContentRegionAvail().X / 100)
: absoluteSize);
}
private void DrawRedrawLine() private void DrawRedrawLine()
{ {
if (config.HideRedrawBar) if (config.HideRedrawBar)