-
Notifications
You must be signed in to change notification settings - Fork 29
Add full-screen ImageViewer widget. Support storing original files and thumbnails in the MediaCache #443
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
base: main
Are you sure you want to change the base?
Add full-screen ImageViewer widget. Support storing original files and thumbnails in the MediaCache #443
Changes from all commits
fc81c57
da49f8f
bf3106f
2345679
ade49c8
e141b6b
a3fcb9d
c0957ee
e8dfb49
9cd54b5
e074794
2e293a4
4a091f9
15eb0a3
a519e68
094f76f
84ae954
cd9c6a4
b39788f
9058bfd
93d1d90
04d23bc
ebca9a7
adce4cf
3a7311e
d8ef44a
b97ab00
94ad1b7
0b926b0
101eb7e
ef3b29b
585b25e
f0ffb6c
4393e6e
eba8cd2
7ec8681
2bd35f9
1f29098
7ad4a3a
901597a
5bf5526
226c692
87c83e8
452e407
b4b6c07
3f0ad24
15cfc26
336a97f
bea98a8
5781a62
1dbfe3c
3bdce7a
fec50ca
af012a2
15e660d
6db0c3a
e94358a
83ac0c1
1a0d1dc
7d91225
8207a50
d95d4b8
0908831
9714b24
cc41e6f
0051f17
91b9a9f
18fca6d
a5b3f05
0f3135c
0c8fe17
3b07fee
68842c1
b072a73
90e1910
f824f99
04ee5f9
8cd8aa8
d92c318
d3169e1
c7d8f18
5dc8bf5
6785e0f
3e3f5aa
35968b0
7c403ba
484ad35
b4caac9
abc3ec4
c443aff
f383824
f1c8b3f
60ef3ff
4dc2fae
e29cae4
3a6bd09
f78eac4
d98facf
837bf11
095df00
103ea80
3225300
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
use std::sync::Arc; | ||
use crate::utils; | ||
|
||
use makepad_widgets::*; | ||
|
||
live_design! { | ||
use link::theme::*; | ||
use link::shaders::*; | ||
use link::widgets::*; | ||
|
||
use crate::shared::styles::*; | ||
use crate::shared::icon_button::RobrixIconButton; | ||
|
||
pub ImageViewer = {{ImageViewer}} { | ||
visible: false | ||
width: Fill, height: Fill | ||
align: {x: 0.5, y: 0.5} | ||
spacing: 12 | ||
flow: Overlay | ||
show_bg: true | ||
draw_bg: { | ||
color: (COLOR_IMAGE_VIEWER_BG) | ||
} | ||
|
||
<View> { | ||
align: {x: 1.0, y: 0.0} | ||
width: Fill, height: Fill | ||
close_button = <RobrixIconButton> { | ||
padding: {left: 15, right: 15} | ||
draw_icon: { | ||
svg_file: (ICON_CLOSE) | ||
color: (COLOR_CLOSE), | ||
} | ||
icon_walk: {width: 25, height: 25, margin: {left: -1, right: -1} } | ||
|
||
draw_bg: { | ||
border_color: (COLOR_CLOSE_BG), | ||
color: (COLOR_CLOSE_BG) // light red | ||
} | ||
} | ||
} | ||
|
||
image_view = <View> { | ||
padding: {top: 40, bottom: 30, left: 20, right: 20} | ||
flow: Overlay | ||
align: {x: 0.5, y: 0.5} | ||
width: Fill, height: Fill, | ||
image = <Image> { | ||
width: Fill, height: Fill, | ||
fit: Smallest, | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Live, LiveHook, Widget)] | ||
pub struct ImageViewer { | ||
#[deref] | ||
view: View, | ||
} | ||
|
||
/// Actions handled by the `ImageViewer` widget. | ||
#[derive(Clone, Debug, DefaultNone)] | ||
pub enum ImageViewerAction { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, on second thought, it might be better to completely redesign this action like so: /// Actions handled by the `ImageViewer` widget.
#[derive(Clone, Debug, DefaultNone)]
pub enum ImageViewerAction {
/// Make the ImageViewer widget visible.
Show,
/// Set the image being displayed by the ImageViewer.
SetImage(Arc<[u8]>),
None,
} Then, when you want to show the image viewer for the first time, you emit two actions:
You'd also need to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's OK but if we design it as this, we must post two actions in
|
||
/// Make the ImageViewer widget visible. | ||
Show, | ||
/// Set the image being displayed by the ImageViewer. | ||
SetImage(Arc<[u8]>), | ||
None, | ||
} | ||
|
||
impl Widget for ImageViewer { | ||
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) { | ||
self.match_event(cx, event); | ||
self.view.handle_event(cx, event, scope); | ||
} | ||
|
||
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep { | ||
self.view.draw_walk(cx, scope, walk) | ||
} | ||
} | ||
impl MatchEvent for ImageViewer { | ||
fn handle_actions(&mut self, cx: &mut Cx, actions: &Actions) { | ||
if self.view.button(id!(close_button)).clicked(actions) { | ||
self.close(cx); | ||
} | ||
|
||
for action in actions { | ||
match action.downcast_ref::<ImageViewerAction>() { | ||
Some(ImageViewerAction::Show) => { | ||
self.open(cx); | ||
} | ||
Some(ImageViewerAction::SetImage(data)) => { | ||
self.load_with_data(cx, data); | ||
} | ||
_ => {} | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl ImageViewer { | ||
fn open(&mut self, cx: &mut Cx) { | ||
self.visible = true; | ||
self.redraw(cx); | ||
} | ||
fn close(&mut self, cx: &mut Cx) { | ||
self.visible = false; | ||
self.view.image(id!(image_view.image)).set_texture(cx, None); | ||
self.redraw(cx); | ||
} | ||
fn load_with_data(&mut self, cx: &mut Cx, data: &[u8]) { | ||
let image = self.view.image(id!(image_view.image)); | ||
|
||
if let Err(e) = utils::load_png_or_jpg(&image, cx, data) { | ||
log!("Error to load image: {e}"); | ||
} else { | ||
self.view.redraw(cx); | ||
} | ||
} | ||
} |
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.
hmm, should we still call
image_set_keys()
if thethumbnail_mxc_uri
isNone
?Currently, if
thumbnail_mxc_uri
is None, themxc_uri_for_timeline
is the same as theoriginal_mxc_uri
. Why would we need to set the keys if we don't have two different URIs?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.
Of course.
Since we need to keep the correct of data structure (
BTreeMap
)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.
okay, let me rephrase. Why is that necessary? what benefit does it provide?
Please elaborate, because I don't understand why this is necessary. In my mind, if the URIs are the same, we don't need to do this separate "set_keys" step, since the single URI will be inserted into the cache later once the media content is ready.
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.
kindly answer this
Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah, it is what i did actually.
Note
set_keys
fuction, only if the entry is vacant, we insert.If occupied, it can confirm they are same URIs, we dont insert.