summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-19 06:38:48 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-19 06:38:48 +0200
commitcda1369c790cac27dce90abaead2bca940047ed0 (patch)
tree7edb07a629d7f1a8853043fa7bbd96f2bbf2f7e5
parent4e38992636dded5868e74e5630a5da72bb4e5f93 (diff)
downloadiced-cda1369c790cac27dce90abaead2bca940047ed0.tar.gz
iced-cda1369c790cac27dce90abaead2bca940047ed0.tar.bz2
iced-cda1369c790cac27dce90abaead2bca940047ed0.zip
Write doc examples for `rich_text` widget
-rw-r--r--widget/src/helpers.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs
index 817d437c..e17ef424 100644
--- a/widget/src/helpers.rs
+++ b/widget/src/helpers.rs
@@ -117,6 +117,31 @@ macro_rules! text {
/// Creates some [`Rich`] text with the given spans.
///
/// [`Rich`]: text::Rich
+///
+/// # Example
+/// ```no_run
+/// # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::core::*; }
+/// # pub type State = ();
+/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
+/// use iced::font;
+/// use iced::widget::{rich_text, span};
+/// use iced::{color, 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() }),
+/// ]
+/// .size(20)
+/// .into()
+/// }
+/// ```
#[macro_export]
macro_rules! rich_text {
() => (
@@ -823,6 +848,31 @@ where
/// Creates a new [`Rich`] text widget with the provided spans.
///
/// [`Rich`]: text::Rich
+///
+/// # Example
+/// ```no_run
+/// # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::core::*; }
+/// # pub type State = ();
+/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
+/// use iced::font;
+/// use iced::widget::{rich_text, span};
+/// use iced::{color, Font};
+///
+/// #[derive(Debug, Clone)]
+/// enum Message {
+/// // ...
+/// }
+///
+/// fn view(state: &State) -> Element<'_, Message> {
+/// rich_text([
+/// span("I am red!").color(color!(0xff0000)),
+/// span(" "),
+/// span("And I am bold!").font(Font { weight: font::Weight::Bold, ..Font::default() }),
+/// ])
+/// .size(20)
+/// .into()
+/// }
+/// ```
pub fn rich_text<'a, Link, Theme, Renderer>(
spans: impl AsRef<[text::Span<'a, Link, Renderer::Font>]> + 'a,
) -> text::Rich<'a, Link, Theme, Renderer>
@@ -837,7 +887,35 @@ where
/// Creates a new [`Span`] of text with the provided content.
///
+/// A [`Span`] is a fragment of some [`Rich`] text.
+///
/// [`Span`]: text::Span
+/// [`Rich`]: text::Rich
+///
+/// # Example
+/// ```no_run
+/// # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::core::*; }
+/// # pub type State = ();
+/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
+/// use iced::font;
+/// use iced::widget::{rich_text, span};
+/// use iced::{color, 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() }),
+/// ]
+/// .size(20)
+/// .into()
+/// }
+/// ```
pub fn span<'a, Link, Font>(
text: impl text::IntoFragment<'a>,
) -> text::Span<'a, Link, Font> {