Skip to content
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

Image Zoom & Pan #306

Closed
tarkah opened this issue Apr 18, 2020 · 7 comments · Fixed by #319
Closed

Image Zoom & Pan #306

tarkah opened this issue Apr 18, 2020 · 7 comments · Fixed by #319
Labels
feature New feature or request good first issue Good for newcomers

Comments

@tarkah
Copy link
Member

tarkah commented Apr 18, 2020

I've searched here and Zulip and couldn't find any relevant discussion.

Are there plans to implement a widget to allow zooming in on an Image (past the dimensions of the parent element / application window) and panning?

@hecrj
Copy link
Member

hecrj commented Apr 20, 2020

I think a widget for this would be great.

It shouldn't be too hard:

  • Listen to mouse events on Widget::on_event. Zoom with the scroll wheel, pan by dragging.
  • Draw using a scaled Image inside a Clip primitive with the correct offset.

@hecrj hecrj added feature New feature or request good first issue Good for newcomers labels Apr 20, 2020
@tarkah
Copy link
Member Author

tarkah commented Apr 20, 2020

Yes, that'd be perfect! Hmm, I may try taking a look this week to see if this is something I could figure out.

@tarkah
Copy link
Member Author

tarkah commented Apr 22, 2020

@hecrj How would you go about "scaling" the Image? I created a widget called ImagePane that takes a State and an Image. I'm comfortable with tracking an offset / scale factor in the State when an event occurs, but I'm not familiar enough with the API to know where and how to apply that scale factor to change the dimensions of the Image. Thanks!

@tarkah
Copy link
Member Author

tarkah commented Apr 23, 2020

Even if I try to manually scale the image before passing it to ImagePane, I can't seem to set Length::Units greater than the actual dimensions for the image.

@tarkah
Copy link
Member Author

tarkah commented Apr 23, 2020

Another issue I can't seem to work around... I have panning working great when the inner image is aligned to the top left corner. If I try to align the image to the center, I can't set a negative offset to the Clip primitive to pan to the left side of the image, since the alignment pushes it negative of the ImagePane's (0,0) bounds.

I'll go ahead an open the PR so you can get your eyes on this to make it easier to see what I am referencing.

@hecrj
Copy link
Member

hecrj commented Apr 23, 2020

I wouldn't use the Image widget internally. Make the widget take an image::Handle instead, and then you should be able to directly produce an Image primitive with any bounds.

I can't set a negative offset to the Clip primitive

I see. We should probably change the Clip offset to support negative values too. I'll try to explore this.

@tarkah
Copy link
Member Author

tarkah commented Apr 23, 2020

Ahh, that's what I was missing. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants