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
use crate::prelude::*;
#[derive(Default)]
pub struct CursorState;
impl State for CursorState {
fn update_post_layout(&self, ctx: &mut Context<'_>) {
let mut widget = ctx.widget();
let selection_length = widget.get::<TextSelection>("text_selection").length;
if selection_length > 0 {
add_selector_to_widget("expanded", &mut widget);
} else {
remove_selector_from_widget("expanded", &mut widget)
}
if *widget.get::<bool>("focused") {
widget.set("visibility", Visibility::from("visible"));
} else {
widget.set("visibility", Visibility::from("collapsed"));
}
}
}
widget!(
Cursor<CursorState> {
text: String16,
text_selection: TextSelection,
background: Brush,
font_size: f64,
font: String,
scroll_offset: Point,
focused: bool,
selector: Selector
}
);
impl Template for Cursor {
fn template(self, _: Entity, _: &mut BuildContext) -> Self {
self.name("Cursor")
.width(1.0)
.selector("cursor")
.text("")
.scroll_offset(0.0)
.background("transparent")
.font_size(fonts::FONT_SIZE_12)
.font("Roboto Regular")
.focused(false)
}
fn render_object(&self) -> Box<dyn RenderObject> {
Box::new(RectangleRenderObject)
}
fn layout(&self) -> Box<dyn Layout> {
Box::new(TextSelectionLayout::default())
}
}