Skip to content

gpui: Add container_query element#60774

Merged
mikayla-maki merged 3 commits into
mainfrom
container-query-element
Jul 12, 2026
Merged

gpui: Add container_query element#60774
mikayla-maki merged 3 commits into
mainfrom
container-query-element

Conversation

@mikayla-maki

@mikayla-maki mikayla-maki commented Jul 10, 2026

Copy link
Copy Markdown
Member

Adds a container_query element to GPUI, in the spirit of CSS container queries: the element's own size is determined solely by its style and the space offered by its parent, and once that size is known the provided closure is called with the measured size to build the contents.

container_query(|size, _window, _cx| {
    if size.width < px(240.) {
        div().child("Narrow layout")
    } else {
        div().child("Wide layout")
    }
});

Implementation notes:

  • Defaults to filling its parent (size_full() semantics), overridable via Styled since contents can't influence the container's size (the same constraint CSS container queries impose).
  • Reworks the grid_layout example (the Holy Grail layout) to demonstrate it: the three-column grid collapses to a stacked column when the window is narrower than 400px, and the header shows the live measured width.

Release Notes:

  • N/A

An element whose contents are built after its own size is resolved,
using the same prepaint two-pass technique as uniform_list (no deferred
draws). Also reworks the grid_layout example to demonstrate it by
collapsing the Holy Grail layout to a stacked column when narrow.
@mikayla-maki mikayla-maki self-assigned this Jul 10, 2026
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 10, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Jul 10, 2026
@mikayla-maki mikayla-maki added this pull request to the merge queue Jul 12, 2026
Merged via the queue into main with commit 49ad06c Jul 12, 2026
34 checks passed
@mikayla-maki mikayla-maki deleted the container-query-element branch July 12, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants