Make scale methods in Frame generic over f32 and Vector
This commit is contained in:
parent
1f263051b6
commit
09965b686e
5 changed files with 19 additions and 11 deletions
|
|
@ -550,7 +550,7 @@ mod grid {
|
||||||
frame.translate(center);
|
frame.translate(center);
|
||||||
frame.scale(self.scaling);
|
frame.scale(self.scaling);
|
||||||
frame.translate(self.translation);
|
frame.translate(self.translation);
|
||||||
frame.scale(Cell::SIZE as f32);
|
frame.scale(Cell::SIZE);
|
||||||
|
|
||||||
let region = self.visible_region(frame.size());
|
let region = self.visible_region(frame.size());
|
||||||
|
|
||||||
|
|
@ -576,7 +576,7 @@ mod grid {
|
||||||
frame.translate(center);
|
frame.translate(center);
|
||||||
frame.scale(self.scaling);
|
frame.scale(self.scaling);
|
||||||
frame.translate(self.translation);
|
frame.translate(self.translation);
|
||||||
frame.scale(Cell::SIZE as f32);
|
frame.scale(Cell::SIZE);
|
||||||
|
|
||||||
frame.fill_rectangle(
|
frame.fill_rectangle(
|
||||||
Point::new(cell.j as f32, cell.i as f32),
|
Point::new(cell.j as f32, cell.i as f32),
|
||||||
|
|
@ -630,7 +630,7 @@ mod grid {
|
||||||
frame.translate(center);
|
frame.translate(center);
|
||||||
frame.scale(self.scaling);
|
frame.scale(self.scaling);
|
||||||
frame.translate(self.translation);
|
frame.translate(self.translation);
|
||||||
frame.scale(Cell::SIZE as f32);
|
frame.scale(Cell::SIZE);
|
||||||
|
|
||||||
let region = self.visible_region(frame.size());
|
let region = self.visible_region(frame.size());
|
||||||
let rows = region.rows();
|
let rows = region.rows();
|
||||||
|
|
@ -834,7 +834,7 @@ mod grid {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cell {
|
impl Cell {
|
||||||
const SIZE: usize = 20;
|
const SIZE: u16 = 20;
|
||||||
|
|
||||||
fn at(position: Point) -> Cell {
|
fn at(position: Point) -> Cell {
|
||||||
let i = (position.y / Cell::SIZE as f32).ceil() as isize;
|
let i = (position.y / Cell::SIZE as f32).ceil() as isize;
|
||||||
|
|
|
||||||
|
|
@ -170,13 +170,13 @@ impl Frame {
|
||||||
|
|
||||||
/// Applies a uniform scaling to the current transform of the [`Frame`].
|
/// Applies a uniform scaling to the current transform of the [`Frame`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn scale(&mut self, scale: f32) {
|
pub fn scale(&mut self, scale: impl Into<f32>) {
|
||||||
delegate!(self, frame, frame.scale(scale));
|
delegate!(self, frame, frame.scale(scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a non-uniform scaling to the current transform of the [`Frame`].
|
/// Applies a non-uniform scaling to the current transform of the [`Frame`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn scale_nonuniform(&mut self, scale: Vector) {
|
pub fn scale_nonuniform(&mut self, scale: impl Into<Vector>) {
|
||||||
delegate!(self, frame, frame.scale_nonuniform(scale));
|
delegate!(self, frame, frame.scale_nonuniform(scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,11 +154,15 @@ impl Frame {
|
||||||
.pre_concat(tiny_skia::Transform::from_rotate(angle.to_degrees()));
|
.pre_concat(tiny_skia::Transform::from_rotate(angle.to_degrees()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scale(&mut self, scale: f32) {
|
pub fn scale(&mut self, scale: impl Into<f32>) {
|
||||||
|
let scale = scale.into();
|
||||||
|
|
||||||
self.scale_nonuniform(Vector { x: scale, y: scale });
|
self.scale_nonuniform(Vector { x: scale, y: scale });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scale_nonuniform(&mut self, scale: Vector) {
|
pub fn scale_nonuniform(&mut self, scale: impl Into<Vector>) {
|
||||||
|
let scale = scale.into();
|
||||||
|
|
||||||
self.transform = self.transform.pre_scale(scale.x, scale.y);
|
self.transform = self.transform.pre_scale(scale.x, scale.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -446,13 +446,17 @@ impl Frame {
|
||||||
|
|
||||||
/// Applies a uniform scaling to the current transform of the [`Frame`].
|
/// Applies a uniform scaling to the current transform of the [`Frame`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn scale(&mut self, scale: f32) {
|
pub fn scale(&mut self, scale: impl Into<f32>) {
|
||||||
|
let scale = scale.into();
|
||||||
|
|
||||||
self.scale_nonuniform(Vector { x: scale, y: scale });
|
self.scale_nonuniform(Vector { x: scale, y: scale });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a non-uniform scaling to the current transform of the [`Frame`].
|
/// Applies a non-uniform scaling to the current transform of the [`Frame`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn scale_nonuniform(&mut self, scale: Vector) {
|
pub fn scale_nonuniform(&mut self, scale: impl Into<Vector>) {
|
||||||
|
let scale = scale.into();
|
||||||
|
|
||||||
self.transforms.current.raw =
|
self.transforms.current.raw =
|
||||||
self.transforms.current.raw.pre_scale(scale.x, scale.y);
|
self.transforms.current.raw.pre_scale(scale.x, scale.y);
|
||||||
self.transforms.current.is_identity = false;
|
self.transforms.current.is_identity = false;
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ impl<'a, Message, Theme> Widget<Message, Renderer<Theme>> for QRCode<'a> {
|
||||||
let geometry =
|
let geometry =
|
||||||
self.state.cache.draw(renderer, bounds.size(), |frame| {
|
self.state.cache.draw(renderer, bounds.size(), |frame| {
|
||||||
// Scale units to cell size
|
// Scale units to cell size
|
||||||
frame.scale(f32::from(self.cell_size));
|
frame.scale(self.cell_size);
|
||||||
|
|
||||||
// Draw background
|
// Draw background
|
||||||
frame.fill_rectangle(
|
frame.fill_rectangle(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue