Draft text scrolling (no clipping yet!)
This commit is contained in:
parent
21eb2f692c
commit
35e94f5a32
1 changed files with 28 additions and 5 deletions
|
|
@ -41,21 +41,23 @@ pub struct Target {
|
||||||
swap_chain: SwapChain,
|
swap_chain: SwapChain,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Layer {
|
pub struct Layer<'a> {
|
||||||
bounds: Rectangle<u32>,
|
bounds: Rectangle<u32>,
|
||||||
y_offset: u32,
|
y_offset: u32,
|
||||||
quads: Vec<Quad>,
|
quads: Vec<Quad>,
|
||||||
images: Vec<Image>,
|
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 {
|
pub fn new(bounds: Rectangle<u32>, y_offset: u32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
bounds,
|
bounds,
|
||||||
y_offset,
|
y_offset,
|
||||||
quads: Vec::new(),
|
quads: Vec::new(),
|
||||||
images: Vec::new(),
|
images: Vec::new(),
|
||||||
|
text: Vec::new(),
|
||||||
layers: Vec::new(),
|
layers: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +178,11 @@ impl Renderer {
|
||||||
*mouse_cursor
|
*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 {
|
match primitive {
|
||||||
Primitive::None => {}
|
Primitive::None => {}
|
||||||
Primitive::Group { primitives } => {
|
Primitive::Group { primitives } => {
|
||||||
|
|
@ -213,7 +219,7 @@ impl Renderer {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.glyph_brush.borrow_mut().queue(Section {
|
layer.text.push(Section {
|
||||||
text: &content,
|
text: &content,
|
||||||
screen_position: (x, y),
|
screen_position: (x, y),
|
||||||
bounds: (bounds.width, bounds.height),
|
bounds: (bounds.width, bounds.height),
|
||||||
|
|
@ -317,6 +323,23 @@ impl Renderer {
|
||||||
target,
|
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() {
|
for layer in layer.layers.iter() {
|
||||||
self.flush(transformation, layer, encoder, target);
|
self.flush(transformation, layer, encoder, target);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue