Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Do not use CalcTextSize outside of Draw
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcintyre committed Jul 13, 2022
1 parent 89c309d commit 7e83be3
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions TitleEdit/TitleEditPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Dalamud.Data;
Expand All @@ -19,7 +17,6 @@
using Dalamud.Logging;
using Dalamud.Plugin;
using ImGuiNET;
using ImGuiScene;
using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json;
using SharpDX;
Expand Down Expand Up @@ -56,7 +53,7 @@ internal class TitleEditPlugin : IDalamudPlugin
private bool _fileWasCreatedRecently;
private ushort _lastTerritoryId;
private ushort[] _territoryWeathers;
private float _widestScreenName;
private float _widestScreenName = 0f;

// Import values
private TitleEditScreen _importExistsScreen;
Expand Down Expand Up @@ -214,13 +211,6 @@ private void EnumerateTitleScreenFiles()
removeList.Remove(removeList[0]);
}

foreach (var title in _titleScreens)
{
var size = ImGui.CalcTextSize(title).X;
if (size > _widestScreenName)
_widestScreenName = size;
}

// Update our selected indices because we modified the collections
_selectedTitleIndex = GetIndexOfSelectedTitle();
_selectedLogoIndex = GetIndexOfSelectedLogo();
Expand Down Expand Up @@ -719,6 +709,16 @@ private void DrawManage()
ImGui.TextColored(new Vector4(1, 0, 0, 1), $"Failed to import {_importError}. Please check the log!");
}

if (_widestScreenName == 0)
{
foreach (var title in _titleScreens)
{
var size = ImGui.CalcTextSize(title).X;
if (size > _widestScreenName)
_widestScreenName = size;
}
}

if (ImGui.CollapsingHeader("Installed Screens"))
{
var width = GuiScale(_widestScreenName + 100);
Expand Down

0 comments on commit 7e83be3

Please sign in to comment.