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
use super::*;

/// Represents an ttf font
///
/// Use with `FormattedText` to render text this font.
#[derive(Debug, Clone, PartialEq)]
pub struct Font {
    data: WorldData,
}

#[allow(dead_code)]
impl Font {
    /// Creates a new `Font`. This creates a data object in the host that can be shared
    /// for multiple entities.
    pub fn new(handle: ffi::ResourceHandleRepr, scale: f32) -> Self {
        let data = WorldData::create_struct(
            ffi::CreateDataType::Font,
            &ffi::v4::FontResource { handle, scale },
        );
        Self { data }
    }

    /// Sets a debug name of this data object. Useful for debugging memory usage and leaks.
    pub fn set_debug_name(&self, name: &str) {
        self.data.set_debug_name(name);
    }

    /// Get raw data handle.
    pub fn data_handle(&self) -> DataHandle {
        self.data.get_data_handle()
    }
}

impl ValueConverterTrait<Font> for ValueConverter {
    fn into_value(v: Font) -> Value {
        <Self as ValueConverterTrait<WorldData>>::into_value(v.data)
    }
    fn from_value(v: &Value) -> Font {
        Font {
            data: <Self as ValueConverterTrait<WorldData>>::from_value(v),
        }
    }
}