// Setup table sizes. private void SetupEffectiveSizes() { if (_effectiveUnscaledArrowLength == 0) { using var font = ImRaii.PushFont(UiBuilder.IconFont); _effectiveUnscaledArrowLength = ImGui.CalcTextSize(FontAwesomeIcon.LongArrowAltLeft.ToIconString()).X / ImGuiHelpers.GlobalScale; } _effectiveArrowLength = _effectiveUnscaledArrowLength * ImGuiHelpers.GlobalScale; _effectiveLeftTextLength = 450 * ImGuiHelpers.GlobalScale; _effectiveRightTextLength = ImGui.GetWindowSize().X - _effectiveArrowLength - _effectiveLeftTextLength; }
// Update all mod header data. Should someone change frame padding or item spacing, // or his default font, this will break, but he will just have to select a different mod to restore. private void UpdateModData() { // Name var name = $" {_mod.Name} "; if (name != _modName) { using var font = ImRaii.PushFont(_nameFont.ImFont, _nameFont.Available); _modName = name; _modNameWidth = ImGui.CalcTextSize(name).X + 2 * (ImGui.GetStyle().FramePadding.X + 2 * ImGuiHelpers.GlobalScale); } // Author var author = _mod.Author.IsEmpty ? string.Empty : $"by {_mod.Author}"; if (author != _modAuthor) { _modAuthor = author; _modAuthorWidth = ImGui.CalcTextSize(author).X; _secondRowWidth = _modAuthorWidth + _modWebsiteButtonWidth + ImGui.GetStyle().ItemSpacing.X; } // Version var version = _mod.Version.Length > 0 ? $"({_mod.Version})" : string.Empty; if (version != _modVersion) { _modVersion = version; _modVersionWidth = ImGui.CalcTextSize(version).X; } // Website if (_modWebsite != _mod.Website) { _modWebsite = _mod.Website; _websiteValid = Uri.TryCreate(_modWebsite, UriKind.Absolute, out var uriResult) && (uriResult.Scheme == Uri.UriSchemeHttps || uriResult.Scheme == Uri.UriSchemeHttp); _modWebsiteButton = _websiteValid ? "Open Website" : _modWebsite.Length == 0 ? string.Empty : $"from {_modWebsite}"; _modWebsiteButtonWidth = _websiteValid ? ImGui.CalcTextSize(_modWebsiteButton).X + 2 * ImGui.GetStyle().FramePadding.X : ImGui.CalcTextSize(_modWebsiteButton).X; _secondRowWidth = _modAuthorWidth + _modWebsiteButtonWidth + ImGui.GetStyle().ItemSpacing.X; } }
// Draw the mod name in the game font with a 2px border, centered, // with at least the width of the version space to each side. private float DrawModName() { var decidingWidth = Math.Max(_secondRowWidth, ImGui.GetWindowWidth()); var offsetWidth = (decidingWidth - _modNameWidth) / 2; var offsetVersion = _modVersion.Length > 0 ? _modVersionWidth + ImGui.GetStyle().ItemSpacing.X + ImGui.GetStyle().WindowPadding.X : 0; var offset = Math.Max(offsetWidth, offsetVersion); if (offset > 0) { ImGui.SetCursorPosX(offset); } using var color = ImRaii.PushColor(ImGuiCol.Border, Colors.MetaInfoText); using var style = ImRaii.PushStyle(ImGuiStyleVar.FrameBorderSize, 2 * ImGuiHelpers.GlobalScale); using var font = ImRaii.PushFont(_nameFont.ImFont, _nameFont.Available); ImGuiUtil.DrawTextButton(_modName, Vector2.Zero, 0); return(offset); }