-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add image dimension and file size information #21675
Add image dimension and file size information #21675
Conversation
We require contributors to sign our Contributor License Agreement, and we don't have @kaf-lamed-beyt on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
@kaf-lamed-beyt :
![]() You can take a screenshot of the image located at the following path: I don't understand why Vscode: ![]() Webstorm: ![]() |
Alright! Thank you for the feedback @Angelk90. I'll take the screenshot and share it here. Quick question though... which crate would I need to update to show this image data in the location you asked me to move it? I'm thinking this one: Perhaps, using the |
@kaf-lamed-beyt : Maybe I figured out why the size of kB = 1,000 bytes (Decimal system, preferred in commercial and in the most recent specifications). But the calculations do not work: 194,360 bytes (webstorm size) − 194,030 bytes = 330 bytes Anyway, an important point in my opinion is the convention of whether to use a
To understand where best to put this information I think you need to ask @danilo-leal. Personally I don't like the file path being visible, if it were possible from the settings I would remove it from mine. @kaf-lamed-beyt : If you can show this information for the images too that would be great. |
Oh! Now I understand the reason for the disparity in file size. So what do you recommend we use in this case @Angelk90? the binary or decimal system? We can decide to accommodate both of them though. If that's okay
cool I'll include this too. |
@danilo-leal, hi 👋🏼 any idea how I can include the image metadata in the status bar? |
@kaf-lamed-beyt : https://github.com/zed-industries/zed/blob/main/assets/settings/default.json {
"system_type": "binary"
} default {
"decimal_separator": "dot", // dot or comma
} Same thing as above. example code: fn format_size(size: u64, base: f64, units: &[&str], separator: char) -> String {
let mut size_in_units = size as f64;
let mut unit_index = 0;
while size_in_units >= base && unit_index < units.len() - 1 {
size_in_units /= base;
unit_index += 1;
}
let formatted_size = format!("{:.2}", size_in_units);
let formatted_size = match separator {
',' => formatted_size.replace('.', ","),
_ => formatted_size
};
format!("{} {}", formatted_size, units[unit_index])
}
fn format_size_decimal(size: u64, separator: char) -> String {
let units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
format_size(size, 1000.0, &units, separator)
}
fn format_size_binary(size: u64, separator: char) -> String {
let units = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
format_size(size, 1024.0, &units, separator)
} We'll have to see what the maintainers think of these choices. |
That was fast! Nice work so far!
Don't. That won't work well if someone opens multiple images side by side. Also there is very limited space in the status bar and I would very much like to see a lot more metadata (file format; color format - channels, bit depth, subsampling, etc; physical size/DPI; comment; whether the file has color profile; ...) As far as I've seen, most applications tend to put metadata in an overlay or a side bar. I think @iamnbutler is the one that should be consulted on that, as he is the main designer in the Zed team AIUI. You might want to arrange a collab call with him to decide on the UI design portion of this. |
@jansol :
Where and how?
Depending on which image the tab focus is on, information is displayed just like vscode does. However, I agree with the choice of having a side menu for file information, as xcode does. |
Thank you, @jansol!
Oh! That's good then. This is a valid reason. I'd check if the image crate can provide all these metadata you mentioned. What's the best way to reach @iamnbutler? Email? Twitter? Discord (I may need the discord handle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I prefer the VSCode style with the size and dimensions in the status bar. You can define a new status bar item in the image_viewer
crate, and then add it after the cursor position indicator here:
Lines 214 to 222 in d7ea3dd
workspace.status_bar().update(cx, |status_bar, cx| { | |
status_bar.add_left_item(diagnostic_summary, cx); | |
status_bar.add_left_item(activity_indicator, cx); | |
status_bar.add_right_item(inline_completion_button, cx); | |
status_bar.add_right_item(active_buffer_language, cx); | |
status_bar.add_right_item(active_toolchain_language, cx); | |
status_bar.add_right_item(vim_mode_indicator, cx); | |
status_bar.add_right_item(cursor_position, cx); | |
}); |
crates/image_viewer/Cargo.toml
Outdated
@@ -23,3 +23,4 @@ theme.workspace = true | |||
ui.workspace = true | |||
util.workspace = true | |||
workspace.workspace = true | |||
image = "0.25.5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's elevate this dependency, and the one in GPUI, to a workspace dependency
@mikayla-maki : what @jansol proposed cannot be done. Let's see what @iamnbutler says. |
@mikayla-maki am i on the right path? I've managed to get a UI element to render in the status bar. But, I do not think the zed/crates/project/src/image_store.rs Lines 135 to 157 in b27afc4
Perhaps, you could point me in the right direction? |
Hey, sorry I'm terrible at keeping up with activity here. My first instinct is that the bottom right of the toolbar should be used to show this metadata. In buffers, that is cursor position, selected lines, characters, etc. So for images it would make sense for it to show file size, dimensions, etc. There is the downside that @jansol mentions, that you can't do comparisons in this way. I wouldn't be opposed to us exploring other options such as overlays, but I would not put this info in the toolbar, as it is intended for controls. If we had sub-splits already (in-buffer sidebars) I would suggest adding a |
Thanks for the feedback @iamnbutler! The approach I'm taking is in line with what you mentioned here
But, I have difficulty getting the image metadata to show up there. I successfully got a UI element to render in the status(tool)bar:a placeholder. So any help, reviewing what I'm doing wrong, would be very much appreciated. If we decide to have a sub-split like you the image description you shared, where or which crates should I be focusing on for this implementation? This is my first "real" rodeo with Rust, so you'll please excuse my questions 👐🏼. Thanks! |
You'll have to figure it out if you want to ship this PR :). I'd suggest looking at the cursor position UI, and learning how it's hooked into the rest of Zed. The key trait you'll want to understand is zed/crates/go_to_line/src/cursor_position.rs Lines 212 to 232 in 2ff06ce
I'm going to mark this as a draft for now, feel free to mark it as ready once you have a new implementation utilizing the status bar working. Good luck and happy holidays! |
Thank you @mikayla-maki! I've been going through the CursorPosition implementation, actually. But, I'll go with your suggestion and approach everything carefully now. I'll make sure to mark this PR as ready when I'm set. Happy holidays! |
The standard fs crate does filesystem operations synchronously which may lead to blocking the main thread when trying to access the image metadata, specifically fs.metadata to obtain the file size. This PR addresses that issue, and also renders other image information like the dimensions (width & height), and the image type (PNG|JPG etc)
Out of 19 failures previously, now it is 1 failure. Good, good! @mikayla-maki... the image store test still fails. See the CI output Summary [ 137.050s] 1545 tests run: 1544 passed (3 slow), 1 failed, 0 skipped
FAIL [ 0.350s] project image_store::tests::test_image_not_loaded_twice And here's what pub fn init_test(cx: &mut TestAppContext) {
if std::env::var("RUST_LOG").is_ok() {
env_logger::try_init().ok();
}
cx.update(|cx| {
let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store);
language::init(cx);
Project::init_settings(cx);
image_viewer::init(cx);
});
} |
@kaf-lamed-beyt You can run that test locally and see what the error is with cargo. |
alright, i'll do this now |
Hi @mikayla-maki, I think it's still the same issue from before My bad! I used what you suggested now, instead of error[E0425]: cannot find function `open_test_db` in crate `$crate`
--> crates/image_viewer/src/image_viewer.rs:378:5
|
378 | / define_connection! {
379 | | pub static ref IMAGE_VIEWER: ImageViewerDb<WorkspaceDb> =
380 | | &[sql!(
381 | | CREATE TABLE image_viewers (
... |
391 | | )];
392 | | }
| |_____^ help: a function with a similar name exists: `open_main_db`
|
::: /oss/zed/crates/db/src/db.rs:76:1
|
76 | async fn open_main_db<M: Migrator>(db_path: &Path) -> Option<ThreadSafeConnection<M>...
| ------------------------------------------------------------------------------------- similarly named function `open_main_db` defined here
|
note: found an item that was configured out
--> /oss/zed/crates/db/src/db.rs:99:14
|
99 | pub async fn open_test_db<M: Migrator>(db_name: &str) -> ThreadSaf...
| ^^^^^^^^^^^^
note: the item is gated here
--> /oss/zed/crates/db/src/db.rs:98:1
|
98 | #[cfg(any(test, feature = "test-support"))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the macro `define_connection` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0425`.
error: could not compile `image_viewer` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish... |
So @mikayla-maki, two things; I realized — after looking at the error closely — that the I pushed a commit just now, so i think the CI should pass now @iamnbutler But, doing this: cargo test -p project test_image_not_loaded_twice --features test-support led to this: Finished `test` profile [unoptimized + debuginfo] target(s) in 3.08s
Running unittests src/project.rs (target/debug/deps/project-71c130b4fc529ae4)
running 1 test
test image_store::tests::test_image_not_loaded_twice ... FAILED
failures:
---- image_store::tests::test_image_not_loaded_twice stdout ----
thread 'image_store::tests::test_image_not_loaded_twice' panicked at crates/project/src/image_store.rs:830:34:
called `Result::unwrap()` on an `Err` value: File does not exist at path: "/root/image_1.png"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
image_store::tests::test_image_not_loaded_twice
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 81 filtered out; finished in 0.77s
error: test failed, to rerun pass `-p project --lib` dunno if it is expected or not. |
@iamnbutler, same error from the CI ──── STDERR: project image_store::tests::test_image_not_loaded_twice
thread 'image_store::tests::test_image_not_loaded_twice' panicked at crates/project/src/image_store.rs:830:34:
called `Result::unwrap()` on an `Err` value: File does not exist at path: "/root/image_1.png" I don't think I need to have |
Closes #21281
@jansol, kindly take a look when you're free.
Release Notes: