aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authoralex-ds13 <145657253+alex-ds13@users.noreply.github.com>2025-12-04 02:40:12 +0000
committerPolesznyák Márk <contact@pml68.dev>2025-12-30 18:13:59 +0100
commitde65c1dc7285b15c87862198b98b435345715d7d (patch)
treeb864fda857f039595990405c2143d80ebbe8029a /src/lib.rs
parentfeat: implement selection across bounds with hacky copy solution (diff)
downloadiced_selection-de65c1dc7285b15c87862198b98b435345715d7d.tar.gz
feat(selectable): draft implementation of selectable widget
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 34c1f73..c1c41cf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,9 +5,12 @@
#[cfg(feature = "markdown")]
pub mod markdown;
+pub mod operation;
+pub mod selectable;
pub mod selection;
pub mod text;
+use core::Element;
use iced_widget::core;
use iced_widget::graphics::text::Paragraph;
#[cfg(feature = "markdown")]
@@ -225,3 +228,45 @@ pub fn span<'a, Link>(
) -> text::Span<'a, Link, core::Font> {
text::Span::new(text)
}
+
+/// Creates some [`Selectable`] with the given content.
+///
+/// [`Selectable`]: crate::selectable::Selectable
+///
+/// # Example
+/// ```no_run,ignore
+/// use iced::font;
+/// use iced_selection::{rich_text, selectable, span};
+/// use iced::{color, column, never, Font};
+///
+/// #[derive(Debug, Clone)]
+/// enum Message {
+/// LinkClicked(&'static str),
+/// // ...
+/// }
+///
+/// fn view(state: &State) -> Element<'_, Message> {
+/// selectable(
+/// column![
+/// rich_text([
+/// span("I am red!").color(color!(0xff0000)),
+/// span(" "),
+/// span("And I am bold!").font(Font { weight: font::Weight::Bold, ..Font::default() }),
+/// ])
+/// .on_link_click(never)
+/// .size(20),
+/// text("Hello, this is iced!"),
+/// ]
+/// )
+/// .into()
+/// }
+/// ```
+pub fn selectable<'a, Message, Theme, Renderer>(
+ content: impl Into<Element<'a, Message, Theme, Renderer>>,
+) -> selectable::Selectable<'a, Message, Theme, Renderer>
+where
+ Theme: 'a,
+ Renderer: core::Renderer,
+{
+ selectable::Selectable::new(content)
+}