diff options
| author | Polesznyák Márk <contact@pml68.dev> | 2025-10-20 12:47:36 +0200 |
|---|---|---|
| committer | Polesznyák Márk <contact@pml68.dev> | 2025-10-20 12:51:08 +0200 |
| commit | e7509d41405a1f5af64f2f74166f2bc5f1673225 (patch) | |
| tree | c2e56fb086d83938d4c40238afccc66f925caacb /examples/rich/src | |
| parent | fix: markdown `Viewer` impl (diff) | |
| download | iced_selection-e7509d41405a1f5af64f2f74166f2bc5f1673225.tar.gz | |
feat: make markdown support optional with a feature flag
Diffstat (limited to 'examples/rich/src')
| -rw-r--r-- | examples/rich/src/main.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/examples/rich/src/main.rs b/examples/rich/src/main.rs new file mode 100644 index 0000000..6c47e0f --- /dev/null +++ b/examples/rich/src/main.rs @@ -0,0 +1,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() + } +} |
