summaryrefslogtreecommitdiffstats
path: root/native/src/renderer/null.rs
blob: fdb6ea92ae8e4721ffaca033cb83a3cab9cb1c34 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use crate::button;
use crate::checkbox;
use crate::pane_grid;
use crate::progress_bar;
use crate::radio;
use crate::renderer::{self, Renderer};
use crate::slider;
use crate::text;
use crate::text_input;
use crate::toggler;
use crate::{Font, Padding, Point, Rectangle, Size, Vector};

/// A renderer that does nothing.
///
/// It can be useful if you are writing tests!
#[derive(Debug, Clone, Copy)]
pub struct Null;

impl Null {
    /// Creates a new [`Null`] renderer.
    pub fn new() -> Null {
        Null
    }
}

impl Renderer for Null {
    fn with_layer(
        &mut self,
        _bounds: Rectangle,
        _offset: Vector<u32>,
        _f: impl FnOnce(&mut Self),
    ) {
    }

    fn clear(&mut self) {}

    fn fill_rectangle(&mut self, _quad: renderer::Quad) {}
}

impl renderer::Text for Null {
    type Font = Font;

    fn fill_text(&mut self, _text: renderer::text::Section<'_, Self::Font>) {}
}

impl text::Renderer for Null {
    fn default_size(&self) -> u16 {
        20
    }

    fn measure(
        &self,
        _content: &str,
        _size: u16,
        _font: Font,
        _bounds: Size,
    ) -> (f32, f32) {
        (0.0, 20.0)
    }

    fn hit_test(
        &self,
        _contents: &str,
        _size: f32,
        _font: Self::Font,
        _bounds: Size,
        _point: Point,
        _nearest_only: bool,
    ) -> Option<text::Hit> {
        None
    }
}

impl text_input::Renderer for Null {
    type Style = ();

    fn measure_value(&self, _value: &str, _size: u16, _font: Font) -> f32 {
        0.0
    }

    fn offset(
        &self,
        _text_bounds: Rectangle,
        _font: Font,
        _size: u16,
        _value: &text_input::Value,
        _state: &text_input::State,
    ) -> f32 {
        0.0
    }
}

impl button::Renderer for Null {
    const DEFAULT_PADDING: Padding = Padding::ZERO;

    type Style = ();
}

impl radio::Renderer for Null {
    type Style = ();

    const DEFAULT_SIZE: u16 = 20;
    const DEFAULT_SPACING: u16 = 15;
}

impl checkbox::Renderer for Null {
    type Style = ();

    const DEFAULT_SIZE: u16 = 20;
    const DEFAULT_SPACING: u16 = 15;
}

impl slider::Renderer for Null {
    type Style = ();

    const DEFAULT_HEIGHT: u16 = 30;
}

impl progress_bar::Renderer for Null {
    type Style = ();

    const DEFAULT_HEIGHT: u16 = 30;
}

impl pane_grid::Renderer for Null {
    type Style = ();
}

impl toggler::Renderer for Null {
    type Style = ();

    const DEFAULT_SIZE: u16 = 20;
}