Implement rich_text widget and markdown example

This commit is contained in:
Héctor Ramón Jiménez 2024-07-17 22:04:11 +02:00
parent ffb520fb37
commit 910eb72a06
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
11 changed files with 787 additions and 99 deletions

View file

@ -112,6 +112,19 @@ macro_rules! text {
};
}
/// Creates some [`Rich`] text with the given spans.
///
/// [`Rich`]: text::Rich
#[macro_export]
macro_rules! rich_text {
() => (
$crate::Column::new()
);
($($x:expr),+ $(,)?) => (
$crate::text::Rich::with_spans([$($crate::text::Span::from($x)),+])
);
}
/// Creates a new [`Container`] with the provided content.
///
/// [`Container`]: crate::Container
@ -646,8 +659,6 @@ where
}
/// Creates a new [`Text`] widget with the provided content.
///
/// [`Text`]: core::widget::Text
pub fn text<'a, Theme, Renderer>(
text: impl text::IntoFragment<'a>,
) -> Text<'a, Theme, Renderer>
@ -659,8 +670,6 @@ where
}
/// Creates a new [`Text`] widget that displays the provided value.
///
/// [`Text`]: core::widget::Text
pub fn value<'a, Theme, Renderer>(
value: impl ToString,
) -> Text<'a, Theme, Renderer>
@ -671,6 +680,28 @@ where
Text::new(value.to_string())
}
/// Creates a new [`Rich`] text widget with the provided spans.
///
/// [`Rich`]: text::Rich
pub fn rich_text<'a, Theme, Renderer>(
spans: impl IntoIterator<Item = text::Span<'a, Renderer::Font>>,
) -> text::Rich<'a, Theme, Renderer>
where
Theme: text::Catalog + 'a,
Renderer: core::text::Renderer,
{
text::Rich::with_spans(spans)
}
/// Creates a new [`Span`] of text with the provided content.
///
/// [`Span`]: text::Span
pub fn span<'a, Font>(
text: impl text::IntoFragment<'a>,
) -> text::Span<'a, Font> {
text::Span::new(text)
}
/// Creates a new [`Checkbox`].
///
/// [`Checkbox`]: crate::Checkbox