Skip to content

Commit

Permalink
Merge pull request fluffy-mods#201 from sineme/1.4
Browse files Browse the repository at this point in the history
Fix horizontal scroll area
  • Loading branch information
Doomster14 committed Nov 12, 2023
2 parents d841340 + 777f1ab commit 294148c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
35 changes: 35 additions & 0 deletions Source/Extensions/PawnTable_Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using RimWorld;
using RimWorld.BaseGen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace WorkTab.Extensions {
internal static class PawnTable_Extensions {
private static ConditionalWeakTable<PawnTable, StrongBox<Rect>> outRectDictionary=new ConditionalWeakTable<PawnTable, StrongBox<Rect>>();
/// <summary>
/// Sets the rectangle the <see cref="PawnTable"/> is drawn in.
/// </summary>
/// <param name="pawnTable">The <see cref="PawnTable"/> being extended.</param>
/// <param name="outRect">The rectangle the <see cref="PawnTable"/> will be drawn in.</param>
internal static void set_OutRect(this PawnTable pawnTable, Rect outRect) {
var value = outRectDictionary.GetValue(
pawnTable,
a => new StrongBox<Rect>(outRect)
);
value.Value = outRect;
}
/// <summary>
/// Gets the rectangle the <see cref="PawnTable"/> will be drawn in.
/// </summary>
/// <param name="pawnTable">The <see cref="PawnTable"/> being extended.</param>
/// <returns>The rectangle the <see cref="PawnTable"/> will be drawn in.</returns>
internal static Rect get_OutRect(this PawnTable pawnTable) {
return outRectDictionary.GetOrCreateValue(pawnTable).Value;
}
}
}
7 changes: 6 additions & 1 deletion Source/HarmonyPatches/PawnTable/PawnTable_PawnTableOnGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using RimWorld;
using UnityEngine;
using Verse;
using WorkTab.Extensions;

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

Rect labelHeaderRect = new Rect(
Expand Down
2 changes: 2 additions & 0 deletions Source/PawnTable/MainTabWindow_WorkTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using RimWorld.Planet;
using UnityEngine;
using Verse;
using WorkTab.Extensions;
using static WorkTab.Constants;
using static WorkTab.InteractionUtilities;
using static WorkTab.Resources;
Expand Down Expand Up @@ -122,6 +123,7 @@ public static void SelectWholeDay() {
}

public override void DoWindowContents(Rect rect) {
Instance.Table.set_OutRect(rect);
if (_columnsChanged) {
RebuildTable();
}
Expand Down

0 comments on commit 294148c

Please sign in to comment.