11using System ;
22using System . Collections . Generic ;
33using System . Diagnostics . CodeAnalysis ;
4+ using System . Numerics ;
45using Yafc . Model ;
56using Yafc . UI ;
67using YAFC . Model ;
78
89namespace 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
0 commit comments