Skip to content

icon: Support SVG bytes in component icon slots - #2980

Merged
huacnlee merged 1 commit into
longbridge:mainfrom
suxiaoshao:codex/2961-icon-svg-bytes
Sep 6, 2026
Merged

icon: Support SVG bytes in component icon slots#2980
huacnlee merged 1 commit into
longbridge:mainfrom
suxiaoshao:codex/2961-icon-svg-bytes

Conversation

@suxiaoshao

Copy link
Copy Markdown
Contributor

Closes #2961

Description

Custom SVG bytes can now be passed to existing component icon slots with Icon::data(&[u8]), without registering an asset path. The last .path() or .data() call selects the source, and existing IconNamed implementations and component conversion APIs remain compatible.

Icon sources and transformations are stored as cloneable configuration shared by both render paths. Native menus on macOS and Windows also resolve byte-backed icons. The change includes focused regression tests, Icon and NativeMenu Story examples, and English/Chinese documentation.

Screenshot

No screenshots attached. The macOS Icon Story was checked in a real window: byte-backed icons, rotated clones and entity views, custom loading icons, and button/dropdown-menu feedback. The new native-menu item was opened and selected; its OS popup image was not captured by the screenshot tool.

Breaking Changes

None. This is an additive API; existing path-based usage remains supported. Applications may opt into embedded bytes:

-Button::new("search").icon(Icon::default().path("icons/search.svg"))
+Button::new("search").icon(Icon::default().data(include_bytes!("search.svg")))

data copies its input into shared storage, and cloning an Icon shares those bytes. GPUI may copy the data again during rendering; this does not promise zero-copy rendering or binary-size savings.

How to Test

Passed locally on macOS:

  • cargo test --locked --workspace --exclude gpui-shell --features gpui-component-story/test-support
  • cargo test --locked -p gpui-component --doc (3 passed, 30 ignored)
  • cargo test --locked -p gpui-component --lib icon (18 passed)
  • Clippy for the changed component and Story targets with warnings denied; targeted rustfmt, typos, and git diff --check.
  • Markdown parsing, local-link validation, and matching new English/Chinese code examples.

To inspect the examples, run cargo run --locked -p gpui-component-story -- Icon, then open NativeMenu and select Search (SVG bytes).

Windows/Linux runtime checks and the full website build have not been run locally and remain for CI/maintainer validation.

AI Assistance

Codex assisted with the implementation, regression tests, Story examples, documentation, and this PR description. Automated checks and agent-driven UI checks are reported above; human review and testing remain for the contributor/maintainers.

Checklist

  • Read the CONTRIBUTING document and repository design/coding guides.
  • Human review and testing of the AI-assisted changes completed.
  • Passed cargo run for the related Story examples on macOS.
  • Tested macOS, Windows and Linux platform performance.

@huacnlee
huacnlee merged commit 4475eeb into longbridge:main Sep 6, 2026
9 checks passed
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.

Icon: Support SVG bytes in component icon slots

2 participants