Skip to content

Commit 0ac3048

Browse files
committed
Calculate the required width of the first column
This prevent unnecessary/reserved width for this colum
1 parent a1a1767 commit 0ac3048

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

Yafc/Workspace/SummaryView.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
4+
using System.Numerics;
45
using Yafc.Model;
56
using Yafc.UI;
67
using YAFC.Model;
78

89
namespace Yafc {
910
public class SummaryView : ProjectPageView<Summary> {
11+
/// <summary>Some padding to have the contents of the first column not 'stick' to the rest of the UI</summary>
12+
private readonly Padding FirstColumnPadding = new Padding(1f, 1.5f, 0, 0);
13+
private static float firstColumnWidth;
14+
1015
private class SummaryScrollArea(GuiBuilder builder) : ScrollArea(DefaultHeight, builder, MainScreen.Instance.InputSystem, horizontal: true) {
1116
private static readonly float DefaultHeight = 10;
1217

@@ -16,23 +21,23 @@ private class SummaryScrollArea(GuiBuilder builder) : ScrollArea(DefaultHeight,
1621
}
1722

1823
private class SummaryTabColumn : TextDataColumn<ProjectPage> {
19-
private const float FirstColumnWidth = 14f; // About 20 'o' wide
20-
21-
public SummaryTabColumn() : base("Tab", FirstColumnWidth) {
24+
public SummaryTabColumn() : base("Tab", firstColumnWidth) {
2225
}
2326

2427
public override void BuildElement(ImGui gui, ProjectPage page) {
28+
width = firstColumnWidth;
29+
2530
if (page?.contentType != typeof(ProductionTable)) {
2631
return;
2732
}
2833

2934
using (gui.EnterGroup(new Padding(0.5f, 0.2f, 0.2f, 0.5f))) {
3035
gui.spacing = 0.2f;
3136
if (page.icon != null) {
32-
gui.BuildIcon(page.icon.icon);
37+
gui.BuildIcon(page.icon.icon, FirstColumnIconSize);
3338
}
3439
else {
35-
_ = gui.AllocateRect(0f, 1.5f);
40+
_ = gui.AllocateRect(0f, FirstColumnIconSize);
3641
}
3742

3843
gui.BuildText(page.name);
@@ -142,6 +147,7 @@ private static void SetProviderAmount(ProductionLink element, ProjectPage page,
142147
private static readonly float Epsilon = 1e-5f;
143148
private static readonly float ElementWidth = 3;
144149
private static readonly float ElementSpacing = 1;
150+
private static readonly float FirstColumnIconSize = 1.5f;
145151

146152
private struct GoodDetails {
147153
public float totalProvided;
@@ -201,12 +207,34 @@ protected override void BuildHeader(ImGui gui) {
201207
gui.allocator = RectAllocator.LeftAlign;
202208
}
203209

210+
private float CalculateFirstColumWidth(ImGui gui) {
211+
// At the least the icons should fit
212+
float width = FirstColumnIconSize;
213+
214+
foreach (Guid displayPage in project.displayPages) {
215+
ProjectPage? page = project.FindPage(displayPage);
216+
if (page?.contentType != typeof(ProductionTable)) {
217+
continue;
218+
}
219+
220+
Vector2 textSize = gui.GetTextDimensions(out _, page.name);
221+
width = MathF.Max(width, textSize.X);
222+
}
223+
224+
// Include padding to perfectly match
225+
return width + FirstColumnPadding.left + FirstColumnPadding.right;
226+
}
227+
204228
protected override void BuildContent(ImGui gui) {
205229
if (gui.BuildCheckBox("Only show issues", model.showOnlyIssues, out bool newValue)) {
206230
model.showOnlyIssues = newValue;
207231
Recalculate();
208232
}
209233

234+
if (gui.isBuilding) {
235+
firstColumnWidth = CalculateFirstColumWidth(gui);
236+
}
237+
210238
scrollArea.Build(gui);
211239
}
212240

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Date: soon
1717
- Add several right-click and keyboard shortcuts, notably Enter/Return to close most dialogs.
1818
- Add UI rebuilding itself on resize.
1919
- When opening the main window, use the same size it was when it was last closed.
20+
- Use calculated width for first column of Summary page.
2021
Bugfixes:
2122
- Fix that some pages couldn't be deleted.
2223
- Fix that returning to the Welcome Screen could break the panels in the main window.

0 commit comments

Comments
 (0)