Add Link support to rich_text widget

This commit is contained in:
Héctor Ramón Jiménez 2024-07-21 12:45:05 +02:00
parent 4b44079f34
commit 9bfaf2840c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
9 changed files with 287 additions and 71 deletions

View file

@ -8,3 +8,5 @@ publish = false
[dependencies]
iced.workspace = true
iced.features = ["markdown", "highlighter", "debug"]
open = "5.3"

View file

@ -16,6 +16,7 @@ struct Markdown {
#[derive(Debug, Clone)]
enum Message {
Edit(text_editor::Action),
LinkClicked(String),
}
impl Markdown {
@ -50,6 +51,9 @@ impl Markdown {
.collect();
}
}
Message::LinkClicked(link) => {
let _ = open::that(link);
}
}
}
@ -60,7 +64,7 @@ impl Markdown {
.padding(10)
.font(Font::MONOSPACE);
let preview = markdown(&self.items);
let preview = markdown(&self.items, Message::LinkClicked);
row![editor, scrollable(preview).spacing(10).height(Fill)]
.spacing(10)