Skip to content

Commit

Permalink
Provide initial scroll position to item lists
Browse files Browse the repository at this point in the history
Fixes #58 at long last.
Will probably be overwritten by the UI rework anyway.
  • Loading branch information
thomotron committed Nov 3, 2022
1 parent 98b51b5 commit e809b50
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Client/Source/GUI/Windows and panels/TradeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ private VerticalFlexContainer GenerateOurOffer()
column.Add(
GenerateItemList(
itemStacks: ourOfferCache,
scrollUpdate: newScrollPos => ourOfferScrollPos = newScrollPos
scrollUpdate: newScrollPos => ourOfferScrollPos = newScrollPos,
initialScrollPos: ourOfferScrollPos
)
);
}
Expand Down Expand Up @@ -584,7 +585,8 @@ private VerticalFlexContainer GenerateTheirOffer()
column.Add(
GenerateItemList(
itemStacks: theirOfferCache,
scrollUpdate: newScrollPos => theirOfferScrollPos = newScrollPos
scrollUpdate: newScrollPos => theirOfferScrollPos = newScrollPos,
initialScrollPos: theirOfferScrollPos
)
);
}
Expand Down Expand Up @@ -694,7 +696,7 @@ private VerticalFlexContainer GenerateAvailableItems()

// Stockpile items list
column.Add(
GenerateItemList(filteredItemStacks, newScrollPos => stockpileItemsScrollPos = newScrollPos, true)
GenerateItemList(filteredItemStacks, newScrollPos => stockpileItemsScrollPos = newScrollPos, true, stockpileItemsScrollPos)
);

// Return the generated flex container
Expand All @@ -705,10 +707,10 @@ private VerticalFlexContainer GenerateAvailableItems()
/// Generates a <see cref="VerticalScrollContainer"/> containing an item list within the given container.
/// </summary>
/// <param name="itemStacks">Item stacks to draw in the list</param>
/// <param name="scrollPos">List scroll position</param>
/// <param name="scrollUpdate">Action invoked with the scroll position of the item list when it is drawn</param>
/// <param name="interactive">Whether the item counts should be modifiable by the user</param>
private VerticalScrollContainer GenerateItemList(IEnumerable<StackedThings> itemStacks, Action<Vector2> scrollUpdate, bool interactive = false)
/// <param name="initialScrollPos">Initial list scroll position</param>
private VerticalScrollContainer GenerateItemList(IEnumerable<StackedThings> itemStacks, Action<Vector2> scrollUpdate, bool interactive = false, Vector2 initialScrollPos = default)
{
// Create a new flex container as our 'column' to hold each element
VerticalFlexContainer column = new VerticalFlexContainer(0f);
Expand Down Expand Up @@ -739,7 +741,7 @@ private VerticalScrollContainer GenerateItemList(IEnumerable<StackedThings> item
}

// Return the flex container wrapped in a scroll container
return new VerticalScrollContainer(column, scrollUpdate);
return new VerticalScrollContainer(column, scrollUpdate, initialScrollPos);
}
}
}

0 comments on commit e809b50

Please sign in to comment.