Introduce with_transformation to Renderer trait
This commit is contained in:
parent
a6e91d13d5
commit
f4d6648601
31 changed files with 161 additions and 118 deletions
|
|
@ -7,7 +7,6 @@ pub use event::Event;
|
|||
pub use program::Program;
|
||||
|
||||
pub use crate::graphics::geometry::*;
|
||||
pub use crate::graphics::Transformation;
|
||||
pub use crate::renderer::geometry::*;
|
||||
|
||||
use crate::core;
|
||||
|
|
@ -16,7 +15,7 @@ use crate::core::mouse;
|
|||
use crate::core::renderer;
|
||||
use crate::core::widget::tree::{self, Tree};
|
||||
use crate::core::{
|
||||
Clipboard, Element, Length, Rectangle, Shell, Size, Vector, Widget,
|
||||
Clipboard, Element, Length, Rectangle, Shell, Size, Transformation, Widget,
|
||||
};
|
||||
use crate::graphics::geometry;
|
||||
|
||||
|
|
@ -208,8 +207,8 @@ where
|
|||
|
||||
let state = tree.state.downcast_ref::<P::State>();
|
||||
|
||||
renderer.with_translation(
|
||||
Vector::new(bounds.x, bounds.y),
|
||||
renderer.with_transformation(
|
||||
Transformation::translate(bounds.x, bounds.y),
|
||||
|renderer| {
|
||||
renderer.draw(
|
||||
self.program.draw(state, renderer, theme, bounds, cursor),
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::core::renderer;
|
|||
use crate::core::widget::tree::{self, Tree};
|
||||
use crate::core::{
|
||||
Clipboard, Element, Layout, Length, Pixels, Point, Rectangle, Shell, Size,
|
||||
Vector, Widget,
|
||||
Transformation, Vector, Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
|
|
@ -328,18 +328,21 @@ where
|
|||
};
|
||||
|
||||
renderer.with_layer(bounds, |renderer| {
|
||||
renderer.with_translation(translation, |renderer| {
|
||||
image::Renderer::draw(
|
||||
renderer,
|
||||
self.handle.clone(),
|
||||
self.filter_method,
|
||||
Rectangle {
|
||||
x: bounds.x,
|
||||
y: bounds.y,
|
||||
..Rectangle::with_size(image_size)
|
||||
},
|
||||
);
|
||||
});
|
||||
renderer.with_transformation(
|
||||
Transformation::translate(translation.x, translation.y),
|
||||
|renderer| {
|
||||
image::Renderer::draw(
|
||||
renderer,
|
||||
self.handle.clone(),
|
||||
self.filter_method,
|
||||
Rectangle {
|
||||
x: bounds.x,
|
||||
y: bounds.y,
|
||||
..Rectangle::with_size(image_size)
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ use crate::core::widget;
|
|||
use crate::core::widget::tree::{self, Tree};
|
||||
use crate::core::{
|
||||
Clipboard, Element, Layout, Length, Pixels, Point, Rectangle, Shell, Size,
|
||||
Vector, Widget,
|
||||
Transformation, Vector, Widget,
|
||||
};
|
||||
|
||||
/// A collection of panes distributed using either vertical or horizontal splits
|
||||
|
|
@ -962,9 +962,11 @@ pub fn draw<Theme, Renderer, T>(
|
|||
if let Some(cursor_position) = cursor.position() {
|
||||
let bounds = layout.bounds();
|
||||
|
||||
renderer.with_translation(
|
||||
cursor_position
|
||||
- Point::new(bounds.x + origin.x, bounds.y + origin.y),
|
||||
let translation = cursor_position
|
||||
- Point::new(bounds.x + origin.x, bounds.y + origin.y);
|
||||
|
||||
renderer.with_transformation(
|
||||
Transformation::translate(translation.x, translation.y),
|
||||
|renderer| {
|
||||
renderer.with_layer(bounds, |renderer| {
|
||||
draw_pane(
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ use crate::core::mouse;
|
|||
use crate::core::renderer::{self, Renderer as _};
|
||||
use crate::core::widget::Tree;
|
||||
use crate::core::{
|
||||
Color, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
|
||||
Color, Element, Layout, Length, Point, Rectangle, Size, Transformation,
|
||||
Vector, Widget,
|
||||
};
|
||||
use crate::graphics::geometry::Renderer as _;
|
||||
use crate::Renderer;
|
||||
|
|
@ -121,9 +122,12 @@ impl<'a, Message, Theme> Widget<Message, Theme, Renderer> for QRCode<'a> {
|
|||
|
||||
let translation = Vector::new(bounds.x, bounds.y);
|
||||
|
||||
renderer.with_translation(translation, |renderer| {
|
||||
renderer.draw(vec![geometry]);
|
||||
});
|
||||
renderer.with_transformation(
|
||||
Transformation::translate(translation.x, translation.y),
|
||||
|renderer| {
|
||||
renderer.draw(vec![geometry]);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue