1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

//! Graphics control the visual appearance of Widgets.
//!
//! Some widgets will simply contain other widgets (their "children"), but
//! in order to have visuals, widgets need a way to interface with the
//! renderer.  The Graphic trait in this module provides this interface.
//!
//! Because Graphic implementations are tightly coupled with the renderer,
//! there are no actual implementations in this module; Suzy's "built-in"
//! graphics can be found in the
//! [module for the opengl platform](../platform/opengl/index.html)

mod color;
mod context;

pub use color::{Color, ParseColorError};
pub use context::{DrawContext, DrawParams, DrawPass};

use crate::platform::{DefaultRenderPlatform, RenderPlatform};

/// A trait which represents a drawable graphic.
///
/// See [module-level documentation](index.html) for more information.
pub trait Graphic<P = DefaultRenderPlatform>
where
    P: RenderPlatform + ?Sized,
{
    /// Draw this graphic.
    fn draw(&mut self, ctx: &mut DrawContext<P>);
}

impl<P: RenderPlatform + ?Sized> Graphic<P> for () {
    fn draw(&mut self, _ctx: &mut DrawContext<P>) {}
}

impl<P: RenderPlatform + ?Sized> Graphic<P> for [(); 0] {
    fn draw(&mut self, _ctx: &mut DrawContext<P>) {}
}

impl<P: RenderPlatform + ?Sized, T: Graphic<P>> Graphic<P> for [T] {
    fn draw(&mut self, ctx: &mut DrawContext<P>) {
        for graphic in self {
            graphic.draw(ctx);
        }
    }
}