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
use Rc;
use Mutex;
use crate*;
/// This widget isn't so special on its own,
/// but if you need direct access to a widget
/// that you cannot otherwise access, this is
/// what you would use
///
/// # Examples:
/// ```rust
/// use tuigui::{ widgets, Style };
///
/// fn main() {
/// // Let's say I wanna change this label's text
/// // after passing it to another widget which doesn't
/// // let me directly access this label widget.
/// let my_label = widgets::label::Label::new(
/// "foobar",
/// widgets::label::LabelStyle::Single(Style::new()),
/// false,
/// );
///
/// // Well in a BoxContainer or other widgets that use dynamic
/// // dispatch or have private fields, you cannot directly
/// // access the widget directly. So... you need a pointer!
/// // The reason there is a dedicated WidgetPointer type is
/// // because it implements the tuigui::Widget trait, thus it
/// // can be used as a normal wrapper widget around our real widget.
/// let my_label_ptr = widgets::widget_pointer::WidgetPointer::new(my_label);
///
/// // This is a perfect example, since BoxContainer uses
/// // Vec<Box<dyn tuigui::Widget>> under the hood to store
/// // its widgets. This is a problem when you want to access
/// // your widget, since it is stored in a vector that uses
/// // dynamic dispatch.
/// let box_container = widgets::box_container::BoxContainer::new(
/// widgets::box_container::Orientation::Vertical,
/// vec![
/// my_label_ptr.clone(),
/// ],
/// );
///
/// // But, since we passed in a clone of the label pointer,
/// // we can access its data!
/// let old_label_text: String = my_label_ptr.pointer.lock().unwrap().label.clone();
/// my_label_ptr.pointer.lock().unwrap().set_label("ABC XYZ");
/// }
/// ```