aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex-ds13 <145657253+alex-ds13@users.noreply.github.com>2025-12-06 13:55:06 +0000
committerPolesznyák Márk <contact@pml68.dev>2025-12-30 18:36:11 +0100
commit9be486dd3f1f310e18bd400fb78257ab587e92e8 (patch)
tree0ec6dfe0b28bc0c78f9b190564eb1779568d14a2
parentfix(selectable): prevent clash with other's custom operations (diff)
downloadiced_selection-9be486dd3f1f310e18bd400fb78257ab587e92e8.tar.gz
fix(examples): add selectable to examples
- Adds the `selectable` to the rich and markdown examples. - Remove debug code from name example and make it simpler without the `selectable` so users know that the `selectable` is optional.
-rw-r--r--examples/markdown/src/main.rs7
-rw-r--r--examples/rich/src/main.rs133
-rw-r--r--src/lib.rs1
3 files changed, 73 insertions, 68 deletions
diff --git a/examples/markdown/src/main.rs b/examples/markdown/src/main.rs
index 4963792..ce5a58b 100644
--- a/examples/markdown/src/main.rs
+++ b/examples/markdown/src/main.rs
@@ -1,6 +1,6 @@
use iced::widget::{operation, row, scrollable, text_editor};
use iced::{Element, Fill, Font, Theme, highlighter};
-use iced_selection::markdown;
+use iced_selection::{markdown, selectable};
fn main() -> iced::Result {
iced::application(State::new, State::update, State::view)
@@ -65,7 +65,10 @@ impl State {
row![
editor,
- scrollable(preview).spacing(10).width(Fill).height(Fill)
+ scrollable(selectable(preview))
+ .spacing(10)
+ .width(Fill)
+ .height(Fill)
]
.spacing(10)
.padding(10)
diff --git a/examples/rich/src/main.rs b/examples/rich/src/main.rs
index 7cb3245..6e59680 100644
--- a/examples/rich/src/main.rs
+++ b/examples/rich/src/main.rs
@@ -1,6 +1,6 @@
use iced::widget::{column, container, responsive};
-use iced::{Center, Element, Fill, Font, color, font, padding};
-use iced_selection::{rich_text, span};
+use iced::{Element, Fill, Font, color, font, padding};
+use iced_selection::{rich_text, selectable, span};
fn main() -> iced::Result {
iced::application(State::default, State::update, State::view)
@@ -37,72 +37,73 @@ impl State {
fn view(&self) -> Element<'_, Message> {
responsive(|size| {
- container(
- 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"),
- ", a delightful functional language for building web applications.\n\n",
- "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.\n\n",
- "iced is strongly focused on ",
- span("simplicity")
- .font(Font {
- weight: font::Weight::Bold,
- ..Font::DEFAULT
- }),
- " and ",
- span("type-safety")
- .font(Font {
- weight: font::Weight::Bold,
- ..Font::DEFAULT
- }),
- ". As a result, iced tries to provide simple building blocks that can be put together with strong typing to reduce the chance of ",
- span("runtime errors")
- .font(Font {
- weight: font::Weight::Bold,
- ..Font::DEFAULT
- }),
- "."
+ selectable(
+ container(
+ 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"),
+ ", a delightful functional language for building web applications.\n\n",
+ "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.\n\n",
+ "iced is strongly focused on ",
+ span("simplicity")
+ .font(Font {
+ weight: font::Weight::Bold,
+ ..Font::DEFAULT
+ }),
+ " and ",
+ span("type-safety")
+ .font(Font {
+ weight: font::Weight::Bold,
+ ..Font::DEFAULT
+ }),
+ ". As a result, iced tries to provide simple building blocks that can be put together with strong typing to reduce the chance of ",
+ span("runtime errors")
+ .font(Font {
+ weight: font::Weight::Bold,
+ ..Font::DEFAULT
+ }),
+ "."
+ ]
+ .on_link_click(Message::LinkClicked)
+ .on_link_hover(Message::LinkHovered)
+ .on_hover_lost(Message::HoverLost),
+ 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_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)),
]
- .on_link_click(Message::LinkClicked)
- .on_link_hover(Message::LinkHovered)
- .on_hover_lost(Message::HoverLost),
- 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_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)),
- ]
- .spacing(10)
- .align_x(Center)
- .max_width(size.width * 0.8),
+ .spacing(10)
+ .max_width(size.width * 0.8),
+ )
+ .padding(padding::top(size.height * 0.4))
+ .center_x(Fill)
)
- .padding(padding::top(size.height * 0.4))
- .center_x(Fill)
.into()
})
.into()
diff --git a/src/lib.rs b/src/lib.rs
index d108c17..5707b98 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -11,6 +11,7 @@ pub mod selection;
pub mod text;
use core::Element;
+
use iced_widget::core;
use iced_widget::graphics::text::Paragraph;
#[cfg(feature = "markdown")]