gpui: Improve img element to support load from Assets (#15482)
Release Notes: - N/A Currently, the `img` element provided by GPUI only supports FilePath or URL, but in actual applications we need to let `img` load an image embedded in Assets. The `svg` element can currently support this, but `img` cannot. For example: We have such an Assets directory: ``` assets |- icons |- images |--- foo.png ``` ```rs // If give a path, considered an Asset img("images/foo.png"); // If give a URI, considered a Remote image img("https://foo.bar/images/foo.png"); // If give a PathBuf, considered a Local file img(PathBuf::from("path/to/foo.png")); ``` ## Example test ``` cargo run -p gpui --example image ``` <img width="827" alt="image" src="https://github.com/user-attachments/assets/e45dcf7f-4626-4fb0-aca9-9b6e1045a952"> --------- Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
99bc90a372
commit
1982a5aed1
3 changed files with 121 additions and 41 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::{SharedUri, WindowContext};
|
||||
use crate::{SharedString, SharedUri, WindowContext};
|
||||
use collections::FxHashMap;
|
||||
use futures::Future;
|
||||
use parking_lot::Mutex;
|
||||
|
@ -11,6 +11,7 @@ use std::{any::Any, path::PathBuf};
|
|||
pub(crate) enum UriOrPath {
|
||||
Uri(SharedUri),
|
||||
Path(Arc<PathBuf>),
|
||||
Asset(SharedString),
|
||||
}
|
||||
|
||||
impl From<SharedUri> for UriOrPath {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue