Introduce with_transformation to Renderer trait

This commit is contained in:
Héctor Ramón Jiménez 2023-10-24 05:34:03 +02:00
parent a6e91d13d5
commit f4d6648601
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
31 changed files with 161 additions and 118 deletions

View file

@ -12,6 +12,7 @@ keywords.workspace = true
[dependencies] [dependencies]
bitflags.workspace = true bitflags.workspace = true
glam.workspace = true
log.workspace = true log.workspace = true
num-traits.workspace = true num-traits.workspace = true
smol_str.workspace = true smol_str.workspace = true

View file

@ -49,6 +49,7 @@ mod rectangle;
mod shadow; mod shadow;
mod shell; mod shell;
mod size; mod size;
mod transformation;
mod vector; mod vector;
pub use alignment::Alignment; pub use alignment::Alignment;
@ -75,6 +76,7 @@ pub use shadow::Shadow;
pub use shell::Shell; pub use shell::Shell;
pub use size::Size; pub use size::Size;
pub use text::Text; pub use text::Text;
pub use transformation::Transformation;
pub use vector::Vector; pub use vector::Vector;
pub use widget::Widget; pub use widget::Widget;

View file

@ -13,4 +13,5 @@ pub enum Interaction {
ResizingHorizontally, ResizingHorizontally,
ResizingVertically, ResizingVertically,
NotAllowed, NotAllowed,
ZoomIn,
} }

View file

@ -5,7 +5,9 @@ mod null;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
pub use null::Null; pub use null::Null;
use crate::{Background, Border, Color, Rectangle, Shadow, Size, Vector}; use crate::{
Background, Border, Color, Rectangle, Shadow, Size, Transformation, Vector,
};
/// A component that can be used by widgets to draw themselves on a screen. /// A component that can be used by widgets to draw themselves on a screen.
pub trait Renderer: Sized { pub trait Renderer: Sized {
@ -14,12 +16,24 @@ pub trait Renderer: Sized {
/// The layer will clip its contents to the provided `bounds`. /// The layer will clip its contents to the provided `bounds`.
fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)); fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self));
/// Applies a `translation` to the primitives recorded in the given closure. /// Applies a [`Transformation`] to the primitives recorded in the given closure.
fn with_transformation(
&mut self,
transformation: Transformation,
f: impl FnOnce(&mut Self),
);
/// Applies a translation to the primitives recorded in the given closure.
fn with_translation( fn with_translation(
&mut self, &mut self,
translation: Vector, translation: Vector,
f: impl FnOnce(&mut Self), f: impl FnOnce(&mut Self),
); ) {
self.with_transformation(
Transformation::translate(translation.x, translation.y),
f,
);
}
/// Fills a [`Quad`] with the provided [`Background`]. /// Fills a [`Quad`] with the provided [`Background`].
fn fill_quad(&mut self, quad: Quad, background: impl Into<Background>); fn fill_quad(&mut self, quad: Quad, background: impl Into<Background>);

View file

@ -1,7 +1,9 @@
use crate::alignment; use crate::alignment;
use crate::renderer::{self, Renderer}; use crate::renderer::{self, Renderer};
use crate::text::{self, Text}; use crate::text::{self, Text};
use crate::{Background, Color, Font, Pixels, Point, Rectangle, Size, Vector}; use crate::{
Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation,
};
use std::borrow::Cow; use std::borrow::Cow;
@ -21,9 +23,9 @@ impl Null {
impl Renderer for Null { impl Renderer for Null {
fn with_layer(&mut self, _bounds: Rectangle, _f: impl FnOnce(&mut Self)) {} fn with_layer(&mut self, _bounds: Rectangle, _f: impl FnOnce(&mut Self)) {}
fn with_translation( fn with_transformation(
&mut self, &mut self,
_translation: Vector, _transformation: Transformation,
_f: impl FnOnce(&mut Self), _f: impl FnOnce(&mut Self),
) { ) {
} }

View file

@ -1,4 +1,4 @@
use crate::core::{Point, Rectangle, Size, Vector}; use crate::{Point, Rectangle, Size, Vector};
use glam::{Mat4, Vec3, Vec4}; use glam::{Mat4, Vec3, Vec4};
use std::ops::Mul; use std::ops::Mul;
@ -31,19 +31,14 @@ impl Transformation {
Transformation(Mat4::from_scale(Vec3::new(scaling, scaling, 1.0))) Transformation(Mat4::from_scale(Vec3::new(scaling, scaling, 1.0)))
} }
/// The scale factor of the [`Transformation`]. /// Returns the scale factor of the [`Transformation`].
pub fn scale_factor(&self) -> f32 { pub fn scale_factor(&self) -> f32 {
self.0.x_axis.x self.0.x_axis.x
} }
/// The translation on the X axis. /// Returns the translation of the [`Transformation`].
pub fn translation_x(&self) -> f32 { pub fn translation(&self) -> Vector {
self.0.w_axis.x Vector::new(self.0.w_axis.x, self.0.w_axis.y)
}
/// The translation on the Y axis.
pub fn translation_y(&self) -> f32 {
self.0.w_axis.y
} }
} }

View file

@ -26,7 +26,6 @@ iced_futures.workspace = true
bitflags.workspace = true bitflags.workspace = true
bytemuck.workspace = true bytemuck.workspace = true
cosmic-text.workspace = true cosmic-text.workspace = true
glam.workspace = true
half.workspace = true half.workspace = true
log.workspace = true log.workspace = true
once_cell.workspace = true once_cell.workspace = true

View file

@ -19,7 +19,6 @@
mod antialiasing; mod antialiasing;
mod error; mod error;
mod primitive; mod primitive;
mod transformation;
mod viewport; mod viewport;
pub mod backend; pub mod backend;
@ -46,7 +45,6 @@ pub use gradient::Gradient;
pub use mesh::Mesh; pub use mesh::Mesh;
pub use primitive::Primitive; pub use primitive::Primitive;
pub use renderer::Renderer; pub use renderer::Renderer;
pub use transformation::Transformation;
pub use viewport::Viewport; pub use viewport::Viewport;
pub use iced_core as core; pub use iced_core as core;

View file

@ -4,11 +4,11 @@ use crate::core::image;
use crate::core::svg; use crate::core::svg;
use crate::core::text; use crate::core::text;
use crate::core::{ use crate::core::{
Background, Border, Color, Font, Pixels, Point, Rectangle, Shadow, Vector, Background, Border, Color, Font, Pixels, Point, Rectangle, Shadow,
Transformation, Vector,
}; };
use crate::text::editor; use crate::text::editor;
use crate::text::paragraph; use crate::text::paragraph;
use crate::Transformation;
use std::sync::Arc; use std::sync::Arc;

View file

@ -6,7 +6,7 @@ use crate::core::renderer;
use crate::core::svg; use crate::core::svg;
use crate::core::text::Text; use crate::core::text::Text;
use crate::core::{ use crate::core::{
Background, Color, Font, Pixels, Point, Rectangle, Size, Vector, Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation,
}; };
use crate::text; use crate::text;
use crate::Primitive; use crate::Primitive;
@ -73,20 +73,20 @@ impl<B: Backend> Renderer<B> {
} }
/// Starts recording a translation. /// Starts recording a translation.
pub fn start_translation(&mut self) -> Vec<Primitive<B::Primitive>> { pub fn start_transformation(&mut self) -> Vec<Primitive<B::Primitive>> {
std::mem::take(&mut self.primitives) std::mem::take(&mut self.primitives)
} }
/// Ends the recording of a translation. /// Ends the recording of a translation.
pub fn end_translation( pub fn end_transformation(
&mut self, &mut self,
primitives: Vec<Primitive<B::Primitive>>, primitives: Vec<Primitive<B::Primitive>>,
translation: Vector, transformation: Transformation,
) { ) {
let layer = std::mem::replace(&mut self.primitives, primitives); let layer = std::mem::replace(&mut self.primitives, primitives);
self.primitives self.primitives
.push(Primitive::group(layer).translate(translation)); .push(Primitive::group(layer).transform(transformation));
} }
} }
@ -99,16 +99,16 @@ impl<B: Backend> iced_core::Renderer for Renderer<B> {
self.end_layer(current, bounds); self.end_layer(current, bounds);
} }
fn with_translation( fn with_transformation(
&mut self, &mut self,
translation: Vector, transformation: Transformation,
f: impl FnOnce(&mut Self), f: impl FnOnce(&mut Self),
) { ) {
let current = self.start_translation(); let current = self.start_transformation();
f(self); f(self);
self.end_translation(current, translation); self.end_transformation(current, transformation);
} }
fn fill_quad( fn fill_quad(

View file

@ -1,6 +1,4 @@
use crate::Transformation; use crate::core::{Size, Transformation};
use iced_core::Size;
/// A viewing region for displaying computer graphics. /// A viewing region for displaying computer graphics.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View file

@ -2,9 +2,8 @@ mod cache;
pub use cache::Cache; pub use cache::Cache;
use crate::core::{Point, Rectangle, Size, Vector}; use crate::core::{Point, Rectangle, Size, Transformation, Vector};
use crate::graphics::geometry::{Fill, Path, Stroke, Text}; use crate::graphics::geometry::{Fill, Path, Stroke, Text};
use crate::graphics::Transformation;
use crate::Renderer; use crate::Renderer;
macro_rules! delegate { macro_rules! delegate {

View file

@ -22,7 +22,9 @@ pub use geometry::Geometry;
use crate::core::renderer; use crate::core::renderer;
use crate::core::text::{self, Text}; use crate::core::text::{self, Text};
use crate::core::{Background, Color, Font, Pixels, Point, Rectangle, Vector}; use crate::core::{
Background, Color, Font, Pixels, Point, Rectangle, Transformation,
};
use crate::graphics::text::Editor; use crate::graphics::text::Editor;
use crate::graphics::text::Paragraph; use crate::graphics::text::Paragraph;
use crate::graphics::Mesh; use crate::graphics::Mesh;
@ -97,20 +99,20 @@ impl core::Renderer for Renderer {
} }
} }
fn with_translation( fn with_transformation(
&mut self, &mut self,
translation: Vector, transformation: Transformation,
f: impl FnOnce(&mut Self), f: impl FnOnce(&mut Self),
) { ) {
match self { match self {
Self::TinySkia(renderer) => { Self::TinySkia(renderer) => {
let primitives = renderer.start_translation(); let primitives = renderer.start_transformation();
f(self); f(self);
match self { match self {
Self::TinySkia(renderer) => { Self::TinySkia(renderer) => {
renderer.end_translation(primitives, translation); renderer.end_transformation(primitives, transformation);
} }
#[cfg(feature = "wgpu")] #[cfg(feature = "wgpu")]
_ => unreachable!(), _ => unreachable!(),
@ -118,14 +120,14 @@ impl core::Renderer for Renderer {
} }
#[cfg(feature = "wgpu")] #[cfg(feature = "wgpu")]
Self::Wgpu(renderer) => { Self::Wgpu(renderer) => {
let primitives = renderer.start_translation(); let primitives = renderer.start_transformation();
f(self); f(self);
match self { match self {
#[cfg(feature = "wgpu")] #[cfg(feature = "wgpu")]
Self::Wgpu(renderer) => { Self::Wgpu(renderer) => {
renderer.end_translation(primitives, translation); renderer.end_transformation(primitives, transformation);
} }
_ => unreachable!(), _ => unreachable!(),
} }

View file

@ -193,7 +193,8 @@ pub use crate::core::color;
pub use crate::core::gradient; pub use crate::core::gradient;
pub use crate::core::{ pub use crate::core::{
Alignment, Background, Border, Color, ContentFit, Degrees, Gradient, Alignment, Background, Border, Color, ContentFit, Degrees, Gradient,
Length, Padding, Pixels, Point, Radians, Rectangle, Shadow, Size, Vector, Length, Padding, Pixels, Point, Radians, Rectangle, Shadow, Size,
Transformation, Vector,
}; };
pub mod clipboard { pub mod clipboard {

View file

@ -1,9 +1,11 @@
use tiny_skia::Size; use tiny_skia::Size;
use crate::core::{Background, Color, Gradient, Rectangle, Vector}; use crate::core::{
Background, Color, Gradient, Rectangle, Transformation, Vector,
};
use crate::graphics::backend; use crate::graphics::backend;
use crate::graphics::text; use crate::graphics::text;
use crate::graphics::{Transformation, Viewport}; use crate::graphics::Viewport;
use crate::primitive::{self, Primitive}; use crate::primitive::{self, Primitive};
use std::borrow::Cow; use std::borrow::Cow;
@ -459,11 +461,12 @@ impl Backend {
self.text_pipeline.draw_paragraph( self.text_pipeline.draw_paragraph(
paragraph, paragraph,
*position * transformation, *position,
*color, *color,
scale_factor * transformation.scale_factor(), scale_factor,
pixels, pixels,
clip_mask, clip_mask,
transformation,
); );
} }
Primitive::Editor { Primitive::Editor {
@ -484,11 +487,12 @@ impl Backend {
self.text_pipeline.draw_editor( self.text_pipeline.draw_editor(
editor, editor,
*position * transformation, *position,
*color, *color,
scale_factor, scale_factor,
pixels, pixels,
clip_mask, clip_mask,
transformation,
); );
} }
Primitive::Text { Primitive::Text {
@ -515,7 +519,7 @@ impl Backend {
self.text_pipeline.draw_cached( self.text_pipeline.draw_cached(
content, content,
*bounds * transformation, *bounds,
*color, *color,
*size, *size,
*line_height, *line_height,
@ -523,9 +527,10 @@ impl Backend {
*horizontal_alignment, *horizontal_alignment,
*vertical_alignment, *vertical_alignment,
*shaping, *shaping,
scale_factor * transformation.scale_factor(), scale_factor,
pixels, pixels,
clip_mask, clip_mask,
transformation,
); );
} }
Primitive::RawText(text::Raw { Primitive::RawText(text::Raw {
@ -550,11 +555,12 @@ impl Backend {
self.text_pipeline.draw_raw( self.text_pipeline.draw_raw(
&buffer, &buffer,
*position * transformation, *position,
*color, *color,
scale_factor, scale_factor,
pixels, pixels,
clip_mask, clip_mask,
transformation,
); );
} }
#[cfg(feature = "image")] #[cfg(feature = "image")]
@ -769,13 +775,15 @@ fn into_color(color: Color) -> tiny_skia::Color {
} }
fn into_transform(transformation: Transformation) -> tiny_skia::Transform { fn into_transform(transformation: Transformation) -> tiny_skia::Transform {
let translation = transformation.translation();
tiny_skia::Transform { tiny_skia::Transform {
sx: transformation.scale_factor(), sx: transformation.scale_factor(),
kx: 0.0, kx: 0.0,
ky: 0.0, ky: 0.0,
sy: transformation.scale_factor(), sy: transformation.scale_factor(),
tx: transformation.translation_x(), tx: translation.x,
ty: transformation.translation_y(), ty: translation.y,
} }
} }

View file

@ -1,9 +1,9 @@
use crate::core::text::LineHeight; use crate::core::text::LineHeight;
use crate::core::{Pixels, Point, Rectangle, Size, Vector}; use crate::core::{Pixels, Point, Rectangle, Size, Transformation, Vector};
use crate::graphics::geometry::fill::{self, Fill}; use crate::graphics::geometry::fill::{self, Fill};
use crate::graphics::geometry::stroke::{self, Stroke}; use crate::graphics::geometry::stroke::{self, Stroke};
use crate::graphics::geometry::{Path, Style, Text}; use crate::graphics::geometry::{Path, Style, Text};
use crate::graphics::{Gradient, Transformation}; use crate::graphics::Gradient;
use crate::primitive::{self, Primitive}; use crate::primitive::{self, Primitive};
pub struct Frame { pub struct Frame {

View file

@ -1,6 +1,8 @@
use crate::core::alignment; use crate::core::alignment;
use crate::core::text::{LineHeight, Shaping}; use crate::core::text::{LineHeight, Shaping};
use crate::core::{Color, Font, Pixels, Point, Rectangle, Size}; use crate::core::{
Color, Font, Pixels, Point, Rectangle, Size, Transformation,
};
use crate::graphics::text::cache::{self, Cache}; use crate::graphics::text::cache::{self, Cache};
use crate::graphics::text::editor; use crate::graphics::text::editor;
use crate::graphics::text::font_system; use crate::graphics::text::font_system;
@ -42,6 +44,7 @@ impl Pipeline {
scale_factor: f32, scale_factor: f32,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: Option<&tiny_skia::Mask>, clip_mask: Option<&tiny_skia::Mask>,
transformation: Transformation,
) { ) {
use crate::core::text::Paragraph as _; use crate::core::text::Paragraph as _;
@ -62,6 +65,7 @@ impl Pipeline {
scale_factor, scale_factor,
pixels, pixels,
clip_mask, clip_mask,
transformation,
); );
} }
@ -73,6 +77,7 @@ impl Pipeline {
scale_factor: f32, scale_factor: f32,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: Option<&tiny_skia::Mask>, clip_mask: Option<&tiny_skia::Mask>,
transformation: Transformation,
) { ) {
use crate::core::text::Editor as _; use crate::core::text::Editor as _;
@ -93,6 +98,7 @@ impl Pipeline {
scale_factor, scale_factor,
pixels, pixels,
clip_mask, clip_mask,
transformation,
); );
} }
@ -110,6 +116,7 @@ impl Pipeline {
scale_factor: f32, scale_factor: f32,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: Option<&tiny_skia::Mask>, clip_mask: Option<&tiny_skia::Mask>,
transformation: Transformation,
) { ) {
let line_height = f32::from(line_height.to_absolute(size)); let line_height = f32::from(line_height.to_absolute(size));
@ -145,6 +152,7 @@ impl Pipeline {
scale_factor, scale_factor,
pixels, pixels,
clip_mask, clip_mask,
transformation,
); );
} }
@ -156,6 +164,7 @@ impl Pipeline {
scale_factor: f32, scale_factor: f32,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: Option<&tiny_skia::Mask>, clip_mask: Option<&tiny_skia::Mask>,
transformation: Transformation,
) { ) {
let mut font_system = font_system().write().expect("Write font system"); let mut font_system = font_system().write().expect("Write font system");
@ -172,6 +181,7 @@ impl Pipeline {
scale_factor, scale_factor,
pixels, pixels,
clip_mask, clip_mask,
transformation,
); );
} }
@ -192,8 +202,9 @@ fn draw(
scale_factor: f32, scale_factor: f32,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: Option<&tiny_skia::Mask>, clip_mask: Option<&tiny_skia::Mask>,
transformation: Transformation,
) { ) {
let bounds = bounds * scale_factor; let bounds = bounds * transformation * scale_factor;
let x = match horizontal_alignment { let x = match horizontal_alignment {
alignment::Horizontal::Left => bounds.x, alignment::Horizontal::Left => bounds.x,
@ -211,7 +222,8 @@ fn draw(
for run in buffer.layout_runs() { for run in buffer.layout_runs() {
for glyph in run.glyphs { for glyph in run.glyphs {
let physical_glyph = glyph.physical((x, y), scale_factor); let physical_glyph = glyph
.physical((x, y), scale_factor * transformation.scale_factor());
if let Some((buffer, placement)) = glyph_cache.allocate( if let Some((buffer, placement)) = glyph_cache.allocate(
physical_glyph.cache_key, physical_glyph.cache_key,
@ -229,7 +241,10 @@ fn draw(
pixels.draw_pixmap( pixels.draw_pixmap(
physical_glyph.x + placement.left, physical_glyph.x + placement.left,
physical_glyph.y - placement.top physical_glyph.y - placement.top
+ (run.line_y * scale_factor).round() as i32, + (run.line_y
* scale_factor
* transformation.scale_factor())
.round() as i32,
pixmap, pixmap,
&tiny_skia::PixmapPaint::default(), &tiny_skia::PixmapPaint::default(),
tiny_skia::Transform::identity(), tiny_skia::Transform::identity(),

View file

@ -1,7 +1,7 @@
use crate::core::{Color, Size}; use crate::core::{Color, Size, Transformation};
use crate::graphics::backend; use crate::graphics::backend;
use crate::graphics::color; use crate::graphics::color;
use crate::graphics::{Transformation, Viewport}; use crate::graphics::Viewport;
use crate::primitive::pipeline; use crate::primitive::pipeline;
use crate::primitive::{self, Primitive}; use crate::primitive::{self, Primitive};
use crate::quad; use crate::quad;

View file

@ -1,6 +1,6 @@
//! Build and draw geometry. //! Build and draw geometry.
use crate::core::text::LineHeight; use crate::core::text::LineHeight;
use crate::core::{Pixels, Point, Rectangle, Size, Vector}; use crate::core::{Pixels, Point, Rectangle, Size, Transformation, Vector};
use crate::graphics::color; use crate::graphics::color;
use crate::graphics::geometry::fill::{self, Fill}; use crate::graphics::geometry::fill::{self, Fill};
use crate::graphics::geometry::{ use crate::graphics::geometry::{
@ -8,7 +8,6 @@ use crate::graphics::geometry::{
}; };
use crate::graphics::gradient::{self, Gradient}; use crate::graphics::gradient::{self, Gradient};
use crate::graphics::mesh::{self, Mesh}; use crate::graphics::mesh::{self, Mesh};
use crate::graphics::Transformation;
use crate::primitive::{self, Primitive}; use crate::primitive::{self, Primitive};
use lyon::geom::euclid; use lyon::geom::euclid;

View file

@ -8,8 +8,7 @@ mod vector;
use atlas::Atlas; use atlas::Atlas;
use crate::core::{Rectangle, Size}; use crate::core::{Rectangle, Size, Transformation};
use crate::graphics::Transformation;
use crate::layer; use crate::layer;
use crate::Buffer; use crate::Buffer;

View file

@ -12,10 +12,12 @@ pub use text::Text;
use crate::core; use crate::core;
use crate::core::alignment; use crate::core::alignment;
use crate::core::{Color, Font, Pixels, Point, Rectangle, Size, Vector}; use crate::core::{
Color, Font, Pixels, Point, Rectangle, Size, Transformation, Vector,
};
use crate::graphics; use crate::graphics;
use crate::graphics::color; use crate::graphics::color;
use crate::graphics::{Transformation, Viewport}; use crate::graphics::Viewport;
use crate::primitive::{self, Primitive}; use crate::primitive::{self, Primitive};
use crate::quad::{self, Quad}; use crate::quad::{self, Quad};
@ -130,10 +132,10 @@ impl<'a> Layer<'a> {
layer.text.push(Text::Paragraph { layer.text.push(Text::Paragraph {
paragraph: paragraph.clone(), paragraph: paragraph.clone(),
position: *position * transformation, position: *position,
color: *color, color: *color,
clip_bounds: *clip_bounds * transformation, clip_bounds: *clip_bounds,
scale: transformation.scale_factor(), transformation,
}); });
} }
Primitive::Editor { Primitive::Editor {
@ -146,10 +148,10 @@ impl<'a> Layer<'a> {
layer.text.push(Text::Editor { layer.text.push(Text::Editor {
editor: editor.clone(), editor: editor.clone(),
position: *position * transformation, position: *position,
color: *color, color: *color,
clip_bounds: *clip_bounds * transformation, clip_bounds: *clip_bounds,
scale: transformation.scale_factor(), transformation,
}); });
} }
Primitive::Text { Primitive::Text {
@ -168,7 +170,7 @@ impl<'a> Layer<'a> {
layer.text.push(Text::Cached(text::Cached { layer.text.push(Text::Cached(text::Cached {
content, content,
bounds: *bounds * transformation, bounds: *bounds + transformation.translation(),
size: *size * transformation.scale_factor(), size: *size * transformation.scale_factor(),
line_height: *line_height, line_height: *line_height,
color: *color, color: *color,

View file

@ -1,7 +1,6 @@
//! A collection of triangle primitives. //! A collection of triangle primitives.
use crate::core::Rectangle; use crate::core::{Rectangle, Transformation};
use crate::graphics::mesh; use crate::graphics::mesh;
use crate::graphics::Transformation;
/// A mesh of triangles. /// A mesh of triangles.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]

View file

@ -1,6 +1,6 @@
use crate::core::alignment; use crate::core::alignment;
use crate::core::text; use crate::core::text;
use crate::core::{Color, Font, Pixels, Point, Rectangle}; use crate::core::{Color, Font, Pixels, Point, Rectangle, Transformation};
use crate::graphics; use crate::graphics;
use crate::graphics::text::editor; use crate::graphics::text::editor;
use crate::graphics::text::paragraph; use crate::graphics::text::paragraph;
@ -15,7 +15,7 @@ pub enum Text<'a> {
position: Point, position: Point,
color: Color, color: Color,
clip_bounds: Rectangle, clip_bounds: Rectangle,
scale: f32, transformation: Transformation,
}, },
/// An editor. /// An editor.
#[allow(missing_docs)] #[allow(missing_docs)]
@ -24,7 +24,7 @@ pub enum Text<'a> {
position: Point, position: Point,
color: Color, color: Color,
clip_bounds: Rectangle, clip_bounds: Rectangle,
scale: f32, transformation: Transformation,
}, },
/// Some cached text. /// Some cached text.
Cached(Cached<'a>), Cached(Cached<'a>),

View file

@ -4,9 +4,9 @@ mod solid;
use gradient::Gradient; use gradient::Gradient;
use solid::Solid; use solid::Solid;
use crate::core::{Background, Rectangle}; use crate::core::{Background, Rectangle, Transformation};
use crate::graphics;
use crate::graphics::color; use crate::graphics::color;
use crate::graphics::{self, Transformation};
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};

View file

@ -1,5 +1,5 @@
use crate::core::alignment; use crate::core::alignment;
use crate::core::{Rectangle, Size}; use crate::core::{Rectangle, Size, Transformation};
use crate::graphics::color; use crate::graphics::color;
use crate::graphics::text::cache::{self, Cache}; use crate::graphics::text::cache::{self, Cache};
use crate::graphics::text::{font_system, to_color, Editor, Paragraph}; use crate::graphics::text::{font_system, to_color, Editor, Paragraph};
@ -124,13 +124,13 @@ impl Pipeline {
vertical_alignment, vertical_alignment,
color, color,
clip_bounds, clip_bounds,
scale, transformation,
) = match section { ) = match section {
Text::Paragraph { Text::Paragraph {
position, position,
color, color,
clip_bounds, clip_bounds,
scale, transformation,
.. ..
} => { } => {
use crate::core::text::Paragraph as _; use crate::core::text::Paragraph as _;
@ -147,14 +147,14 @@ impl Pipeline {
paragraph.vertical_alignment(), paragraph.vertical_alignment(),
*color, *color,
*clip_bounds, *clip_bounds,
*scale, *transformation,
) )
} }
Text::Editor { Text::Editor {
position, position,
color, color,
clip_bounds, clip_bounds,
scale, transformation,
.. ..
} => { } => {
use crate::core::text::Editor as _; use crate::core::text::Editor as _;
@ -171,7 +171,7 @@ impl Pipeline {
alignment::Vertical::Top, alignment::Vertical::Top,
*color, *color,
*clip_bounds, *clip_bounds,
*scale, *transformation,
) )
} }
Text::Cached(text) => { Text::Cached(text) => {
@ -191,7 +191,7 @@ impl Pipeline {
text.vertical_alignment, text.vertical_alignment,
text.color, text.color,
text.clip_bounds, text.clip_bounds,
1.0, Transformation::IDENTITY,
) )
} }
Text::Raw(text) => { Text::Raw(text) => {
@ -211,12 +211,12 @@ impl Pipeline {
alignment::Vertical::Top, alignment::Vertical::Top,
text.color, text.color,
text.clip_bounds, text.clip_bounds,
1.0, Transformation::IDENTITY,
) )
} }
}; };
let bounds = bounds * scale_factor; let bounds = bounds * transformation * scale_factor;
let left = match horizontal_alignment { let left = match horizontal_alignment {
alignment::Horizontal::Left => bounds.x, alignment::Horizontal::Left => bounds.x,
@ -241,7 +241,7 @@ impl Pipeline {
buffer, buffer,
left, left,
top, top,
scale: scale * scale_factor, scale: scale_factor * transformation.scale_factor(),
bounds: glyphon::TextBounds { bounds: glyphon::TextBounds {
left: clip_bounds.x as i32, left: clip_bounds.x as i32,
top: clip_bounds.y as i32, top: clip_bounds.y as i32,

View file

@ -1,8 +1,8 @@
//! Draw meshes of triangles. //! Draw meshes of triangles.
mod msaa; mod msaa;
use crate::core::Size; use crate::core::{Size, Transformation};
use crate::graphics::{Antialiasing, Transformation}; use crate::graphics::Antialiasing;
use crate::layer::mesh::{self, Mesh}; use crate::layer::mesh::{self, Mesh};
use crate::Buffer; use crate::Buffer;

View file

@ -7,7 +7,6 @@ pub use event::Event;
pub use program::Program; pub use program::Program;
pub use crate::graphics::geometry::*; pub use crate::graphics::geometry::*;
pub use crate::graphics::Transformation;
pub use crate::renderer::geometry::*; pub use crate::renderer::geometry::*;
use crate::core; use crate::core;
@ -16,7 +15,7 @@ use crate::core::mouse;
use crate::core::renderer; use crate::core::renderer;
use crate::core::widget::tree::{self, Tree}; use crate::core::widget::tree::{self, Tree};
use crate::core::{ use crate::core::{
Clipboard, Element, Length, Rectangle, Shell, Size, Vector, Widget, Clipboard, Element, Length, Rectangle, Shell, Size, Transformation, Widget,
}; };
use crate::graphics::geometry; use crate::graphics::geometry;
@ -208,8 +207,8 @@ where
let state = tree.state.downcast_ref::<P::State>(); let state = tree.state.downcast_ref::<P::State>();
renderer.with_translation( renderer.with_transformation(
Vector::new(bounds.x, bounds.y), Transformation::translate(bounds.x, bounds.y),
|renderer| { |renderer| {
renderer.draw( renderer.draw(
self.program.draw(state, renderer, theme, bounds, cursor), self.program.draw(state, renderer, theme, bounds, cursor),

View file

@ -7,7 +7,7 @@ use crate::core::renderer;
use crate::core::widget::tree::{self, Tree}; use crate::core::widget::tree::{self, Tree};
use crate::core::{ use crate::core::{
Clipboard, Element, Layout, Length, Pixels, Point, Rectangle, Shell, Size, Clipboard, Element, Layout, Length, Pixels, Point, Rectangle, Shell, Size,
Vector, Widget, Transformation, Vector, Widget,
}; };
use std::hash::Hash; use std::hash::Hash;
@ -328,18 +328,21 @@ where
}; };
renderer.with_layer(bounds, |renderer| { renderer.with_layer(bounds, |renderer| {
renderer.with_translation(translation, |renderer| { renderer.with_transformation(
image::Renderer::draw( Transformation::translate(translation.x, translation.y),
renderer, |renderer| {
self.handle.clone(), image::Renderer::draw(
self.filter_method, renderer,
Rectangle { self.handle.clone(),
x: bounds.x, self.filter_method,
y: bounds.y, Rectangle {
..Rectangle::with_size(image_size) x: bounds.x,
}, y: bounds.y,
); ..Rectangle::with_size(image_size)
}); },
);
},
);
}); });
} }
} }

View file

@ -43,7 +43,7 @@ use crate::core::widget;
use crate::core::widget::tree::{self, Tree}; use crate::core::widget::tree::{self, Tree};
use crate::core::{ use crate::core::{
Clipboard, Element, Layout, Length, Pixels, Point, Rectangle, Shell, Size, 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 /// 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() { if let Some(cursor_position) = cursor.position() {
let bounds = layout.bounds(); let bounds = layout.bounds();
renderer.with_translation( let translation = cursor_position
cursor_position - Point::new(bounds.x + origin.x, bounds.y + origin.y);
- Point::new(bounds.x + origin.x, bounds.y + origin.y),
renderer.with_transformation(
Transformation::translate(translation.x, translation.y),
|renderer| { |renderer| {
renderer.with_layer(bounds, |renderer| { renderer.with_layer(bounds, |renderer| {
draw_pane( draw_pane(

View file

@ -5,7 +5,8 @@ use crate::core::mouse;
use crate::core::renderer::{self, Renderer as _}; use crate::core::renderer::{self, Renderer as _};
use crate::core::widget::Tree; use crate::core::widget::Tree;
use crate::core::{ 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::graphics::geometry::Renderer as _;
use crate::Renderer; 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); let translation = Vector::new(bounds.x, bounds.y);
renderer.with_translation(translation, |renderer| { renderer.with_transformation(
renderer.draw(vec![geometry]); Transformation::translate(translation.x, translation.y),
}); |renderer| {
renderer.draw(vec![geometry]);
},
);
} }
} }

View file

@ -385,6 +385,7 @@ pub fn mouse_interaction(
} }
Interaction::ResizingVertically => winit::window::CursorIcon::NsResize, Interaction::ResizingVertically => winit::window::CursorIcon::NsResize,
Interaction::NotAllowed => winit::window::CursorIcon::NotAllowed, Interaction::NotAllowed => winit::window::CursorIcon::NotAllowed,
Interaction::ZoomIn => winit::window::CursorIcon::ZoomIn,
} }
} }