diff options
author | Minijackson <minijackson@riseup.net> | 2023-02-03 19:59:43 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2023-02-03 19:59:43 +0100 |
commit | 82ffe3187a32bad4ecca0736882a23793a800822 (patch) | |
tree | 2d3ab9231b76dadcf2ab69b27053df6cc66bead1 /core/src/rendering.rs | |
parent | c8bb3e4a24ca1ca6ec1a57c9e8cd8655483b3eb0 (diff) | |
download | diaphragm-82ffe3187a32bad4ecca0736882a23793a800822.tar.gz diaphragm-82ffe3187a32bad4ecca0736882a23793a800822.zip |
add support for images, and some chores
- SVG files not yet supported
- Remove dead commented code
- Add inherent constraints for text, path, and images
- Formatting
Diffstat (limited to 'core/src/rendering.rs')
-rw-r--r-- | core/src/rendering.rs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/core/src/rendering.rs b/core/src/rendering.rs index 73daa2a..9c719c4 100644 --- a/core/src/rendering.rs +++ b/core/src/rendering.rs | |||
@@ -1,7 +1,11 @@ | |||
1 | use super::core_shapes::*; | 1 | use std::path::Path; |
2 | use super::styles::{DefinedDashStyle, DefinedStrokeStyle, FillStyle, Pattern}; | 2 | |
3 | use super::text::{DefinedFontDescription, FontDescription}; | 3 | use crate::{ |
4 | use super::types::DefinedCoreShapeContext; | 4 | core_shapes::*, |
5 | styles::{DefinedDashStyle, DefinedStrokeStyle, FillStyle, Pattern}, | ||
6 | text::{DefinedFontDescription, DefinedText, FontDescription}, | ||
7 | types::DefinedCoreShapeContext, | ||
8 | }; | ||
5 | 9 | ||
6 | pub trait Renderer { | 10 | pub trait Renderer { |
7 | // Must be called once before any drawing happens | 11 | // Must be called once before any drawing happens |
@@ -19,6 +23,9 @@ pub trait Renderer { | |||
19 | // For a font of size 1. | 23 | // For a font of size 1. |
20 | fn text_extents(&self, text: &str, font: &FontDescription) -> (f64, f64); | 24 | fn text_extents(&self, text: &str, font: &FontDescription) -> (f64, f64); |
21 | fn show_text(&mut self, text: &str, font: &DefinedFontDescription); | 25 | fn show_text(&mut self, text: &str, font: &DefinedFontDescription); |
26 | |||
27 | fn show_image(&mut self, path: &Path, x: f64, y: f64, width: f64, height: f64); | ||
28 | fn geometry_for_image(&mut self, path: &Path) -> (f64, f64); | ||
22 | } | 29 | } |
23 | 30 | ||
24 | pub trait Render { | 31 | pub trait Render { |
@@ -31,6 +38,7 @@ impl Render for DefinedCoreShape { | |||
31 | Self::Rectangle(r) => r.render(context, renderer), | 38 | Self::Rectangle(r) => r.render(context, renderer), |
32 | Self::Text(t) => t.render(context, renderer), | 39 | Self::Text(t) => t.render(context, renderer), |
33 | Self::StraightPath(p) => p.render(context, renderer), | 40 | Self::StraightPath(p) => p.render(context, renderer), |
41 | Self::Image(i) => i.render(context, renderer), | ||
34 | } | 42 | } |
35 | } | 43 | } |
36 | } | 44 | } |
@@ -96,3 +104,16 @@ impl Render for DefinedStraightPath { | |||
96 | draw(&context.fill, &context.stroke, renderer); | 104 | draw(&context.fill, &context.stroke, renderer); |
97 | } | 105 | } |
98 | } | 106 | } |
107 | |||
108 | impl Render for Image { | ||
109 | fn render(&self, context: DefinedCoreShapeContext, renderer: &mut dyn Renderer) { | ||
110 | // TODO: what about pattern, and fill color? Do we do something with that? | ||
111 | renderer.show_image( | ||
112 | &self.path, | ||
113 | context.bounds.left, | ||
114 | context.bounds.top, | ||
115 | context.bounds.width, | ||
116 | context.bounds.height, | ||
117 | ); | ||
118 | } | ||
119 | } | ||