pub struct TextInput { /* private fields */ }
Expand description
The TextInput
widget that allows the user to enter text.
Implementations§
Source§impl TextInput
impl TextInput
Sourcepub fn new(
width: f32,
height: f32,
bg: Color,
fg: Color,
font: Option<Font>,
) -> Self
pub fn new( width: f32, height: f32, bg: Color, fg: Color, font: Option<Font>, ) -> Self
Creates a new TextInput
widget.
Examples found in repository?
examples/textinp.rs (line 8)
5async fn main() {
6 let poppins = load_ttf_font("examples/poppins.ttf").await.unwrap();
7 let label = Label::new("Text Inputs!".to_string(), Color::new(0.05, 0.05, 0.1, 1.0), Color::new(0.5, 0.5, 1.0, 1.0), Some(poppins.clone()), 48.0);
8 let textinp = TextInput::new(512.0, 64.0, Color::new(0.05, 0.05, 0.1, 1.0), Color::new(0.5, 0.5, 1.0, 1.0), Some(poppins.clone()));
9 let textinp2 = TextInput::new(512.0, 64.0, Color::new(0.05, 0.05, 0.1, 1.0), Color::new(0.5, 0.5, 1.0, 1.0), Some(poppins.clone()));
10 let mut container = Container::new(Direction::Vertical, Align::Center, 20.0, Color::new(0.05, 0.05, 0.1, 1.0), None, None);
11 container.add_child(Box::new(label));
12 container.add_child(Box::new(textinp));
13 container.add_child(Box::new(textinp2));
14
15 let mut previous_text = String::new();
16 let mut previous_text2 = String::new();
17
18 loop {
19 clear_background(Color::new(0.05, 0.05, 0.1, 1.0));
20
21 container.update(screen_width() / 2.0 - container.width() / 2.0, screen_height() / 2.0 - container.height() / 2.0);
22 container.render(screen_width() / 2.0 - container.width() / 2.0, screen_height() / 2.0 - container.height() / 2.0);
23 // println!("Text: {}", container.get_child_as::<TextInput>(1).unwrap().get_text());
24 // println!("Text2: {}", container.get_child_as::<TextInput>(2).unwrap().get_text());
25 let textinp = container.get_child_as::<TextInput>(1).unwrap();
26 let textinp2 = container.get_child_as::<TextInput>(2).unwrap();
27 if textinp.get_text() != previous_text {
28 println!("Text: {}", textinp.get_text());
29 previous_text = textinp.get_text();
30 }
31 if textinp2.get_text() != previous_text2 {
32 println!("Text2: {}", textinp2.get_text());
33 previous_text2 = textinp2.get_text();
34 }
35
36 next_frame().await;
37 }
38}
Sourcepub fn get_text(&self) -> String
pub fn get_text(&self) -> String
Returns the text entered in the TextInput
widget.
Examples found in repository?
examples/textinp.rs (line 27)
5async fn main() {
6 let poppins = load_ttf_font("examples/poppins.ttf").await.unwrap();
7 let label = Label::new("Text Inputs!".to_string(), Color::new(0.05, 0.05, 0.1, 1.0), Color::new(0.5, 0.5, 1.0, 1.0), Some(poppins.clone()), 48.0);
8 let textinp = TextInput::new(512.0, 64.0, Color::new(0.05, 0.05, 0.1, 1.0), Color::new(0.5, 0.5, 1.0, 1.0), Some(poppins.clone()));
9 let textinp2 = TextInput::new(512.0, 64.0, Color::new(0.05, 0.05, 0.1, 1.0), Color::new(0.5, 0.5, 1.0, 1.0), Some(poppins.clone()));
10 let mut container = Container::new(Direction::Vertical, Align::Center, 20.0, Color::new(0.05, 0.05, 0.1, 1.0), None, None);
11 container.add_child(Box::new(label));
12 container.add_child(Box::new(textinp));
13 container.add_child(Box::new(textinp2));
14
15 let mut previous_text = String::new();
16 let mut previous_text2 = String::new();
17
18 loop {
19 clear_background(Color::new(0.05, 0.05, 0.1, 1.0));
20
21 container.update(screen_width() / 2.0 - container.width() / 2.0, screen_height() / 2.0 - container.height() / 2.0);
22 container.render(screen_width() / 2.0 - container.width() / 2.0, screen_height() / 2.0 - container.height() / 2.0);
23 // println!("Text: {}", container.get_child_as::<TextInput>(1).unwrap().get_text());
24 // println!("Text2: {}", container.get_child_as::<TextInput>(2).unwrap().get_text());
25 let textinp = container.get_child_as::<TextInput>(1).unwrap();
26 let textinp2 = container.get_child_as::<TextInput>(2).unwrap();
27 if textinp.get_text() != previous_text {
28 println!("Text: {}", textinp.get_text());
29 previous_text = textinp.get_text();
30 }
31 if textinp2.get_text() != previous_text2 {
32 println!("Text2: {}", textinp2.get_text());
33 previous_text2 = textinp2.get_text();
34 }
35
36 next_frame().await;
37 }
38}
Trait Implementations§
Source§impl Action for TextInput
impl Action for TextInput
Source§fn is_clicked(&self) -> bool
fn is_clicked(&self) -> bool
Returns if the widget is clicked.
Source§fn is_hovered(&self) -> bool
fn is_hovered(&self) -> bool
Returns if the widget is hovered.
Auto Trait Implementations§
impl Freeze for TextInput
impl RefUnwindSafe for TextInput
impl Send for TextInput
impl Sync for TextInput
impl Unpin for TextInput
impl UnwindSafe for TextInput
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