aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/rich/src/main.rs50
1 files changed, 41 insertions, 9 deletions
diff --git a/examples/rich/src/main.rs b/examples/rich/src/main.rs
index f8f7414..095651a 100644
--- a/examples/rich/src/main.rs
+++ b/examples/rich/src/main.rs
@@ -1,5 +1,5 @@
-use iced::widget::{center, column, responsive};
-use iced::{Center, Element, color};
+use iced::widget::{column, container, responsive};
+use iced::{Center, Element, Fill, Font, color, font, padding};
use iced_selection::{rich_text, span};
fn main() -> iced::Result {
@@ -8,12 +8,15 @@ fn main() -> iced::Result {
#[derive(Default)]
struct State {
- link: Option<String>,
+ clicked: Option<String>,
+ hovered: Option<String>,
}
#[derive(Debug, Clone)]
enum Message {
LinkClicked(String),
+ LinkHovered(String),
+ HoverLost,
}
impl State {
@@ -21,14 +24,18 @@ impl State {
match message {
Message::LinkClicked(link) => {
let _ = open::that_in_background(&link);
- self.link = Some(link);
+ self.clicked = Some(link);
}
+ Message::LinkHovered(link) => {
+ self.hovered = Some(link);
+ }
+ Message::HoverLost => self.hovered = None,
};
}
fn view(&self) -> Element<'_, Message> {
responsive(|size| {
- center(
+ container(
column![
rich_text![
span("iced")
@@ -42,19 +49,44 @@ impl State {
span("Elm")
.color(color!(0x2b79a2))
.link("https://elm-lang.org"),
- "."
+ ", a delightful functional language for building web applications."
+ ]
+ .on_link_click(Message::LinkClicked)
+ .on_link_hover(Message::LinkHovered)
+ .on_hover_lost(Message::HoverLost),
+ rich_text![
+ "As a GUI library, iced helps you build ",
+ span("graphical user interfaces")
+ .color(color!(0x2b79a2))
+ .link("https://en.wikipedia.org/wiki/Graphical_user_interface")
+ .font(Font {
+ style:font::Style::Italic,
+ ..Font::DEFAULT
+ }),
+ " for your Rust applications."
+ ]
+ .on_link_click(Message::LinkClicked)
+ .on_link_hover(Message::LinkHovered)
+ .on_hover_lost(Message::HoverLost),
+ self.hovered.as_deref().map(|link| rich_text![
+ "Currently hovered link: ",
+ span(link).color(color!(0x2b79a2)).link(link)
]
- .on_link_click(Message::LinkClicked),
- self.link.as_deref().map(|link| rich_text![
+ .on_link_click(Message::LinkClicked)),
+ self.clicked.as_deref().map(|link| rich_text![
"Last clicked link: ",
span(link).color(color!(0x2b79a2)).link(link)
]
- .on_link_click(Message::LinkClicked))
+ .on_link_click(Message::LinkClicked)
+ .on_link_hover(Message::LinkHovered)
+ .on_hover_lost(Message::HoverLost))
]
.spacing(10)
.align_x(Center)
.max_width(size.width * 0.8),
)
+ .padding(padding::top(size.height * 0.4))
+ .center_x(Fill)
.into()
})
.into()