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
#![warn(missing_docs)]
use rich_sdl2_rust::{Result, Sdl, SdlError, SdlVersion};
use static_assertions::assert_not_impl_all;
use std::{cell::Cell, marker::PhantomData, os::raw::c_int};
#[allow(warnings)]
mod bind;
pub mod font;
pub mod script;
#[derive(Debug)]
pub struct Ttf {
_phantom: PhantomData<Cell<u8>>,
}
assert_not_impl_all!(Ttf: Send, Sync);
impl Ttf {
pub fn new() -> Self {
let ret = unsafe { bind::TTF_Init() };
if ret == -1 {
Sdl::error_then_panic("Ttf");
}
Self {
_phantom: PhantomData,
}
}
pub fn version() -> SdlVersion {
let raw = unsafe { &*bind::TTF_Linked_Version() };
SdlVersion {
major: raw.major,
minor: raw.minor,
patch: raw.patch,
}
}
}
impl Drop for Ttf {
fn drop(&mut self) {
unsafe { bind::TTF_Quit() }
}
}
impl Default for Ttf {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Direction {
Ltr,
Rtl,
Ttb,
Btt,
}
impl Direction {
fn into_raw(self) -> c_int {
match self {
Direction::Ltr => 4,
Direction::Rtl => 5,
Direction::Ttb => 6,
Direction::Btt => 7,
}
}
pub fn set_direction(self) -> Result<()> {
let ret = unsafe { bind::TTF_SetDirection(self.into_raw()) };
if ret != 0 {
Err(SdlError::UnsupportedFeature)
} else {
Ok(())
}
}
}