Turn methods into helper functions in image::viewer
This commit is contained in:
parent
74ee7cca81
commit
71de341684
1 changed files with 20 additions and 26 deletions
|
|
@ -132,7 +132,7 @@ impl<'a> Viewer<'a> {
|
||||||
{
|
{
|
||||||
let (width, height) = renderer.dimensions(&self.handle);
|
let (width, height) = renderer.dimensions(&self.handle);
|
||||||
|
|
||||||
let dimensions = {
|
let (width, height) = {
|
||||||
let dimensions = (width as f32, height as f32);
|
let dimensions = (width as f32, height as f32);
|
||||||
|
|
||||||
let width_ratio = bounds.width / dimensions.0;
|
let width_ratio = bounds.width / dimensions.0;
|
||||||
|
|
@ -152,33 +152,27 @@ impl<'a> Viewer<'a> {
|
||||||
Rectangle {
|
Rectangle {
|
||||||
x: bounds.x,
|
x: bounds.x,
|
||||||
y: bounds.y,
|
y: bounds.y,
|
||||||
width: dimensions.0,
|
width,
|
||||||
height: dimensions.1,
|
height,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Cursor position relative to the [`Viewer`] bounds.
|
/// Cursor position relative to the [`Viewer`] bounds.
|
||||||
///
|
///
|
||||||
/// [`Viewer`]: struct.Viewer.html
|
/// [`Viewer`]: struct.Viewer.html
|
||||||
fn relative_cursor_position(
|
fn relative_cursor_position(
|
||||||
&self,
|
absolute_position: Point,
|
||||||
mut absolute_position: Point,
|
bounds: Rectangle,
|
||||||
bounds: Rectangle,
|
) -> Point {
|
||||||
) -> Point {
|
absolute_position - Vector::new(bounds.x, bounds.y)
|
||||||
absolute_position.x -= bounds.x;
|
}
|
||||||
absolute_position.y -= bounds.y;
|
|
||||||
absolute_position
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Center point relative to the [`Viewer`] bounds.
|
/// Center point relative to the [`Viewer`] bounds.
|
||||||
///
|
///
|
||||||
/// [`Viewer`]: struct.Viewer.html
|
/// [`Viewer`]: struct.Viewer.html
|
||||||
fn relative_center(&self, bounds: Rectangle) -> Point {
|
fn relative_center(bounds: Rectangle) -> Point {
|
||||||
let mut center = bounds.center();
|
bounds.center() - Vector::new(bounds.x, bounds.y)
|
||||||
center.x -= bounds.x;
|
|
||||||
center.y -= bounds.y;
|
|
||||||
center
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Renderer> Widget<Message, Renderer> for Viewer<'a>
|
impl<'a, Message, Renderer> Widget<Message, Renderer> for Viewer<'a>
|
||||||
|
|
@ -256,10 +250,10 @@ where
|
||||||
- 1.0;
|
- 1.0;
|
||||||
|
|
||||||
let cursor_to_center =
|
let cursor_to_center =
|
||||||
self.relative_cursor_position(
|
relative_cursor_position(
|
||||||
cursor_position,
|
cursor_position,
|
||||||
bounds,
|
bounds,
|
||||||
) - self.relative_center(bounds);
|
) - relative_center(bounds);
|
||||||
|
|
||||||
let adjustment = cursor_to_center * factor
|
let adjustment = cursor_to_center * factor
|
||||||
+ self.state.current_offset * factor;
|
+ self.state.current_offset * factor;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue