pub trait Renderer {
fn renderable_area(&self) -> BBox;
fn render(&self, object: &dyn Widget, bbox: BBox, cap: &dyn Cap) -> BBox;
fn pre_render(&self) { ... }
fn post_render(&self) { ... }
}
Expand description
An abstraction for objects used for rendering widgets.
Required Methods
sourcefn renderable_area(&self) -> BBox
fn renderable_area(&self) -> BBox
Retrieve the bounding box of the renderable area (typically the
screen).
Note that the units to be used are not specified. That is, the
result could be in pixels, characters (in case of a terminal), or
just arbitrary numbers (if virtual coordinates are being used), as
long as this Renderer
knows how to interpret them.
sourcefn render(&self, object: &dyn Widget, bbox: BBox, cap: &dyn Cap) -> BBox
fn render(&self, object: &dyn Widget, bbox: BBox, cap: &dyn Cap) -> BBox
Render an object.
Objects are represented as Widget
and need to be cast into the
actual widget type to render by the Renderer
itself, should that
be necessary. A simplified implementation could look as follows:
fn render(&self, widget: &dyn Widget, bbox: BBox, cap: &dyn Cap) -> BBox {
if let Some(widget1) = widget.downcast_ref::<ConcreteWidget1>() {
self.render_concrete_widget1(widget1, bbox)
} else if let Some(widget2) = widget.downcast_ref::<ConcreteWidget1>() {
self.render_concrete_widget2(widget2, bbox)
} else {
panic!("Widget {:?} is unknown to the renderer", widget)
}
}
Provided Methods
sourcefn pre_render(&self)
fn pre_render(&self)
Perform some pre-render step.
sourcefn post_render(&self)
fn post_render(&self)
Perform some post-render step.