summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-27 03:11:54 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-27 03:11:54 +0100
commit35e94f5a324f5c28de855b725039733efb21b26a (patch)
tree4571168a65c48cc5828debb219874c542f3a82a5 /wgpu
parent21eb2f692c687a675c54ae5e951556e28e7435eb (diff)
downloadiced-35e94f5a324f5c28de855b725039733efb21b26a.tar.gz
iced-35e94f5a324f5c28de855b725039733efb21b26a.tar.bz2
iced-35e94f5a324f5c28de855b725039733efb21b26a.zip
Draft text scrolling (no clipping yet!)
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/renderer.rs33
1 files changed, 28 insertions, 5 deletions
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs
index ba140a66..cfdd7a45 100644
--- a/wgpu/src/renderer.rs
+++ b/wgpu/src/renderer.rs
@@ -41,21 +41,23 @@ pub struct Target {
swap_chain: SwapChain,
}
-pub struct Layer {
+pub struct Layer<'a> {
bounds: Rectangle<u32>,
y_offset: u32,
quads: Vec<Quad>,
images: Vec<Image>,
- layers: Vec<Layer>,
+ text: Vec<wgpu_glyph::Section<'a>>,
+ layers: Vec<Layer<'a>>,
}
-impl Layer {
+impl<'a> Layer<'a> {
pub fn new(bounds: Rectangle<u32>, y_offset: u32) -> Self {
Self {
bounds,
y_offset,
quads: Vec::new(),
images: Vec::new(),
+ text: Vec::new(),
layers: Vec::new(),
}
}
@@ -176,7 +178,11 @@ impl Renderer {
*mouse_cursor
}
- fn draw_primitive(&mut self, primitive: &Primitive, layer: &mut Layer) {
+ fn draw_primitive<'a>(
+ &mut self,
+ primitive: &'a Primitive,
+ layer: &mut Layer<'a>,
+ ) {
match primitive {
Primitive::None => {}
Primitive::Group { primitives } => {
@@ -213,7 +219,7 @@ impl Renderer {
}
};
- self.glyph_brush.borrow_mut().queue(Section {
+ layer.text.push(Section {
text: &content,
screen_position: (x, y),
bounds: (bounds.width, bounds.height),
@@ -317,6 +323,23 @@ impl Renderer {
target,
);
+ {
+ let mut glyph_brush = self.glyph_brush.borrow_mut();
+
+ for text in layer.text.iter() {
+ glyph_brush.queue(text);
+ }
+
+ glyph_brush
+ .draw_queued_with_transform(
+ &mut self.device,
+ encoder,
+ target,
+ translated.into(),
+ )
+ .expect("Draw text");
+ }
+
for layer in layer.layers.iter() {
self.flush(transformation, layer, encoder, target);
}