Move the ItemRenderer to the item_rendering module

This commit is contained in:
Olivier Goffart 2021-01-06 10:19:39 +01:00 committed by Simon Hausmann
parent b0fd400cd1
commit c7ff67d0fc
7 changed files with 50 additions and 51 deletions

View file

@ -45,37 +45,9 @@ pub use text::*;
mod image;
pub use self::image::*;
pub trait ItemRenderer {
/// will draw a rectangle in (pos.x + rect.x)
fn draw_rectangle(&mut self, pos: Point, rect: Pin<&Rectangle>);
fn draw_border_rectangle(&mut self, pos: Point, rect: Pin<&BorderRectangle>);
fn draw_image(&mut self, pos: Point, image: Pin<&Image>);
fn draw_clipped_image(&mut self, pos: Point, image: Pin<&ClippedImage>);
fn draw_text(&mut self, pos: Point, text: Pin<&Text>);
fn draw_text_input(&mut self, pos: Point, text_input: Pin<&TextInput>);
fn draw_path(&mut self, pos: Point, path: Pin<&Path>);
fn combine_clip(&mut self, pos: Point, clip: &Pin<&Clip>);
fn clip_rects(&self) -> SharedVector<Rect>;
fn reset_clip(&mut self, rects: SharedVector<Rect>);
/// Returns the scale factor
fn scale_factor(&self) -> f32;
/// Draw a pixmap in position indicated by the `pos`.
/// The pixmap will be taken from cache if the cache is valid, otherwise, update_fn will be called
/// with a callback that need to be called once with `fn (width, height, data)` where data are the
/// argb premultiplied pixel values
fn draw_cached_pixmap(
&mut self,
item_cache: &CachedRenderingData,
pos: Point,
update_fn: &dyn Fn(&mut dyn FnMut(u32, u32, &[u8])),
);
}
/// Alias for `&mut dyn ItemRenderer`. Required so cbingen generates the ItemVTable
/// despite the presence of trait object
type ItemRendererRef<'a> = &'a mut dyn ItemRenderer;
type ItemRendererRef<'a> = &'a mut dyn crate::item_rendering::ItemRenderer;
/// Items are the nodes in the render tree.
#[vtable]
@ -207,7 +179,7 @@ impl Item for Rectangle {
fn focus_event(self: Pin<&Self>, _: &FocusEvent, _window: &ComponentWindow) {}
fn render(self: Pin<&Self>, pos: Point, backend: &mut &mut dyn ItemRenderer) {
fn render(self: Pin<&Self>, pos: Point, backend: &mut ItemRendererRef) {
(*backend).draw_rectangle(pos, self)
}
}
@ -272,7 +244,7 @@ impl Item for BorderRectangle {
fn focus_event(self: Pin<&Self>, _: &FocusEvent, _window: &ComponentWindow) {}
fn render(self: Pin<&Self>, pos: Point, backend: &mut &mut dyn ItemRenderer) {
fn render(self: Pin<&Self>, pos: Point, backend: &mut ItemRendererRef) {
(*backend).draw_border_rectangle(pos, self)
}
}
@ -384,7 +356,7 @@ impl Item for TouchArea {
fn focus_event(self: Pin<&Self>, _: &FocusEvent, _window: &ComponentWindow) {}
fn render(self: Pin<&Self>, _pos: Point, _backend: &mut &mut dyn ItemRenderer) {}
fn render(self: Pin<&Self>, _pos: Point, _backend: &mut ItemRendererRef) {}
}
impl ItemConsts for TouchArea {
@ -443,7 +415,7 @@ impl Item for Clip {
fn focus_event(self: Pin<&Self>, _: &FocusEvent, _window: &ComponentWindow) {}
fn render(self: Pin<&Self>, pos: Point, backend: &mut &mut dyn ItemRenderer) {
fn render(self: Pin<&Self>, pos: Point, backend: &mut ItemRendererRef) {
(*backend).combine_clip(pos, &self)
}
}
@ -506,7 +478,7 @@ impl Item for Path {
fn focus_event(self: Pin<&Self>, _: &FocusEvent, _window: &ComponentWindow) {}
fn render(self: Pin<&Self>, pos: Point, backend: &mut &mut dyn ItemRenderer) {
fn render(self: Pin<&Self>, pos: Point, backend: &mut ItemRendererRef) {
(*backend).draw_path(pos, self)
}
}
@ -580,7 +552,7 @@ impl Item for Flickable {
fn focus_event(self: Pin<&Self>, _: &FocusEvent, _window: &ComponentWindow) {}
fn render(self: Pin<&Self>, _pos: Point, _backend: &mut &mut dyn ItemRenderer) {}
fn render(self: Pin<&Self>, _pos: Point, _backend: &mut ItemRendererRef) {}
}
impl ItemConsts for Flickable {
@ -686,7 +658,7 @@ impl Item for Window {
fn focus_event(self: Pin<&Self>, _: &FocusEvent, _window: &ComponentWindow) {}
fn render(self: Pin<&Self>, _pos: Point, _backend: &mut &mut dyn ItemRenderer) {}
fn render(self: Pin<&Self>, _pos: Point, _backend: &mut ItemRendererRef) {}
}
impl ItemConsts for Window {