2019-08-29 01:35:37 +02:00
|
|
|
//! Write your own renderer.
|
2019-12-29 12:29:47 +01:00
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
|
mod null;
|
2023-03-04 05:37:11 +01:00
|
|
|
|
2019-11-21 13:47:20 +01:00
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
|
pub use null::Null;
|
2019-10-05 03:56:18 +02:00
|
|
|
|
2024-01-20 13:29:25 +01:00
|
|
|
use crate::{Background, Border, Color, Rectangle, Shadow, Size, Vector};
|
2019-11-11 06:07:31 +01:00
|
|
|
|
2022-04-30 14:20:52 +02:00
|
|
|
/// A component that can be used by widgets to draw themselves on a screen.
|
2019-11-11 06:07:31 +01:00
|
|
|
pub trait Renderer: Sized {
|
2021-11-04 19:22:29 +07:00
|
|
|
/// Draws the primitives recorded in the given closure in a new layer.
|
|
|
|
|
///
|
|
|
|
|
/// The layer will clip its contents to the provided `bounds`.
|
2021-10-25 16:16:35 +07:00
|
|
|
fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self));
|
|
|
|
|
|
2021-11-04 19:22:29 +07:00
|
|
|
/// Applies a `translation` to the primitives recorded in the given closure.
|
2021-10-25 16:16:35 +07:00
|
|
|
fn with_translation(
|
2021-10-14 17:15:29 +07:00
|
|
|
&mut self,
|
2021-10-25 16:16:35 +07:00
|
|
|
translation: Vector,
|
2021-10-14 17:15:29 +07:00
|
|
|
f: impl FnOnce(&mut Self),
|
|
|
|
|
);
|
2021-10-14 16:59:19 +07:00
|
|
|
|
2021-11-04 19:22:29 +07:00
|
|
|
/// Fills a [`Quad`] with the provided [`Background`].
|
|
|
|
|
fn fill_quad(&mut self, quad: Quad, background: impl Into<Background>);
|
2023-01-12 02:59:08 +01:00
|
|
|
|
|
|
|
|
/// Clears all of the recorded primitives in the [`Renderer`].
|
|
|
|
|
fn clear(&mut self);
|
2021-10-18 14:47:49 +07:00
|
|
|
}
|
|
|
|
|
|
2021-11-05 15:31:33 +07:00
|
|
|
/// A polygon with four sides.
|
2021-10-18 14:47:49 +07:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
|
pub struct Quad {
|
2021-11-05 15:31:33 +07:00
|
|
|
/// The bounds of the [`Quad`].
|
2021-10-18 14:47:49 +07:00
|
|
|
pub bounds: Rectangle,
|
2021-11-05 15:31:33 +07:00
|
|
|
|
2024-01-20 13:29:25 +01:00
|
|
|
/// The [`Border`] of the [`Quad`].
|
|
|
|
|
pub border: Border,
|
2021-11-05 15:31:33 +07:00
|
|
|
|
2024-01-20 13:29:25 +01:00
|
|
|
/// The [`Shadow`] of the [`Quad`].
|
|
|
|
|
pub shadow: Shadow,
|
2024-01-20 12:11:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for Quad {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
bounds: Rectangle::with_size(Size::ZERO),
|
2024-01-20 13:29:25 +01:00
|
|
|
border: Border::default(),
|
|
|
|
|
shadow: Shadow::default(),
|
2024-01-20 12:11:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-10-05 03:56:18 +02:00
|
|
|
}
|
2021-10-18 15:19:04 +07:00
|
|
|
|
|
|
|
|
/// The styling attributes of a [`Renderer`].
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
|
pub struct Style {
|
|
|
|
|
/// The text color
|
|
|
|
|
pub text_color: Color,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for Style {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Style {
|
|
|
|
|
text_color: Color::BLACK,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|