# gpui: Add \`scroll_to_item_with_offset\` to \`UniformListScrollState\` \(\#35064\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/f78a1123873526bb112183033641d9077b47981c)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: f78a1123873526bb112183033641d9077b47981c

Requested commit: f78a1123873526bb112183033641d9077b47981c

Commit: f78a1123873526bb112183033641d9077b47981c

Tree: b453679c2ec8b80ab479302ef1ef6f3ea2f91810

Author: Smit Barmase

Committer: GitHub

## Message

````
gpui: Add `scroll_to_item_with_offset` to `UniformListScrollState` (#35064)

Previously we had `ScrollStrategy::ToPosition(usize)` which lets you
define the offset where you want to scroll that item to. This is the
same as `ScrollStrategy::Top` but imagine some space reserved at the
top.

This PR removes `ScrollStrategy::ToPosition` in favor of
`scroll_to_item_with_offset` which is the method to do the same. The
reason to add this method is that now not just `ScrollStrategy::Top` but
`ScrollStrategy::Center` can also uses this offset to center the item in
the remaining unreserved space.

```rs
// Before
scroll_handle.scroll_to_item(index, ScrollStrategy::ToPosition(offset));

// After
scroll_handle.scroll_to_item_with_offset(index, ScrollStrategy::Top, offset);

// New! Centers item skipping first x items
scroll_handle.scroll_to_item_with_offset(index, ScrollStrategy::Center, offset);
```

This will be useful for follow up PR.

Release Notes:

- N/A
````

## Parents

- [66acc2698aa39468ea9a0beecc8892cc57f1a91f](https://git.cafe/gitcafe/zed/commit/66acc2698aa39468ea9a0beecc8892cc57f1a91f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/f78a1123873526bb112183033641d9077b47981c?format=markdown)
