Rename Cursor::*_position
methods in canvas
This commit is contained in:
parent
70f86f998b
commit
5d12e194f4
@ -110,7 +110,7 @@ mod bezier {
|
||||
bounds: Rectangle,
|
||||
cursor: Cursor,
|
||||
) -> Option<Curve> {
|
||||
let cursor_position = cursor.internal_position(&bounds)?;
|
||||
let cursor_position = cursor.position_in(&bounds)?;
|
||||
|
||||
match event {
|
||||
Event::Mouse(mouse_event) => match mouse_event {
|
||||
@ -210,7 +210,7 @@ mod bezier {
|
||||
fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Geometry {
|
||||
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 {
|
||||
Pending::One { from } => {
|
||||
let line = Path::line(from, cursor_position);
|
||||
|
@ -298,7 +298,7 @@ mod grid {
|
||||
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 (i, j) = self.cell_at(region, cursor_position)?;
|
||||
@ -365,8 +365,7 @@ mod grid {
|
||||
frame.translate(Vector::new(region.x, region.y));
|
||||
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)
|
||||
{
|
||||
let interaction = Path::rectangle(
|
||||
@ -397,7 +396,7 @@ mod grid {
|
||||
) -> MouseCursor {
|
||||
let region = self.region(bounds.size());
|
||||
|
||||
match cursor.internal_position(&bounds) {
|
||||
match cursor.position_in(&bounds) {
|
||||
Some(position) if region.contains(position) => {
|
||||
MouseCursor::Crosshair
|
||||
}
|
||||
|
@ -24,20 +24,20 @@ impl Cursor {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn relative_position(&self, bounds: &Rectangle) -> Option<Point> {
|
||||
match self {
|
||||
Cursor::Available(position) => {
|
||||
Some(Point::new(position.x - bounds.x, position.y - bounds.y))
|
||||
}
|
||||
_ => None,
|
||||
pub fn position_in(&self, bounds: &Rectangle) -> Option<Point> {
|
||||
if self.is_over(bounds) {
|
||||
self.position_from(bounds.position())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn internal_position(&self, bounds: &Rectangle) -> Option<Point> {
|
||||
if self.is_over(bounds) {
|
||||
self.relative_position(bounds)
|
||||
} else {
|
||||
None
|
||||
pub fn position_from(&self, origin: Point) -> Option<Point> {
|
||||
match self {
|
||||
Cursor::Available(position) => {
|
||||
Some(Point::new(position.x - origin.x, position.y - origin.y))
|
||||
}
|
||||
Cursor::Unavailable => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user