diff options
| author | Polesznyák Márk <contact@pml68.dev> | 2025-10-19 12:17:01 +0200 |
|---|---|---|
| committer | Polesznyák Márk <contact@pml68.dev> | 2025-10-19 12:17:01 +0200 |
| commit | 7d3bacc69df0ba1151836c8da40bace5dfc5f037 (patch) | |
| tree | 1f0d531f3810b32a8b5ab6e6d63f856b98c51931 /src/lib.rs | |
| parent | feat: initial commit (diff) | |
| download | iced_selection-7d3bacc69df0ba1151836c8da40bace5dfc5f037.tar.gz | |
feat: add selectable `Rich` widget with an example
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 44 |
1 files changed, 42 insertions, 2 deletions
@@ -3,10 +3,11 @@ //! [`Paragraph`]: https://docs.iced.rs/iced_graphics/text/paragraph/struct.Paragraph.html pub mod selection; - pub mod text; use iced_widget::core; +use iced_widget::graphics::text::Paragraph; +#[doc(no_inline)] pub use text::Text; /// Creates a new [`Text`] widget with the provided content. @@ -17,9 +18,22 @@ macro_rules! text { }; } +/// Creates some [`Rich`] text with the given spans. +/// +/// [`Rich`]: crate::text::Rich +#[macro_export] +macro_rules! rich_text { + () => ( + $crate::text::Rich::new() + ); + ($($x:expr),+ $(,)?) => ( + $crate::text::Rich::from_iter([$($crate::text::Span::from($x)),+]) + ); +} + /// Creates a new [`Text`] widget with the provided content. pub fn text<'a, Theme, Renderer>( - text: impl core::text::IntoFragment<'a>, + text: impl text::IntoFragment<'a>, ) -> Text<'a, Theme, Renderer> where Theme: text::Catalog + 'a, @@ -27,3 +41,29 @@ where { Text::new(text) } + +/// Creates some [`Rich`] text with the given spans. +/// +/// [`Rich`]: crate::text::Rich +pub fn rich_text<'a, Link, Message, Theme, Renderer>( + spans: impl AsRef<[text::Span<'a, Link, core::Font>]> + 'a, +) -> text::Rich<'a, Link, Message, Theme, Renderer> +where + Link: Clone + 'static, + Theme: text::Catalog + 'a, + Renderer: core::text::Renderer<Paragraph = Paragraph, Font = core::Font>, +{ + text::Rich::with_spans(spans) +} + +/// Creates a new [`Span`] of text with the provided content. +/// +/// A [`Span`] is a fragment of some [`Rich`] text. +/// +/// [`Rich`]: crate::text::Rich +/// [`Span`]: crate::text::Span +pub fn span<'a, Link>( + text: impl text::IntoFragment<'a>, +) -> text::Span<'a, Link, core::Font> { + text::Span::new(text) +} |
