Rename Cursor::*_position methods in canvas

This commit is contained in:
Héctor Ramón Jiménez 2020-04-29 20:58:59 +02:00
parent 70f86f998b
commit 5d12e194f4
3 changed files with 16 additions and 17 deletions

View File

@ -110,7 +110,7 @@ mod bezier {
bounds: Rectangle, bounds: Rectangle,
cursor: Cursor, cursor: Cursor,
) -> Option<Curve> { ) -> Option<Curve> {
let cursor_position = cursor.internal_position(&bounds)?; let cursor_position = cursor.position_in(&bounds)?;
match event { match event {
Event::Mouse(mouse_event) => match mouse_event { Event::Mouse(mouse_event) => match mouse_event {
@ -210,7 +210,7 @@ mod bezier {
fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Geometry { fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Geometry {
let mut frame = Frame::new(bounds.size()); let mut frame = Frame::new(bounds.size());
if let Some(cursor_position) = cursor.internal_position(&bounds) { if let Some(cursor_position) = cursor.position_in(&bounds) {
match *self { match *self {
Pending::One { from } => { Pending::One { from } => {
let line = Path::line(from, cursor_position); let line = Path::line(from, cursor_position);

View File

@ -298,7 +298,7 @@ mod grid {
self.mouse_pressed = state == ButtonState::Pressed; self.mouse_pressed = state == ButtonState::Pressed;
} }
let cursor_position = cursor.internal_position(&bounds)?; let cursor_position = cursor.position_in(&bounds)?;
let region = self.region(bounds.size()); let region = self.region(bounds.size());
let (i, j) = self.cell_at(region, cursor_position)?; let (i, j) = self.cell_at(region, cursor_position)?;
@ -365,8 +365,7 @@ mod grid {
frame.translate(Vector::new(region.x, region.y)); frame.translate(Vector::new(region.x, region.y));
frame.scale(region.width / SIZE as f32); frame.scale(region.width / SIZE as f32);
if let Some(cursor_position) = cursor.internal_position(&bounds) if let Some(cursor_position) = cursor.position_in(&bounds) {
{
if let Some((i, j)) = self.cell_at(region, cursor_position) if let Some((i, j)) = self.cell_at(region, cursor_position)
{ {
let interaction = Path::rectangle( let interaction = Path::rectangle(
@ -397,7 +396,7 @@ mod grid {
) -> MouseCursor { ) -> MouseCursor {
let region = self.region(bounds.size()); let region = self.region(bounds.size());
match cursor.internal_position(&bounds) { match cursor.position_in(&bounds) {
Some(position) if region.contains(position) => { Some(position) if region.contains(position) => {
MouseCursor::Crosshair MouseCursor::Crosshair
} }

View File

@ -24,20 +24,20 @@ impl Cursor {
} }
} }
pub fn relative_position(&self, bounds: &Rectangle) -> Option<Point> { pub fn position_in(&self, bounds: &Rectangle) -> Option<Point> {
match self { if self.is_over(bounds) {
Cursor::Available(position) => { self.position_from(bounds.position())
Some(Point::new(position.x - bounds.x, position.y - bounds.y)) } else {
} None
_ => None,
} }
} }
pub fn internal_position(&self, bounds: &Rectangle) -> Option<Point> { pub fn position_from(&self, origin: Point) -> Option<Point> {
if self.is_over(bounds) { match self {
self.relative_position(bounds) Cursor::Available(position) => {
} else { Some(Point::new(position.x - origin.x, position.y - origin.y))
None }
Cursor::Unavailable => None,
} }
} }