Skip to content

Commit 294148c

Browse files
committed
Merge pull request fluffy-mods#201 from sineme/1.4
Fix horizontal scroll area
2 parents d841340 + 777f1ab commit 294148c

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using RimWorld;
2+
using RimWorld.BaseGen;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Runtime.CompilerServices;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using UnityEngine;
10+
11+
namespace WorkTab.Extensions {
12+
internal static class PawnTable_Extensions {
13+
private static ConditionalWeakTable<PawnTable, StrongBox<Rect>> outRectDictionary=new ConditionalWeakTable<PawnTable, StrongBox<Rect>>();
14+
/// <summary>
15+
/// Sets the rectangle the <see cref="PawnTable"/> is drawn in.
16+
/// </summary>
17+
/// <param name="pawnTable">The <see cref="PawnTable"/> being extended.</param>
18+
/// <param name="outRect">The rectangle the <see cref="PawnTable"/> will be drawn in.</param>
19+
internal static void set_OutRect(this PawnTable pawnTable, Rect outRect) {
20+
var value = outRectDictionary.GetValue(
21+
pawnTable,
22+
a => new StrongBox<Rect>(outRect)
23+
);
24+
value.Value = outRect;
25+
}
26+
/// <summary>
27+
/// Gets the rectangle the <see cref="PawnTable"/> will be drawn in.
28+
/// </summary>
29+
/// <param name="pawnTable">The <see cref="PawnTable"/> being extended.</param>
30+
/// <returns>The rectangle the <see cref="PawnTable"/> will be drawn in.</returns>
31+
internal static Rect get_OutRect(this PawnTable pawnTable) {
32+
return outRectDictionary.GetOrCreateValue(pawnTable).Value;
33+
}
34+
}
35+
}

Source/HarmonyPatches/PawnTable/PawnTable_PawnTableOnGUI.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using RimWorld;
99
using UnityEngine;
1010
using Verse;
11+
using WorkTab.Extensions;
1112

1213
namespace WorkTab {
1314
[HarmonyPatch(typeof(PawnTable), nameof(PawnTable.PawnTableOnGUI))]
@@ -79,7 +80,11 @@ public static bool Prefix(PawnTable __instance,
7980
// Instead, we want to limit outRect to the available view area, so a horizontal scrollbar can appear.
8081
float labelWidth = cachedColumnWidths[0];
8182
var labelCol = columns[0];
82-
float outWidth = Mathf.Min( cachedSize.x - labelWidth, UI.screenWidth - (standardWindowMargin * 2f) );
83+
// ideally this method would be called with a Rect outRect
84+
// indicating the window it is being drawn in instead
85+
// of a Vector2 position
86+
var outRect = __instance.get_OutRect();
87+
float outWidth = outRect.width - labelWidth;
8388
float viewWidth = cachedSize.x - labelWidth - 16f;
8489

8590
Rect labelHeaderRect = new Rect(

Source/PawnTable/MainTabWindow_WorkTab.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using RimWorld.Planet;
1111
using UnityEngine;
1212
using Verse;
13+
using WorkTab.Extensions;
1314
using static WorkTab.Constants;
1415
using static WorkTab.InteractionUtilities;
1516
using static WorkTab.Resources;
@@ -122,6 +123,7 @@ public static void SelectWholeDay() {
122123
}
123124

124125
public override void DoWindowContents(Rect rect) {
126+
Instance.Table.set_OutRect(rect);
125127
if (_columnsChanged) {
126128
RebuildTable();
127129
}

0 commit comments

Comments
 (0)