Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix horizontal scroll area #201

Open
wants to merge 1 commit into
base: 1.4
Choose a base branch
from
Open

Fix horizontal scroll area #201

wants to merge 1 commit into from

Conversation

sineme
Copy link

@sineme sineme commented Dec 28, 2022

fixes #157, #159 and #164

The scroll area was using cachedSize for its output rectangle capping it at the screen width. As the "Work"-tab window is not always as wide as the screen, ouput rectangle was too wide when there were many work types.

To fix this the PawnTable was extended with the property methods

  • void set_OutRect(this PawnTable, Rect)
  • Rect get_OutRect()

'fake adding' a new property that can be used to set and get the "Work"-tab window dimension instead of relying on the screen size.

MainTabWindow_WorkTab.DoWindowContents calls set_OutRect with the window dimension

public override void DoWindowContents(Rect rect) {
    Instance.Table.set_OutRect(rect);
    ...
}

and PawnTable_PawnTableOnGUI.PawnTableOnGUI calls get_OutRect to clamp the output rectangle properly

public static bool Prefix(PawnTable __instance,
                                   Vector2 position,
                                   PawnTableDef ___def,
                                   ref Vector2 ___scrollPosition)
//harmony 1.2.0.1 gives access to private fields by ___name.
{
    ...
    var outRect = __instance.get_OutRect();
    float outWidth   = outRect.width - labelWidth;
    ...
}

I think ideally PawnTable.PawnTableOnGUI's parameter would be Rect window instead of Vector2 position in the future.

fixes fluffy-mods#157, fluffy-mods#159 and fluffy-mods#164

The scroll area was using cachedSize for its output rectangle capping it at the screen width. As the "Work"-tab window is not as wide as the screen, ouput rectangle was too wide when there were many work types.

To fix this the PawnTable was extended with the property methods void set_OutRect(this PawnTable, Rect) and Rect get_OutRect() 'fake adding' a new property that can be used to set and get the "Work"-tab window dimension instead of relying on the screen size.

MainTabWindow_WorkTab.DoWindowContents calls set_OutRect with the window dimension PawnTable_PawnTableOnGUI.PawnTableOnGUI calls get_OutRect to clamp the output rectangle properly

I think ideally PawnTable.PawnTableOnGUI's parameter would be Rect window instead of Vector2 position in the future.
Doomster14 added a commit to Doomster14/WorkTab that referenced this pull request Nov 12, 2023
@JiaRG
Copy link

JiaRG commented Jul 12, 2024

The paste button of the last column does not appear when the column is expanded.
My current approach:

           ...
            var outRect = __instance.get_OutRect();
            float outWidth = outRect.width - labelWidth;
            float viewWidth = cachedSize.x - labelWidth;
            if (cachedSize.x < UI.screenWidth)
            {
                viewWidth -= 16f;
            }
           ...
            // increase height of table to accomodate scrollbar if necessary and possible.
            if (viewWidth > outWidth && cachedSize.y + 16f < UI.screenHeight)
            {
                // NOTE: this is probably optimistic about the available height, but it appears to be what vanilla uses.
                tableOutRect.height += 16f;
                viewWidth += 16f;
            }
            // Check if the table's height exceeds the screen height.  53: MainTabWindow_WorkTab.ExtraBottomSpace  16: horizontal scrollbar
            if (cachedHeightNoScrollbar + MainButtonDef.ButtonHeight + Constants.PriorityLabelSize.y + 53 + 16 > UI.screenHeight)
            {
                tableOutRect.width += 16f;
            }

Is there a better way to deal with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants