Skip to content

Commit

Permalink
Expose the scale value from Renderer. (#444)
Browse files Browse the repository at this point in the history
Rationale: It is possible to set the scale on a PaintCx, but not to restore it to its previous value,
and `PaintCx.save()` and `PaintCx.restore()` do not handle it, since it is writing directly to a property
of the underlying renderer.

Use-case: In order to debug layout issues, it is useful to be able to scale a component's content down,
render it that way and observe if there is any painting outside the expected bounds.
  • Loading branch information
timboudreau authored May 13, 2024
1 parent ab28c54 commit 1a4fc03
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ impl<W: wgpu::WindowHandle> Renderer<W> {
Renderer::TinySkia(r) => r.set_scale(scale),
}
}

pub fn scale(&self) -> f64 {
match self {
Renderer::Vger(r) => r.scale(),
Renderer::TinySkia(r) => r.scale(),
}
}
}

impl<W: wgpu::WindowHandle> floem_renderer::Renderer for Renderer<W> {
Expand Down
4 changes: 4 additions & 0 deletions tiny_skia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ impl<W: raw_window_handle::HasWindowHandle + raw_window_handle::HasDisplayHandle
pub fn set_scale(&mut self, scale: f64) {
self.scale = scale;
}

pub fn scale(&self) -> f64 {
self.scale
}
}

fn to_color(color: Color) -> tiny_skia::Color {
Expand Down
4 changes: 4 additions & 0 deletions vger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ impl VgerRenderer {
pub fn set_scale(&mut self, scale: f64) {
self.scale = scale;
}

pub fn scale(&self) -> f64 {
self.scale
}
}

impl VgerRenderer {
Expand Down

0 comments on commit 1a4fc03

Please sign in to comment.