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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! Stroke and shadow on text over a photograph.
//!
//! Run with: cargo run --example text_decoration_example
//!
//! The problem both solve: over a picture there is no single text colour that
//! works, because the picture is light in some places and dark in others. The
//! left column is the control — plain white, illegible wherever the photo is
//! bright. The others separate the glyphs from whatever is behind them.
use guido::prelude::*;
const LABEL: &str = "09:41";
fn photo() -> Container {
container().width(fill()).height(fill()).child(
image(ImageSource::Path("examples/assets/photo.webp".into()))
.content_fit(ContentFit::Cover),
)
}
/// One sample: the same text over the same photo, styled differently.
fn panel(caption: &'static str, styled: Text) -> Container {
container()
.layout(Flex::column().spacing(8.0))
.child(
container()
.width(240.0)
.height(120.0)
.corners(8.0)
.overflow(Overflow::Hidden)
.layout(ZStack::new())
.child(photo())
.child(
container()
.width(fill())
.height(fill())
.layout(Flex::column().center())
.child(styled.font_size(52.0).color(Color::WHITE).nowrap()),
),
)
.child(
container().child(
text(caption)
.font_size(12.0)
.color(Color::rgb(0.7, 0.7, 0.75)),
),
)
}
fn main() {
env_logger::init();
App::new().run(|app| {
let view = container()
.padding(24.0)
.layout(Flex::row().spacing(20.0))
.child(panel("nothing", text(LABEL)))
.child(panel(
"stroke 1.5",
text(LABEL).text_stroke(TextStroke::new(1.5, Color::BLACK)),
))
.child(panel(
"shadow 0,2 blur 10",
text(LABEL).text_shadow(TextShadow::new(
0.0,
2.0,
10.0,
Color::rgba(0.0, 0.0, 0.0, 0.75),
)),
))
.child(panel(
"both",
text(LABEL)
.text_stroke(TextStroke::new(1.0, Color::rgba(0.0, 0.0, 0.0, 0.6)))
.text_shadow(TextShadow::new(
0.0,
2.0,
8.0,
Color::rgba(0.0, 0.0, 0.0, 0.6),
)),
));
app.add_surface(
SurfaceConfig::new()
.width(1080)
.height(210)
.anchor(Anchor::TOP | Anchor::LEFT)
.layer(Layer::Top)
.namespace("text-decoration-example")
.background_color(Color::rgb(0.1, 0.1, 0.15)),
|| view,
);
});
}