From f343c97fcab1f49504c322a6f752e990306ab0a2 Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Sat, 2 Aug 2025 19:07:54 -0400 Subject: [PATCH 1/6] Cache invalidation --- src/LiveSplit.Splits/UI/Components/LabelsComponent.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/LiveSplit.Splits/UI/Components/LabelsComponent.cs b/src/LiveSplit.Splits/UI/Components/LabelsComponent.cs index 8179a77..7fb3d12 100644 --- a/src/LiveSplit.Splits/UI/Components/LabelsComponent.cs +++ b/src/LiveSplit.Splits/UI/Components/LabelsComponent.cs @@ -165,9 +165,14 @@ public void Update(IInvalidator invalidator, LiveSplitState state, float width, Cache.Restart(); Cache["ColumnsCount"] = ColumnsList.Count(); - foreach (SimpleLabel label in LabelsList) + for (int index = 0; index < LabelsList.Count; index++) { - Cache["Columns" + LabelsList.IndexOf(label) + "Text"] = label.Text; + SimpleLabel label = LabelsList[index]; + Cache["Columns" + index + "Text"] = label.Text; + if (index < ColumnWidths.Count) + { + Cache["Columns" + index + "Width"] = ColumnWidths[index]; + } } if (invalidator != null && (Cache.HasChanged || FrameCount > 1)) From 6d56ba1e6693e68b5b156f31e7d75a15d269127f Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Sat, 2 Aug 2025 21:32:34 -0400 Subject: [PATCH 2/6] Expand ColumnWidths on longer times --- .../UI/Components/SplitsComponent.cs | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs b/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs index f7e95c3..c70645f 100644 --- a/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs +++ b/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs @@ -415,6 +415,41 @@ private void CalculateColumnWidths(IRun run) ColumnWidths.Add(0f); } + TimeSpan longest_time = new TimeSpan(24, 0, 0); + TimeSpan longest_delta = new TimeSpan(0, 9, 0, 0); + foreach (ISegment split in run.Reverse()) + { + if (split.SplitTime.RealTime is TimeSpan real_time && longest_time < real_time) + { + longest_time = real_time; + } + + foreach (KeyValuePair kv in split.Comparisons) + { + if (kv.Value.RealTime is TimeSpan cmp_real_time && longest_time < cmp_real_time) + { + longest_time = cmp_real_time; + } + + if (split.SplitTime.RealTime - kv.Value.RealTime is TimeSpan real_delta) + { + if (longest_delta < real_delta) + { + longest_delta = real_delta; + } + else if (longest_delta < (- real_delta)) + { + longest_delta = - real_delta; + } + } + } + } + + int time_length = TimeFormatter.Format(longest_time).Length; + int delta_length = DeltaTimeFormatter.Format(longest_delta).Length; + float time_width = Math.Max(MeasureTimeLabel.ActualWidth, MeasureCharLabel.ActualWidth * time_length); + float delta_width = Math.Max(MeasureDeltaLabel.ActualWidth, MeasureCharLabel.ActualWidth * delta_length); + for (int i = 0; i < ColumnsList.Count(); i++) { ColumnData column = ColumnsList.ElementAt(i); @@ -422,15 +457,15 @@ private void CalculateColumnWidths(IRun run) float labelWidth = 0f; if (column.Type is ColumnType.DeltaorSplitTime or ColumnType.SegmentDeltaorSegmentTime) { - labelWidth = Math.Max(MeasureDeltaLabel.ActualWidth, MeasureTimeLabel.ActualWidth); + labelWidth = Math.Max(delta_width, time_width); } else if (column.Type is ColumnType.Delta or ColumnType.SegmentDelta) { - labelWidth = MeasureDeltaLabel.ActualWidth; + labelWidth = delta_width; } else if (column.Type is ColumnType.SplitTime or ColumnType.SegmentTime) { - labelWidth = MeasureTimeLabel.ActualWidth; + labelWidth = time_width; } else if (column.Type is ColumnType.CustomVariable) { From 09409e8f980d538b9660a516761cdf182a13fe11 Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Mon, 4 Aug 2025 19:08:47 -0400 Subject: [PATCH 3/6] initial longest time/delta zero --- src/LiveSplit.Splits/UI/Components/SplitsComponent.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs b/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs index c70645f..a461957 100644 --- a/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs +++ b/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs @@ -415,8 +415,8 @@ private void CalculateColumnWidths(IRun run) ColumnWidths.Add(0f); } - TimeSpan longest_time = new TimeSpan(24, 0, 0); - TimeSpan longest_delta = new TimeSpan(0, 9, 0, 0); + TimeSpan longest_time = TimeSpan.Zero; + TimeSpan longest_delta = TimeSpan.Zero; foreach (ISegment split in run.Reverse()) { if (split.SplitTime.RealTime is TimeSpan real_time && longest_time < real_time) From a86582322358ff48f907cb01ae7347e95e8b1b12 Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Tue, 5 Aug 2025 01:08:38 -0400 Subject: [PATCH 4/6] char_width --- src/LiveSplit.Splits/UI/Components/SplitsComponent.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs b/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs index a461957..0b2b314 100644 --- a/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs +++ b/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs @@ -415,8 +415,8 @@ private void CalculateColumnWidths(IRun run) ColumnWidths.Add(0f); } - TimeSpan longest_time = TimeSpan.Zero; - TimeSpan longest_delta = TimeSpan.Zero; + TimeSpan longest_time = new TimeSpan(24, 0, 0); + TimeSpan longest_delta = new TimeSpan(0, 9, 0, 0); foreach (ISegment split in run.Reverse()) { if (split.SplitTime.RealTime is TimeSpan real_time && longest_time < real_time) @@ -447,8 +447,9 @@ private void CalculateColumnWidths(IRun run) int time_length = TimeFormatter.Format(longest_time).Length; int delta_length = DeltaTimeFormatter.Format(longest_delta).Length; - float time_width = Math.Max(MeasureTimeLabel.ActualWidth, MeasureCharLabel.ActualWidth * time_length); - float delta_width = Math.Max(MeasureDeltaLabel.ActualWidth, MeasureCharLabel.ActualWidth * delta_length); + float char_width = MeasureTimeLabel.Text.Length > 0 ? MeasureTimeLabel.ActualWidth / MeasureTimeLabel.Text.Length : MeasureCharLabel.ActualWidth; + float time_width = Math.Max(MeasureTimeLabel.ActualWidth, char_width * time_length); + float delta_width = Math.Max(MeasureDeltaLabel.ActualWidth, char_width * delta_length); for (int i = 0; i < ColumnsList.Count(); i++) { From 1d3bc3f4ee2a6b7a4f923fd91844e09ce5fc49c2 Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Fri, 8 Aug 2025 00:36:32 -0400 Subject: [PATCH 5/6] better adjusted widths --- .../UI/Components/LabelsComponent.cs | 10 +++++----- .../UI/Components/SplitComponent.cs | 17 +++++++++++------ .../UI/Components/SplitsComponent.cs | 19 ++++++++++--------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/LiveSplit.Splits/UI/Components/LabelsComponent.cs b/src/LiveSplit.Splits/UI/Components/LabelsComponent.cs index 7fb3d12..d1da35c 100644 --- a/src/LiveSplit.Splits/UI/Components/LabelsComponent.cs +++ b/src/LiveSplit.Splits/UI/Components/LabelsComponent.cs @@ -19,7 +19,7 @@ public class LabelsComponent : IComponent public IEnumerable ColumnsList { get; set; } public IList LabelsList { get; set; } - protected List ColumnWidths { get; } + protected List<(int exLength, float exWidth, float width)> ColumnWidths { get; } public float PaddingTop => 0f; public float PaddingLeft => 0f; @@ -35,7 +35,7 @@ public class LabelsComponent : IComponent public float MinimumHeight { get; set; } public IDictionary ContextMenuControls => null; - public LabelsComponent(SplitsSettings settings, IEnumerable columns, List columnWidths) + public LabelsComponent(SplitsSettings settings, IEnumerable columns, List<(int exLength, float exWidth, float width)> columnWidths) { Settings = settings; MinimumHeight = 31; @@ -69,13 +69,13 @@ private void DrawGeneral(Graphics g, LiveSplitState state, float width, float he { while (ColumnWidths.Count < LabelsList.Count) { - ColumnWidths.Add(0f); + ColumnWidths.Add((0, 0f, 0f)); } float curX = width - 7; foreach (SimpleLabel label in LabelsList.Reverse()) { - float labelWidth = ColumnWidths[LabelsList.IndexOf(label)]; + float labelWidth = ColumnWidths[LabelsList.IndexOf(label)].width; curX -= labelWidth + 5; label.Width = labelWidth; @@ -171,7 +171,7 @@ public void Update(IInvalidator invalidator, LiveSplitState state, float width, Cache["Columns" + index + "Text"] = label.Text; if (index < ColumnWidths.Count) { - Cache["Columns" + index + "Width"] = ColumnWidths[index]; + Cache["Columns" + index + "Width"] = ColumnWidths[index].width; } } diff --git a/src/LiveSplit.Splits/UI/Components/SplitComponent.cs b/src/LiveSplit.Splits/UI/Components/SplitComponent.cs index f88773a..fda4c8e 100644 --- a/src/LiveSplit.Splits/UI/Components/SplitComponent.cs +++ b/src/LiveSplit.Splits/UI/Components/SplitComponent.cs @@ -45,7 +45,7 @@ public class SplitComponent : IComponent public IEnumerable ColumnsList { get; set; } public IList LabelsList { get; set; } - protected List ColumnWidths { get; } + protected List<(int exLength, float exWidth, float width)> ColumnWidths { get; } public float VerticalHeight { get; set; } @@ -59,7 +59,7 @@ public float HorizontalWidth public IDictionary ContextMenuControls => null; - public SplitComponent(SplitsSettings settings, IEnumerable columnsList, List columnWidths) + public SplitComponent(SplitsSettings settings, IEnumerable columnsList, List<(int exLength, float exWidth, float width)> columnWidths) { NameLabel = new SimpleLabel() { @@ -218,14 +218,15 @@ private void DrawGeneral(Graphics g, LiveSplitState state, float width, float he { while (ColumnWidths.Count < LabelsList.Count) { - ColumnWidths.Add(0f); + ColumnWidths.Add((0, 0f, 0f)); } float curX = width - 7; float nameX = width - 7; foreach (SimpleLabel label in LabelsList.Reverse()) { - float labelWidth = ColumnWidths[LabelsList.IndexOf(label)]; + int i = LabelsList.IndexOf(label); + float labelWidth = ColumnWidths[i].width; label.Width = labelWidth + 20; curX -= labelWidth + 5; @@ -239,6 +240,10 @@ private void DrawGeneral(Graphics g, LiveSplitState state, float width, float he if (!string.IsNullOrEmpty(label.Text)) { nameX = curX + labelWidth + 5 - label.ActualWidth; + if (ColumnWidths[i].exWidth < label.ActualWidth) + { + ColumnWidths[i] = (label.Text.Length, label.ActualWidth, labelWidth); + } } } @@ -507,7 +512,7 @@ protected float CalculateLabelsWidth() { if (ColumnWidths != null) { - return ColumnWidths.Sum() + (5 * ColumnWidths.Count()); + return ColumnWidths.Sum(e => e.width) + (5 * ColumnWidths.Count()); } return 0f; @@ -565,7 +570,7 @@ public void Update(IInvalidator invalidator, LiveSplitState state, float width, Cache["Columns" + index + "Color"] = label.ForeColor.ToArgb(); if (index < ColumnWidths.Count) { - Cache["Columns" + index + "Width"] = ColumnWidths[index]; + Cache["Columns" + index + "Width"] = ColumnWidths[index].width; } } diff --git a/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs b/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs index 0b2b314..32c6825 100644 --- a/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs +++ b/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs @@ -47,7 +47,7 @@ public class SplitsComponent : IComponent protected Color OldShadowsColor { get; set; } protected IEnumerable ColumnsList => Settings.ColumnsList.Select(x => x.Data); - protected List ColumnWidths { get; set; } + protected List<(int exLength, float exWidth, float width)> ColumnWidths { get; set; } public string ComponentName => "Splits"; @@ -77,7 +77,7 @@ public SplitsComponent(LiveSplitState state) visualSplitCount = Settings.VisualSplitCount; settingsSplitCount = Settings.VisualSplitCount; Settings.SplitLayoutChanged += Settings_SplitLayoutChanged; - ColumnWidths = Settings.ColumnsList.Select(_ => 0f).ToList(); + ColumnWidths = Settings.ColumnsList.Select(_ => (0, 0f, 0f)).ToList(); ScrollOffset = 0; RebuildVisualSplits(); state.ComparisonRenamed += state_ComparisonRenamed; @@ -412,11 +412,11 @@ private void CalculateColumnWidths(IRun run) { while (ColumnWidths.Count < ColumnsList.Count()) { - ColumnWidths.Add(0f); + ColumnWidths.Add((0, 0f, 0f)); } - TimeSpan longest_time = new TimeSpan(24, 0, 0); - TimeSpan longest_delta = new TimeSpan(0, 9, 0, 0); + TimeSpan longest_time = new TimeSpan(9, 0, 0); + TimeSpan longest_delta = new TimeSpan(0, 0, 59, 0); foreach (ISegment split in run.Reverse()) { if (split.SplitTime.RealTime is TimeSpan real_time && longest_time < real_time) @@ -448,8 +448,8 @@ private void CalculateColumnWidths(IRun run) int time_length = TimeFormatter.Format(longest_time).Length; int delta_length = DeltaTimeFormatter.Format(longest_delta).Length; float char_width = MeasureTimeLabel.Text.Length > 0 ? MeasureTimeLabel.ActualWidth / MeasureTimeLabel.Text.Length : MeasureCharLabel.ActualWidth; - float time_width = Math.Max(MeasureTimeLabel.ActualWidth, char_width * time_length); - float delta_width = Math.Max(MeasureDeltaLabel.ActualWidth, char_width * delta_length); + float time_width = Math.Max(MeasureTimeLabel.ActualWidth, char_width * (time_length + 1)); + float delta_width = Math.Max(MeasureDeltaLabel.ActualWidth, char_width * (delta_length + 1)); for (int i = 0; i < ColumnsList.Count(); i++) { @@ -479,10 +479,11 @@ private void CalculateColumnWidths(IRun run) } } - labelWidth = MeasureCharLabel.ActualWidth * longest_length; + float charWidth = ColumnWidths[i].exLength > 0 ? ColumnWidths[i].exWidth / ColumnWidths[i].exLength : MeasureCharLabel.ActualWidth; + labelWidth = charWidth * (longest_length + 1); } - ColumnWidths[i] = labelWidth; + ColumnWidths[i] = (ColumnWidths[i].exLength, ColumnWidths[i].exWidth, labelWidth); } } } From 0016b07f88d62a5d67191922bd48b572e039b356 Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Sat, 23 Aug 2025 13:07:33 -0400 Subject: [PATCH 6/6] snake_case -> camelCase --- .../UI/Components/SplitsComponent.cs | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs b/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs index 32c6825..3a9bacf 100644 --- a/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs +++ b/src/LiveSplit.Splits/UI/Components/SplitsComponent.cs @@ -415,41 +415,41 @@ private void CalculateColumnWidths(IRun run) ColumnWidths.Add((0, 0f, 0f)); } - TimeSpan longest_time = new TimeSpan(9, 0, 0); - TimeSpan longest_delta = new TimeSpan(0, 0, 59, 0); + TimeSpan longestTime = new TimeSpan(9, 0, 0); + TimeSpan longestDelta = new TimeSpan(0, 0, 59, 0); foreach (ISegment split in run.Reverse()) { - if (split.SplitTime.RealTime is TimeSpan real_time && longest_time < real_time) + if (split.SplitTime.RealTime is TimeSpan splitRealTime && longestTime < splitRealTime) { - longest_time = real_time; + longestTime = splitRealTime; } foreach (KeyValuePair kv in split.Comparisons) { - if (kv.Value.RealTime is TimeSpan cmp_real_time && longest_time < cmp_real_time) + if (kv.Value.RealTime is TimeSpan cmpRealTime && longestTime < cmpRealTime) { - longest_time = cmp_real_time; + longestTime = cmpRealTime; } - if (split.SplitTime.RealTime - kv.Value.RealTime is TimeSpan real_delta) + if (split.SplitTime.RealTime - kv.Value.RealTime is TimeSpan deltaRealTime) { - if (longest_delta < real_delta) + if (longestDelta < deltaRealTime) { - longest_delta = real_delta; + longestDelta = deltaRealTime; } - else if (longest_delta < (- real_delta)) + else if (longestDelta < (- deltaRealTime)) { - longest_delta = - real_delta; + longestDelta = - deltaRealTime; } } } } - int time_length = TimeFormatter.Format(longest_time).Length; - int delta_length = DeltaTimeFormatter.Format(longest_delta).Length; - float char_width = MeasureTimeLabel.Text.Length > 0 ? MeasureTimeLabel.ActualWidth / MeasureTimeLabel.Text.Length : MeasureCharLabel.ActualWidth; - float time_width = Math.Max(MeasureTimeLabel.ActualWidth, char_width * (time_length + 1)); - float delta_width = Math.Max(MeasureDeltaLabel.ActualWidth, char_width * (delta_length + 1)); + int timeLength = TimeFormatter.Format(longestTime).Length; + int deltaLength = DeltaTimeFormatter.Format(longestDelta).Length; + float timeCharWidth = MeasureTimeLabel.Text.Length > 0 ? MeasureTimeLabel.ActualWidth / MeasureTimeLabel.Text.Length : MeasureCharLabel.ActualWidth; + float timeWidth = Math.Max(MeasureTimeLabel.ActualWidth, timeCharWidth * (timeLength + 1)); + float deltaWidth = Math.Max(MeasureDeltaLabel.ActualWidth, timeCharWidth * (deltaLength + 1)); for (int i = 0; i < ColumnsList.Count(); i++) { @@ -458,29 +458,29 @@ private void CalculateColumnWidths(IRun run) float labelWidth = 0f; if (column.Type is ColumnType.DeltaorSplitTime or ColumnType.SegmentDeltaorSegmentTime) { - labelWidth = Math.Max(delta_width, time_width); + labelWidth = Math.Max(deltaWidth, timeWidth); } else if (column.Type is ColumnType.Delta or ColumnType.SegmentDelta) { - labelWidth = delta_width; + labelWidth = deltaWidth; } else if (column.Type is ColumnType.SplitTime or ColumnType.SegmentTime) { - labelWidth = time_width; + labelWidth = timeWidth; } else if (column.Type is ColumnType.CustomVariable) { - int longest_length = run.Metadata.CustomVariableValue(column.Name).Length; + int longestLength = run.Metadata.CustomVariableValue(column.Name).Length; foreach (ISegment split in run) { if (split.CustomVariableValues.TryGetValue(column.Name, out string value) && !string.IsNullOrEmpty(value)) { - longest_length = Math.Max(longest_length, value.Length); + longestLength = Math.Max(longestLength, value.Length); } } - float charWidth = ColumnWidths[i].exLength > 0 ? ColumnWidths[i].exWidth / ColumnWidths[i].exLength : MeasureCharLabel.ActualWidth; - labelWidth = charWidth * (longest_length + 1); + float exCharWidth = ColumnWidths[i].exLength > 0 ? ColumnWidths[i].exWidth / ColumnWidths[i].exLength : MeasureCharLabel.ActualWidth; + labelWidth = exCharWidth * (longestLength + 1); } ColumnWidths[i] = (ColumnWidths[i].exLength, ColumnWidths[i].exWidth, labelWidth);