pub struct Text<'a> { /* private fields */ }Implementations§
Source§impl<'a> Text<'a>
impl<'a> Text<'a>
Sourcepub fn width(&self) -> u32
pub fn width(&self) -> u32
Return width of the text
Examples found in repository?
examples/character_map.rs (line 35)
15fn main() {
16 let (title, font_res) = match env::args().nth(1) {
17 Some(arg) => (arg.clone(), Font::from_path(&arg)),
18 None => ("Default Font".to_string(), Font::find(None, None, None)),
19 };
20
21 match font_res {
22 Ok(font) => {
23 let lines = [
24 font.render("ABCDEFGHIJK", 64.0),
25 font.render("LMNOPQRSTUV", 64.0),
26 font.render("WXYZabcdefg", 64.0),
27 font.render("hijklmnopqr", 64.0),
28 font.render("stuvwxyz.?!", 64.0),
29 font.render("0123456789 ", 64.0),
30 ];
31
32 let mut width = 0;
33 let mut height = 0;
34 for line in lines.iter() {
35 width = max(width, line.width());
36 height += line.height();
37 }
38
39 let redraw = move |window: &mut Window| {
40 window.set(Color::rgb(255, 255, 255));
41 let mut y = 0;
42 for line in lines.iter() {
43 line.draw(window, 0, y, Color::rgb(0, 0, 0));
44 y += line.height() as i32;
45 }
46 window.sync();
47 };
48
49 let mut window = Window::new_flags(
50 -1,
51 -1,
52 max(320, width),
53 max(32, height),
54 &format!("{} - Character Map", title),
55 &[WindowFlag::Resizable],
56 )
57 .unwrap();
58
59 redraw(&mut window);
60
61 loop {
62 for event in window.events() {
63 match event.to_option() {
64 EventOption::Resize(_) => redraw(&mut window),
65 EventOption::Quit(_) => return,
66 _ => (),
67 }
68 }
69 }
70 }
71 Err(err) => {
72 let mut window =
73 Window::new(-1, -1, 320, 32, &format!("{} - Character Map", err)).unwrap();
74 window.set(Color::rgb(0, 0, 0));
75 window.sync();
76 loop {
77 for event in window.events() {
78 match event.to_option() {
79 EventOption::Quit(_) => return,
80 _ => (),
81 }
82 }
83 }
84 }
85 }
86}Sourcepub fn height(&self) -> u32
pub fn height(&self) -> u32
Return height of the text
Examples found in repository?
examples/character_map.rs (line 36)
15fn main() {
16 let (title, font_res) = match env::args().nth(1) {
17 Some(arg) => (arg.clone(), Font::from_path(&arg)),
18 None => ("Default Font".to_string(), Font::find(None, None, None)),
19 };
20
21 match font_res {
22 Ok(font) => {
23 let lines = [
24 font.render("ABCDEFGHIJK", 64.0),
25 font.render("LMNOPQRSTUV", 64.0),
26 font.render("WXYZabcdefg", 64.0),
27 font.render("hijklmnopqr", 64.0),
28 font.render("stuvwxyz.?!", 64.0),
29 font.render("0123456789 ", 64.0),
30 ];
31
32 let mut width = 0;
33 let mut height = 0;
34 for line in lines.iter() {
35 width = max(width, line.width());
36 height += line.height();
37 }
38
39 let redraw = move |window: &mut Window| {
40 window.set(Color::rgb(255, 255, 255));
41 let mut y = 0;
42 for line in lines.iter() {
43 line.draw(window, 0, y, Color::rgb(0, 0, 0));
44 y += line.height() as i32;
45 }
46 window.sync();
47 };
48
49 let mut window = Window::new_flags(
50 -1,
51 -1,
52 max(320, width),
53 max(32, height),
54 &format!("{} - Character Map", title),
55 &[WindowFlag::Resizable],
56 )
57 .unwrap();
58
59 redraw(&mut window);
60
61 loop {
62 for event in window.events() {
63 match event.to_option() {
64 EventOption::Resize(_) => redraw(&mut window),
65 EventOption::Quit(_) => return,
66 _ => (),
67 }
68 }
69 }
70 }
71 Err(err) => {
72 let mut window =
73 Window::new(-1, -1, 320, 32, &format!("{} - Character Map", err)).unwrap();
74 window.set(Color::rgb(0, 0, 0));
75 window.sync();
76 loop {
77 for event in window.events() {
78 match event.to_option() {
79 EventOption::Quit(_) => return,
80 _ => (),
81 }
82 }
83 }
84 }
85 }
86}Sourcepub fn draw_clipped<R: Renderer + ?Sized>(
&self,
renderer: &mut R,
x: i32,
y: i32,
bounds_x: i32,
bounds_width: u32,
color: Color,
)
pub fn draw_clipped<R: Renderer + ?Sized>( &self, renderer: &mut R, x: i32, y: i32, bounds_x: i32, bounds_width: u32, color: Color, )
Draw the text onto a window and clipp the text to the given bounds
Sourcepub fn draw<R: Renderer + ?Sized>(
&self,
renderer: &mut R,
x: i32,
y: i32,
color: Color,
)
pub fn draw<R: Renderer + ?Sized>( &self, renderer: &mut R, x: i32, y: i32, color: Color, )
Draw the text onto a window
Examples found in repository?
examples/character_map.rs (line 43)
15fn main() {
16 let (title, font_res) = match env::args().nth(1) {
17 Some(arg) => (arg.clone(), Font::from_path(&arg)),
18 None => ("Default Font".to_string(), Font::find(None, None, None)),
19 };
20
21 match font_res {
22 Ok(font) => {
23 let lines = [
24 font.render("ABCDEFGHIJK", 64.0),
25 font.render("LMNOPQRSTUV", 64.0),
26 font.render("WXYZabcdefg", 64.0),
27 font.render("hijklmnopqr", 64.0),
28 font.render("stuvwxyz.?!", 64.0),
29 font.render("0123456789 ", 64.0),
30 ];
31
32 let mut width = 0;
33 let mut height = 0;
34 for line in lines.iter() {
35 width = max(width, line.width());
36 height += line.height();
37 }
38
39 let redraw = move |window: &mut Window| {
40 window.set(Color::rgb(255, 255, 255));
41 let mut y = 0;
42 for line in lines.iter() {
43 line.draw(window, 0, y, Color::rgb(0, 0, 0));
44 y += line.height() as i32;
45 }
46 window.sync();
47 };
48
49 let mut window = Window::new_flags(
50 -1,
51 -1,
52 max(320, width),
53 max(32, height),
54 &format!("{} - Character Map", title),
55 &[WindowFlag::Resizable],
56 )
57 .unwrap();
58
59 redraw(&mut window);
60
61 loop {
62 for event in window.events() {
63 match event.to_option() {
64 EventOption::Resize(_) => redraw(&mut window),
65 EventOption::Quit(_) => return,
66 _ => (),
67 }
68 }
69 }
70 }
71 Err(err) => {
72 let mut window =
73 Window::new(-1, -1, 320, 32, &format!("{} - Character Map", err)).unwrap();
74 window.set(Color::rgb(0, 0, 0));
75 window.sync();
76 loop {
77 for event in window.events() {
78 match event.to_option() {
79 EventOption::Quit(_) => return,
80 _ => (),
81 }
82 }
83 }
84 }
85 }
86}Auto Trait Implementations§
impl<'a> Freeze for Text<'a>
impl<'a> RefUnwindSafe for Text<'a>
impl<'a> Send for Text<'a>
impl<'a> Sync for Text<'a>
impl<'a> Unpin for Text<'a>
impl<'a> UnsafeUnpin for Text<'a>
impl<'a> UnwindSafe for Text<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more