Skip to content

Commit d7573ff

Browse files
authored
(minor) fixes (#31)
It is a collection of changes I made for ShadowTheAge#145 to fix various things. In order to make this (big) PR adding the summary view smaller, I moved this (and some other changed) to their own PR, before submitting the PR to add the summary view. List of improvements/fixes: * _Don't use 'weird' output of `EncapsulateRect()` as 'lastRect', but the actual rect of the (old) state_ `EncapsulateRect()` changes the returned rectangle while processing it, causing rendering issues (I forgot the details, it is ages ago) * _Improve ScrollArea class names to reflect horizontal scrolling as well, including a constructor parameter to enable horizontal scrolling_ The ScrollArea is capable of having both vertical and horizontal scrollbars. The horizontal scrollbar is never used, and was not exposed. But the summary view needs it for larger factories or the user needs an ultra, mega, super wide screen 😛 * _Renamed some variables_ For clarification * Typos and some formatting
2 parents 0f3bb1b + 11c6331 commit d7573ff

10 files changed

Lines changed: 85 additions & 84 deletions

File tree

YAFC/Widgets/ObjectTooltip.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ private void BuildRecipe(RecipeOrTechnology recipe, ImGui gui)
432432
gui.BuildText(DataUtils.FormatAmount(ingredient.amount, UnitOfMeasure.None));
433433
}
434434

435-
gui.allocator = RectAllocator.RemainigRow;
435+
gui.allocator = RectAllocator.RemainingRow;
436436
gui.BuildFactorioObjectButtonWithText(technology);
437437
}
438438
}

