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
|
use iced::widget::{center, column, responsive};
use iced::{Center, Element, color};
use iced_selection::{rich_text, span};
fn main() -> iced::Result {
iced::run(State::update, State::view)
}
#[derive(Default)]
struct State {
link: Option<String>,
}
#[derive(Debug, Clone)]
enum Message {
LinkClicked(String),
}
impl State {
fn update(&mut self, message: Message) {
match message {
Message::LinkClicked(link) => {
let _ = open::that(&link);
self.link = Some(link);
}
};
}
fn view(&self) -> Element<'_, Message> {
responsive(|size| {
center(
column![
rich_text![
span("iced")
.color(color!(0x2b79a2))
.link("https://iced.rs"),
" is a cross-platform GUI library for ",
span("Rust")
.color(color!(0x2b79a2))
.link("https://rust-lang.org"),
". It is inspired by ",
span("Elm")
.color(color!(0x2b79a2))
.link("https://elm-lang.org"),
"."
]
.on_link_click(Message::LinkClicked),
self.link.as_deref().map(|link| rich_text![
"Last clicked link: ",
span(link).color(color!(0x2b79a2)).link(link)
]
.on_link_click(Message::LinkClicked))
]
.spacing(10)
.align_x(Center)
.max_width(size.width * 0.8),
)
.into()
})
.into()
}
}
|