summaryrefslogtreecommitdiffstats
path: root/native/src/renderer/windowed.rs
blob: 89f80bbea3aaaaa8dd36f317df0e192a40198706 (plain) (blame)
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
50
51
52
53
54
55
56
use crate::{Color, MouseCursor};

use raw_window_handle::HasRawWindowHandle;

/// A renderer that can target windows.
pub trait Windowed: super::Renderer + Sized {
    /// The type of target.
    type Target: Target<Renderer = Self>;

    /// Creates a new [`Windowed`] renderer.
    ///
    /// [`Windowed`]: trait.Windowed.html
    fn new() -> Self;

    /// Performs the drawing operations described in the output on the given
    /// target.
    ///
    /// The overlay can be a bunch of debug text logs. It should be rendered on
    /// top of the GUI on most scenarios.
    fn draw<T: AsRef<str>>(
        &mut self,
        clear_color: Color,
        output: &Self::Output,
        overlay: &[T],
        target: &mut Self::Target,
    ) -> MouseCursor;
}

/// A rendering target.
pub trait Target {
    /// The renderer of this target.
    type Renderer;

    /// Creates a new rendering [`Target`] from the given window handle, width,
    /// height and dpi factor.
    ///
    /// [`Target`]: trait.Target.html
    fn new<W: HasRawWindowHandle>(
        window: &W,
        width: u16,
        height: u16,
        dpi: f32,
        renderer: &Self::Renderer,
    ) -> Self;

    /// Resizes the current [`Target`].
    ///
    /// [`Target`]: trait.Target.html
    fn resize(
        &mut self,
        width: u16,
        height: u16,
        dpi: f32,
        renderer: &Self::Renderer,
    );
}