# gpui: Fix anchored element size calculation with negative coordinates \(\#55124\) · gitcafe/zed

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

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

Visibility: public

Requested revision: b38194198b3da945b01fbb2739d91a23a0da71e0

Requested commit: b38194198b3da945b01fbb2739d91a23a0da71e0

Commit: b38194198b3da945b01fbb2739d91a23a0da71e0

Tree: a77ff169fc6b31a0e01b061a494d3e92d651f52f

Author: Agus Zubiaga

Committer: GitHub

## Message

```
gpui: Fix anchored element size calculation with negative coordinates (#55124)

Closes #53202 

`Anchored::prepaint` computes the bounding box of its children to
determine the size used for fitting the anchored element in the window.

Previously, this calculation manually tracked the minimum origin and
maximum bottom-right point, initializing the maximum point to `(0, 0)`.
If child bounds were in negative coordinates, the maximum point could be
clamped to `(0, 0)`, inflating the computed size.

This replaces the manual min/max accumulation with `Bounds::union`,
starting from the actual child bounds instead of sentinel values. This
computes the child bounding box correctly regardless of coordinate sign.

---

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed a bug where the context menu in the agent panel (and other
scrollable surfaces) would appear at the wrong location
```

## Parents

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

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