pub struct Text { /* private fields */ }
Expand description
§Text struct
Text is a drawable entity that can be used to display text. The text need a MutResource because the text mut the internal texture of his font.
Implementations§
Source§impl Text
impl Text
Sourcepub fn new(font: &Rc<RefCell<Font>>) -> Text
pub fn new(font: &Rc<RefCell<Font>>) -> Text
Create a new text from a font previously created
Examples found in repository?
examples/font.rs (line 21)
8fn main() {
9 // Create drawer window
10 let mut window = Window::new(gust::WIDTH, gust::HEIGHT, "Hello");
11
12 // Create event handler
13 let event_handler = EventHandler::new(&window);
14
15 // Create font
16 let font = Rc::new(RefCell::new(
17 Font::from_path("examples/font/test.ttf").unwrap(),
18 ));
19
20 // Create text with font
21 let mut text = Text::new(&font);
22 text.set_content("Welcome to Gust you can write text and\na lot more !\t(Like tabs)");
23 text.set_position(Vector::new(100.0, 100.0));
24
25 // Create a 2nd text with font
26 let mut text2 = Text::from_str(&font, "Salut !");
27 text2.set_position(Vector::new(200.0, 200.0));
28 text2.update();
29
30 // Loop preparation
31 window.set_clear_color(Color::new(0.0, 0.0, 0.0));
32 window.enable_cursor();
33 window.poll(None);
34 while window.is_open() {
35 // update text
36 text.update();
37
38 // Poll event
39 window.poll_events();
40 event_handler
41 .fetch()
42 .for_each(|event| handle(&event, &mut window, &mut text));
43
44 // Draw process (Clear -> Draw -> Display)
45 window.clear();
46 window.draw(&text);
47 window.draw(&text2);
48 window.display();
49 }
50}
Sourcepub fn from_str(font: &Rc<RefCell<Font>>, content: &str) -> Text
pub fn from_str(font: &Rc<RefCell<Font>>, content: &str) -> Text
Create a text from it’s content and a font
Examples found in repository?
examples/multi_window.rs (line 49)
44fn window2() -> Result<(), Box<Error>> {
45 let mut window = Window::new(500, 500, "Hello2");
46 let font = Rc::new(RefCell::new(
47 Font::from_path("examples/font/terminus.ttf").unwrap(),
48 ));
49 let mut text = Text::from_str(&font, "I've been looking forward to this.");
50 text.set_position(Vector::new(5.0, 40.0));
51 let event_handler = EventHandler::new(&window);
52
53 window.set_clear_color(Color::new(1.0, 0.0, 1.0));
54 window.enable_cursor();
55 window.poll(None);
56
57 while window.is_open() {
58 text.update();
59 window.poll_events();
60
61 for event in event_handler.fetch() {
62 event_process(event, &mut window);
63 }
64
65 window.clear();
66 window.draw(&mut text);
67 window.display();
68 }
69 Ok(())
70}
More examples
examples/font.rs (line 26)
8fn main() {
9 // Create drawer window
10 let mut window = Window::new(gust::WIDTH, gust::HEIGHT, "Hello");
11
12 // Create event handler
13 let event_handler = EventHandler::new(&window);
14
15 // Create font
16 let font = Rc::new(RefCell::new(
17 Font::from_path("examples/font/test.ttf").unwrap(),
18 ));
19
20 // Create text with font
21 let mut text = Text::new(&font);
22 text.set_content("Welcome to Gust you can write text and\na lot more !\t(Like tabs)");
23 text.set_position(Vector::new(100.0, 100.0));
24
25 // Create a 2nd text with font
26 let mut text2 = Text::from_str(&font, "Salut !");
27 text2.set_position(Vector::new(200.0, 200.0));
28 text2.update();
29
30 // Loop preparation
31 window.set_clear_color(Color::new(0.0, 0.0, 0.0));
32 window.enable_cursor();
33 window.poll(None);
34 while window.is_open() {
35 // update text
36 text.update();
37
38 // Poll event
39 window.poll_events();
40 event_handler
41 .fetch()
42 .for_each(|event| handle(&event, &mut window, &mut text));
43
44 // Draw process (Clear -> Draw -> Display)
45 window.clear();
46 window.draw(&text);
47 window.draw(&text2);
48 window.display();
49 }
50}
Sourcepub fn set_content(&mut self, content: &str)
pub fn set_content(&mut self, content: &str)
Set the content of the text
Examples found in repository?
examples/font.rs (line 22)
8fn main() {
9 // Create drawer window
10 let mut window = Window::new(gust::WIDTH, gust::HEIGHT, "Hello");
11
12 // Create event handler
13 let event_handler = EventHandler::new(&window);
14
15 // Create font
16 let font = Rc::new(RefCell::new(
17 Font::from_path("examples/font/test.ttf").unwrap(),
18 ));
19
20 // Create text with font
21 let mut text = Text::new(&font);
22 text.set_content("Welcome to Gust you can write text and\na lot more !\t(Like tabs)");
23 text.set_position(Vector::new(100.0, 100.0));
24
25 // Create a 2nd text with font
26 let mut text2 = Text::from_str(&font, "Salut !");
27 text2.set_position(Vector::new(200.0, 200.0));
28 text2.update();
29
30 // Loop preparation
31 window.set_clear_color(Color::new(0.0, 0.0, 0.0));
32 window.enable_cursor();
33 window.poll(None);
34 while window.is_open() {
35 // update text
36 text.update();
37
38 // Poll event
39 window.poll_events();
40 event_handler
41 .fetch()
42 .for_each(|event| handle(&event, &mut window, &mut text));
43
44 // Draw process (Clear -> Draw -> Display)
45 window.clear();
46 window.draw(&text);
47 window.draw(&text2);
48 window.display();
49 }
50}
Sourcepub fn content_mut(&mut self) -> &mut String
pub fn content_mut(&mut self) -> &mut String
Get the content of the text as &mut String
Trait Implementations§
Source§impl Drawable for Text
impl Drawable for Text
Source§fn update(&mut self)
fn update(&mut self)
Update the openGL state of the drawable entity
Should be call often so be carefull when implementing.
Source§fn draw<T: Drawer>(&self, target: &mut T)
fn draw<T: Drawer>(&self, target: &mut T)
Draw the drawable structure, you need a Drawer(Where the struct will be draw)
Source§fn draw_with_context(&self, context: &mut Context<'_>)
fn draw_with_context(&self, context: &mut Context<'_>)
Draw with a particular context
Source§fn setup_draw(&self, context: &mut Context<'_>)
fn setup_draw(&self, context: &mut Context<'_>)
Setup the draw for the final system you don’t have to implement it in a normal drawable
Source§impl DrawableMut for Text
impl DrawableMut for Text
Source§impl Rotable for Text
impl Rotable for Text
Source§fn rotate<T>(&mut self, _angle: T)
fn rotate<T>(&mut self, _angle: T)
Rotate from the actual angle with the angle given in argument.
Source§fn set_rotation<T>(&mut self, _angle: T)
fn set_rotation<T>(&mut self, _angle: T)
Set the rotation of the Rotable struct.
Source§fn get_rotation(&self) -> f32
fn get_rotation(&self) -> f32
Return the rotation of the struct.
Auto Trait Implementations§
impl Freeze for Text
impl !RefUnwindSafe for Text
impl !Send for Text
impl !Sync for Text
impl Unpin for Text
impl !UnwindSafe for Text
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SetParameter for T
impl<T> SetParameter for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.