-
Notifications
You must be signed in to change notification settings - Fork 27
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
When the user clicks a thumbnail image, show the full-size image in an image viewer widget #341
base: main
Are you sure you want to change the base?
Conversation
There is no close button for Image previewer. Only the button to close the entire program. |
|
robrix/src/image_viewer_modal.rs Line 15 in cd9c6a4
Line 210 in cd9c6a4
We can keep this pr open and I shall put my energies elsewhere issues, IMHO |
Right, but in general, the Matrix SDK can provide image metadata including dimensions, so you can use that as a placeholder until you download the entire image. Even if you don't know the size of the image, you can just show the thumbnail image in the ImageViewer widget until the full-size image has been fully-fetched, and then you will know the size of the full image. Regardless, it should not matter what the image's size is. The ImageViewer should be full-screen (
You're correct, the Modal widget doesn't. We can modify it, but in general, the Modal widget has lots of issues right now. Don't use the Modal widget; you can copy my
I don't understand what this means, sorry.
Yes, of course, you'll have to do it on a background thread/task. We already have the infrastructure for this. In summary, it sounds like you're a bit stuck on this, which is totally fine. Thanks for submitting your work thus far; in the future, I (or others) can help you complete the ImageViewer widget. |
I removed the spin loader in this pr while would take it back if #389 is OK. lastest fix: |
Yes, we have planned to do this for all images for a while now, just haven't gotten around to it. The general idea of offloading image decoding to a background thread has been floating around our discussions for a few months at least, and yes, we should absolutely do it -- but not just for the ImageViewer, for all images. Let's keep that as part of a separate PR though, in the future. |
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.
The design of the ImageViewer widget itself is way too complicated. We don't need a fancy BTreeMap or a MediaCache within it --- the only thing it needs to include is a simple <Image>
or <TextOrImage>
instance. This is because the actual image data (for the image that will be shown) will come from another part of the code, so we don't need to store anything within the ImageViewer
instance itself.
src/home/room_screen.rs
Outdated
match media_cache.try_get_media_or_fetch(mxc_uri.clone(), Some(MEDIA_THUMBNAIL_FORMAT.into())) { | ||
MediaCacheEntry::Loaded(data) => { | ||
|
||
let mut fetch_and_show_image_uri = |cx: &mut Cx2d, original_source: MediaSource, mxc_uri: OwnedMxcUri, image_info: Option<&ImageInfo>| { |
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.
now that we have multiple different image "sources", we need to name them more clearly. What is original_source
? Is that the source info for the full-sized image?
And then what is mxc_uri
for? We need to name them better so we know what each one means.
Same question for image_info
-- which image does that apply to?
src/home/room_screen.rs
Outdated
|
||
if let MediaSource::Plain(original_uri) = original_source { | ||
let original_thumbnail = OriginalAndThumbnail::new(original_uri, thumbnail_data); | ||
Cx::post_action(ImageViewerAction::SetData {text_or_image_uid, original_thumbnail}); |
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.
why do you need to pass in the widget UID of the TextOrImage instance? that doesn't make any sense --- there's only one ImageViewer, so this widget UID will never be of any use.
src/home/room_screen.rs
Outdated
@@ -3452,7 +3459,10 @@ fn populate_image_message_content( | |||
} | |||
}; | |||
|
|||
let mut fetch_and_show_media_source = |cx: &mut Cx2d, media_source: MediaSource, image_info: Option<&ImageInfo>| { | |||
|
|||
let mut fetch_and_show_media_source = |cx: &mut Cx2d, original_source: MediaSource, thumbnail_source: Option<MediaSource>, image_info: Option<&ImageInfo>| { |
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.
same comment here about naming the arguments.
src/home/room_screen.rs
Outdated
.and_then(|image_info| image_info.thumbnail_source) | ||
.unwrap_or(original_source); | ||
fetch_and_show_media_source(cx, media_source, image_info.as_ref()); | ||
let thumbnail_source = image_info.clone() |
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.
do we need to repeatedly (and eagerly) clone
all of the image info? That seems unnecessary. Couldn't you just pass in a reference to all of these image_info instances?
src/image_viewer.rs
Outdated
/// Key is uid of `TextOrImage`, val is the corresponded image uri and its thumbnail data. | ||
#[rust] | ||
map: BTreeMap<WidgetUid, OriginalAndThumbnail>, | ||
/// We use a standalone `MediaCache` to store the original image data. | ||
#[rust] | ||
media_cache: MediaCache, |
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.
this is a strange approach for designing this widget. It should literally just contain a single image instance (maybe a TextOrImage instead, if we want to show a loading message, which would be a good idea), and nothing else. This widget should be very simple, no need to overcomplicate it.
We don't need this weird map
or a media_cache
here at all. Including those do not make any sense, because that information is already available from the room's timeline message or user avatar that actually provided the image source.
need to refactor |
let mut fetch_and_show_image_uri = |cx: &mut Cx2d, mxc_uri: OwnedMxcUri, image_info: Option<&ImageInfo>| { | ||
match media_cache.try_get_media_or_fetch(mxc_uri.clone(), MEDIA_THUMBNAIL_FORMAT.into()) { | ||
// | ||
// I refactor those two closure here, feel free to renamed it. |
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.
@kevinaboos , Just feel free to rename this closure here.
issue 327: When the user clicks a thumbnail image, show the full-size image in an image viewer widget