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
//! A text input, primarily use for text fields.

use std::cell::RefCell;
use std::rc::Rc;

pub struct TextInput {
    pub(crate) text: Rc<RefCell<(String, bool)>>,
}

impl TextInput {
    pub fn get_text(&self) -> String {
        self.text.borrow().0.clone()
    }

    pub fn start(&mut self) {
        *self.text.borrow_mut() = (String::new(), true);
    }

    pub fn stop(&mut self) {
        self.text.borrow_mut().1 = false;
    }

    pub fn reading(&mut self) -> bool {
        self.text.borrow().1
    }
}