Add Symbol view #73

Merged
david-swift merged 1 commits from marquiskurt/adwaita-swift:main into main 2025-10-25 15:37:37 +02:00
Contributor

Steps

  • Build the project on your machine. If it does not compile, fix the errors.
  • Describe the purpose and approach of your pull request below.
  • Submit the pull request. Thank you very much for your contribution!

Purpose

Describe the problem or feature.
I needed a way to display symbolic icons that I've added to my app without trying to determine where that symbolic icon lives. While I can use a Picture to display an arbitrary image from disk, I need to know the URL beforehand, and the location for icons seems to be a bit abstracted away.

If there is a related issue, add the link.
No issue filed for this, I figured I'd just make the pull request after some sleuthing on my end.

Approach

Describe how this pull request solves the problem or adds the feature.
After browsing through the GTK documentation and libadwaita source code, I came across the Image type, which did exactly what I needed. I updated the generator to generate this type, excluding file, paintable, icon-name, and gicon and made a typealiased version called Symbol so that folks would be less confused between what an Image and a Picture was. Symbol can be initialized by providing the icon in question:

import Adwaita

struct MyView: View {
    var view: Body {
        Symbol(icon: .default(icon: .goPrevious))
            .pixelSize(64)
    }
}

I've also updated the demo page to include this with some default icons. I would've loved to also include a custom one for completeness sake, but none existed for this.

Effectively, this behaves like a SwiftUI Image with an SF Symbol instead of data.

## Steps - [x] Build the project on your machine. If it does not compile, fix the errors. - [x] Describe the purpose and approach of your pull request below. - [x] Submit the pull request. Thank you very much for your contribution! ## Purpose _Describe the problem or feature._ I needed a way to display symbolic icons that I've added to my app without trying to determine where that symbolic icon lives. While I can use a `Picture` to display an arbitrary image from disk, I need to know the URL beforehand, and the location for icons seems to be a bit abstracted away. _If there is a related issue, add the link._ No issue filed for this, I figured I'd just make the pull request after some sleuthing on my end. ## Approach _Describe how this pull request solves the problem or adds the feature._ After browsing through the GTK documentation and libadwaita source code, I came across the `Image` type, which did exactly what I needed. I updated the generator to generate this type, excluding `file`, `paintable`, `icon-name`, and `gicon` and made a typealiased version called `Symbol` so that folks would be less confused between what an `Image` and a `Picture` was. `Symbol` can be initialized by providing the icon in question: ```swift import Adwaita struct MyView: View { var view: Body { Symbol(icon: .default(icon: .goPrevious)) .pixelSize(64) } } ``` I've also updated the demo page to include this with some default icons. I would've loved to also include a custom one for completeness sake, but none existed for this. Effectively, this behaves like a SwiftUI `Image` with an SF Symbol instead of data.
marquiskurt added 1 commit 2025-10-24 05:01:16 +02:00
Add Symbol view
Some checks failed
SwiftLint / SwiftLint (pull_request) Has been cancelled
ac2dbadedb
A symbol view is used to display an symbolic icon at an arbitrary
size. It is a typealias to the Image class from GTK.
david-swift approved these changes 2025-10-25 15:37:27 +02:00
david-swift left a comment
Owner

Thank you very much for this great addition :D

Thank you very much for this great addition :D
david-swift merged commit f86e968028 into main 2025-10-25 15:37:37 +02:00
Sign in to join this conversation.
No Reviewers
No Milestone
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: aparoksha/adwaita-swift#73
No description provided.