YAFC/Windows/DependencyExplorer.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using System.Runtime.CompilerServices;
43
using SDL2;
54
using YAFC.Model;
65
using YAFC.UI;
@@ -11,8 +10,8 @@ public class DependencyExplorer : PseudoScreen
1110
{
1211
private static readonly DependencyExplorer Instance = new DependencyExplorer();
1312

14-
private readonly VerticalScrollCustom dependencies;
15-
private readonly VerticalScrollCustom dependants;
13+
private readonly ScrollArea dependencies;
14+
private readonly ScrollArea dependants;
1615
private static readonly Padding listPad = new Padding(0.5f);
1716

1817
private readonly List<FactorioObject> history = new List<FactorioObject>();
@@ -34,8 +33,8 @@ public class DependencyExplorer : PseudoScreen
3433

3534
public DependencyExplorer() : base(60f)
3635
{
37-
dependencies = new VerticalScrollCustom(30f, DrawDependencies);
38-
dependants = new VerticalScrollCustom(30f, DrawDependants);
36+
dependencies = new ScrollArea(30f, DrawDependencies);
37+
dependants = new ScrollArea(30f, DrawDependants);
3938
}
4039

4140
public static void Show(FactorioObject target)

YAFC/Windows/ErrorListPanel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ public class ErrorListPanel : PseudoScreen
77
{
88
private static readonly ErrorListPanel Instance = new ErrorListPanel();
99
private ErrorCollector collector;
10-
private readonly VerticalScrollCustom verticalList;
10+
private readonly ScrollArea verticalList;
1111
private (string error, ErrorSeverity severity)[] errors;
1212

1313
public ErrorListPanel() : base(60f)
1414
{
15-
verticalList = new VerticalScrollCustom(30f, BuildErrorList, default, true);
15+
verticalList = new ScrollArea(30f, BuildErrorList, default, true);
1616
}
1717

1818
private void BuildErrorList(ImGui gui)

YAFC/Windows/NeverEnoughItemsPanel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public class NeverEnoughItemsPanel : PseudoScreen, IComparer<NeverEnoughItemsPan
1414
private readonly List<Goods> recent = new List<Goods>();
1515
private bool atCurrentMilestones;
1616

17-
private readonly VerticalScrollCustom productionList;
18-
private readonly VerticalScrollCustom usageList;
17+
private readonly ScrollArea productionList;
18+
private readonly ScrollArea usageList;
1919

2020
private enum EntryStatus
2121
{
@@ -62,8 +62,8 @@ public RecipeEntry(Recipe recipe, bool isProduction, Goods currentItem, bool atC
6262

6363
public NeverEnoughItemsPanel() : base(76f)
6464
{
65-
productionList = new VerticalScrollCustom(40f, BuildItemProduction, new Padding(0.5f));
66-
usageList = new VerticalScrollCustom(40f, BuildItemUsages, new Padding(0.5f));
65+
productionList = new ScrollArea(40f, BuildItemProduction, new Padding(0.5f));
66+
usageList = new ScrollArea(40f, BuildItemUsages, new Padding(0.5f));
6767
}
6868

6969
private void SetItem(Goods current)
@@ -204,7 +204,7 @@ private void DrawRecipeEntry(ImGui gui, RecipeEntry entry, bool production)
204204
if (recipe.products.Length < 3 && recipe.ingredients.Length < 5)
205205
gui.AllocateSpacing((3 - entry.recipe.products.Length) * 3f);
206206
else if (recipe.products.Length < 3)
207-
gui.allocator = RectAllocator.RemainigRow;
207+
gui.allocator = RectAllocator.RemainingRow;
208208
gui.BuildIcon(Icon.ArrowRight, 3f);
209209
}
210210
}

YAFC/Windows/WelcomeScreen.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class WelcomeScreen : WindowUtility, IProgress<(string, string)>
1818
private bool expensive;
1919
private string createText;
2020
private bool canCreate;
21-
private readonly VerticalScrollCustom errorScroll;
22-
private readonly VerticalScrollCustom recentProjectScroll;
23-
private readonly VerticalScrollCustom languageScroll;
21+
private readonly ScrollArea errorScroll;
22+
private readonly ScrollArea recentProjectScroll;
23+
private readonly ScrollArea languageScroll;
2424
private string errorMod;
2525
private string errorMessage;
2626
private string tip;
@@ -69,9 +69,9 @@ public WelcomeScreen() : base(ImGuiUtils.DefaultScreenPadding)
6969
RenderingUtils.SetColorScheme(Preferences.Instance.darkMode);
7070
var lastProject = Preferences.Instance.recentProjects.FirstOrDefault();
7171
SetProject(lastProject);
72-
errorScroll = new VerticalScrollCustom(20f, BuildError, collapsible:true);
73-
recentProjectScroll = new VerticalScrollCustom(20f, BuildRecentProjectList, collapsible:true);
74-
languageScroll = new VerticalScrollCustom(20f, LanguageSelection, collapsible: true);
72+
errorScroll = new ScrollArea(20f, BuildError, collapsible:true);
73+
recentProjectScroll = new ScrollArea(20f, BuildRecentProjectList, collapsible:true);
74+
languageScroll = new ScrollArea(20f, LanguageSelection, collapsible: true);
7575
Create("Welcome to YAFC CE v"+YafcLib.version.ToString(3), 45, null);
7676
IconCollection.ClearCustomIcons();
7777
if (tips == null)

YAFC/Workspace/ProductionTable/ProductionLinkSummaryScreen.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ public class ProductionLinkSummaryScreen : PseudoScreen, IComparer<(RecipeRow ro
1212
private readonly List<(RecipeRow row, float flow)> input = new List<(RecipeRow, float)>();
1313
private readonly List<(RecipeRow row, float flow)> output = new List<(RecipeRow, float)>();
1414
private float totalInput, totalOutput;
15-
private readonly VerticalScrollCustom scrollArea;
15+
private readonly ScrollArea scrollArea;
1616

1717
private ProductionLinkSummaryScreen()
1818
{
19-
scrollArea = new VerticalScrollCustom(30, BuildScrollArea);
19+
scrollArea = new ScrollArea(30, BuildScrollArea);
2020
}
2121

2222
private void BuildScrollArea(ImGui gui)
2323
{
24-
gui.BuildText("Production: "+DataUtils.FormatAmount(totalInput, link.goods.flowUnitOfMeasure), Font.subheader);
24+
gui.BuildText("Production: " + DataUtils.FormatAmount(totalInput, link.goods.flowUnitOfMeasure), Font.subheader);
2525
BuildFlow(gui, input, totalInput);
2626
gui.spacing = 0.5f;
27-
gui.BuildText("Consumption: "+DataUtils.FormatAmount(totalOutput, link.goods.flowUnitOfMeasure), Font.subheader);
27+
gui.BuildText("Consumption: " + DataUtils.FormatAmount(totalOutput, link.goods.flowUnitOfMeasure), Font.subheader);
2828
BuildFlow(gui, output, totalOutput);
2929
if (link.flags.HasFlags(ProductionLink.Flags.LinkNotMatched) && totalInput != totalOutput)
30-
gui.BuildText((totalInput > totalOutput ? "Overproduction: " : "Overconsumption: ") + DataUtils.FormatAmount(MathF.Abs(totalInput-totalOutput), link.goods.flowUnitOfMeasure), Font.subheader, color:SchemeColor.Error);
30+
gui.BuildText((totalInput > totalOutput ? "Overproduction: " : "Overconsumption: ") + DataUtils.FormatAmount(MathF.Abs(totalInput - totalOutput), link.goods.flowUnitOfMeasure), Font.subheader, color: SchemeColor.Error);
3131
}
3232

3333
public override void Build(ImGui gui)
@@ -71,7 +71,7 @@ private void CalculateFlow(ProductionLink link)
7171
{
7272
input.Add((recipe, localFlow));
7373
totalInput += localFlow;
74-
}
74+
}
7575
else if (localFlow < 0)
7676
{
7777
output.Add((recipe, -localFlow));

YAFCui/ImGui/ImGui.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
43
using System.Numerics;
54
using System.Runtime.CompilerServices;
65
using SDL2;
@@ -47,7 +46,7 @@ public enum RectAllocator
4746
Center,
4847
LeftRow,
4948
RightRow,
50-
RemainigRow,
49+
RemainingRow,
5150
FixedRect,
5251
HalfRow
5352
}
@@ -56,17 +55,17 @@ public enum RectAllocator
5655

5756
public sealed partial class ImGui : IDisposable, IPanel
5857
{
59-
public ImGui(GuiBuilder gui, Padding padding, RectAllocator defaultAllocator = RectAllocator.Stretch, bool clip = false)
58+
public ImGui(GuiBuilder guiBuilder, Padding padding, RectAllocator defaultAllocator = RectAllocator.Stretch, bool clip = false)
6059
{
61-
this.gui = gui;
62-
if (gui == null)
60+
this.guiBuilder = guiBuilder;
61+
if (guiBuilder == null)
6362
action = ImGuiAction.Build;
6463
this.defaultAllocator = defaultAllocator;
6564
this.clip = clip;
6665
initialPadding = padding;
6766
}
6867

69-
public readonly GuiBuilder gui;
68+
public readonly GuiBuilder guiBuilder;
7069
public Window window { get; private set; }
7170
public ImGui parent { get; private set; }
7271
IPanel IPanel.Parent => parent;

YAFCui/ImGui/ImGuiBuilding.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void Deconstruct(out Rect rect, out T data, out SchemeColor color)
2626
color = this.color;
2727
}
2828
}
29-
29+
3030
private readonly List<DrawCommand<RectangleBorder>> rects = new List<DrawCommand<RectangleBorder>>();
3131
private readonly List<DrawCommand<Icon>> icons = new List<DrawCommand<Icon>>();
3232
private readonly List<DrawCommand<IRenderable>> renderables = new List<DrawCommand<IRenderable>>();
@@ -75,10 +75,10 @@ private void ClearDrawCommandList()
7575

7676
public void ManualDrawingClear()
7777
{
78-
if (gui == null)
78+
if (guiBuilder == null)
7979
ClearDrawCommandList();
8080
}
81-
81+
8282
public readonly ImGuiCache<TextCache, (FontFile.FontSize size, string text, uint wrapWidth)>.Cache textCache = new ImGuiCache<TextCache, (FontFile.FontSize size, string text, uint wrapWidth)>.Cache();
8383

8484
public FontFile.FontSize GetFontSize(Font font = null) => (font ?? Font.text).GetFontSize(pixelsPerUnit);
@@ -108,7 +108,7 @@ public Rect AllocateTextRect(out TextCache cache, string text, Font font = null,
108108
}
109109
else
110110
{
111-
cache = textCache.GetCached((fontSize, text, wrap ? (uint) UnitsToPixels(MathF.Max(width, 5f)) : uint.MaxValue));
111+
cache = textCache.GetCached((fontSize, text, wrap ? (uint)UnitsToPixels(MathF.Max(width, 5f)) : uint.MaxValue));
112112
rect = AllocateRect(cache.texRect.w / pixelsPerUnit, topOffset + cache.texRect.h / pixelsPerUnit, align);
113113
}
114114

@@ -141,7 +141,7 @@ public bool BuildTextInput(string text, out string newText, string placeholder,
141141
textInputHelper = new ImGuiTextInputHelper(this);
142142
return textInputHelper.BuildTextInput(text, out newText, placeholder, GetFontSize(), delayed, icon, padding, alignment, color);
143143
}
144-
144+
145145
public void BuildIcon(Icon icon, float size = 1.5f, SchemeColor color = SchemeColor.None)
146146
{
147147
if (color == SchemeColor.None)
@@ -162,15 +162,15 @@ public void BuildIcon(Icon icon, float size = 1.5f, SchemeColor color = SchemeCo
162162

163163
private bool DoGui(ImGuiAction action)
164164
{
165-
if (gui == null)
165+
if (guiBuilder == null)
166166
return false;
167167
this.action = action;
168168
ResetLayout();
169169
buildingWidth = buildWidth;
170170
buildGroupsIndex = -1;
171171
using (EnterGroup(initialPadding, defaultAllocator, initialTextColor))
172172
{
173-
gui(this);
173+
guiBuilder(this);
174174
}
175175
actionParameter = 0;
176176
if (action == ImGuiAction.Build)
@@ -184,14 +184,14 @@ private bool DoGui(ImGuiAction action)
184184

185185
private void BuildGui(float width)
186186
{
187-
if (gui == null)
187+
if (guiBuilder == null)
188188
return;
189189
buildWidth = width;
190190
nextRebuildTimer = long.MaxValue;
191191
rebuildRequested = false;
192192
ClearDrawCommandList();
193193
DoGui(ImGuiAction.Build);
194-
contentSize = new Vector2(buildingWidth, lastRect.Bottom);
194+
contentSize = new Vector2(lastRect.Right, lastRect.Bottom);
195195
if (boxColor != SchemeColor.None)
196196
{
197197
var rect = new Rect(default, contentSize);
@@ -252,7 +252,7 @@ public void MouseUp(int button)
252252
SDL.SDL_SetCursor(RenderingUtils.cursorHand);
253253
cursorSetByMouseDown = false;
254254
}
255-
255+
256256
actionParameter = button;
257257
DoGui(ImGuiAction.MouseUp);
258258
}
@@ -354,7 +354,7 @@ public void SetFocus(Rect rect)
354354
mouseDownRect = rect;
355355
Rebuild();
356356
}
357-
357+
358358
public void SetTextInputFocus(Rect rect, string text)
359359
{
360360
if (textInputHelper != null && InputSystem.Instance.currentKeyboardFocus != textInputHelper)
@@ -366,7 +366,6 @@ public void SetTextInputFocus(Rect rect, string text)
366366

367367
public void SaveToImage()
368368
{
369-
370369
}
371370
}
372371
}

0 commit comments

Comments
 (0)