diff options
| author | Polesznyák Márk <contact@pml68.dev> | 2025-11-03 17:35:06 +0100 |
|---|---|---|
| committer | Polesznyák Márk <contact@pml68.dev> | 2025-11-03 17:35:06 +0100 |
| commit | 0193d984c61dae797366e3438597caf0513e1a65 (patch) | |
| tree | 6fd102f4ec6625a179a88f55e1a5c06250e704a5 | |
| parent | fix: `Selection::text` not counting from `start.line` (diff) | |
| download | iced_selection-0193d984c61dae797366e3438597caf0513e1a65.tar.gz | |
feat: add `span!` macro (same as `text!`)
| -rw-r--r-- | src/lib.rs | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -86,6 +86,47 @@ macro_rules! rich_text { ); } +/// Creates a new [`Span`] of text with the provided content. +/// +/// A [`Span`] is a fragment of some [`Rich`] text. +/// +/// This macro uses the same syntax as [`format!`], but creates a new [`Span`] widget instead. +/// +/// See [the formatting documentation in `std::fmt`](std::fmt) +/// for details of the macro argument syntax. +/// +/// # Example +/// ```no_run,ignore +/// use iced::font; +/// use iced_selection::{rich_text, span}; +/// use iced::{color, never, Font}; +/// +/// #[derive(Debug, Clone)] +/// enum Message { +/// // ... +/// } +/// +/// fn view(state: &State) -> Element<'_, Message> { +/// rich_text![ +/// span!("I am {}!", red).color(color!(0xff0000)), +/// " ", +/// span!("And I am bold!").font(Font { weight: font::Weight::Bold, ..Font::default() }), +/// ] +/// .on_link_click(never) +/// .size(20) +/// .into() +/// } +/// ``` +/// +/// [`Rich`]: crate::text::Rich +/// [`Span`]: crate::text::Span +#[macro_export] +macro_rules! span { + ($($arg:tt)*) => { + $crate::text::Span::new(format!($($arg)*)) + }; +} + /// Creates a new [`Text`] widget with the provided content. /// /// # Example |
