diff options
author | 2024-08-21 02:34:03 +0200 | |
---|---|---|
committer | 2024-08-21 02:34:03 +0200 | |
commit | 55764b923e69afa8a92b4a6cbd34ee9ddbf8a03d (patch) | |
tree | c3826e820fad9f3ddeff947d79e7e403c3f7d2e1 /widget/src/markdown.rs | |
parent | 9b99b932bced46047ec2e18c2b6ec5a6c5b3636f (diff) | |
download | iced-55764b923e69afa8a92b4a6cbd34ee9ddbf8a03d.tar.gz iced-55764b923e69afa8a92b4a6cbd34ee9ddbf8a03d.tar.bz2 iced-55764b923e69afa8a92b4a6cbd34ee9ddbf8a03d.zip |
Decouple `markdown` widget from built-in `Theme`
Diffstat (limited to 'widget/src/markdown.rs')
-rw-r--r-- | widget/src/markdown.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/widget/src/markdown.rs b/widget/src/markdown.rs index 23e36435..2bcbde5c 100644 --- a/widget/src/markdown.rs +++ b/widget/src/markdown.rs @@ -7,8 +7,8 @@ use crate::core::border; use crate::core::font::{self, Font}; use crate::core::padding; -use crate::core::theme::{self, Theme}; -use crate::core::{self, color, Color, Element, Length, Pixels}; +use crate::core::theme; +use crate::core::{self, color, Color, Element, Length, Pixels, Theme}; use crate::{column, container, rich_text, row, scrollable, span, text}; pub use pulldown_cmark::HeadingLevel; @@ -349,11 +349,12 @@ impl Default for Settings { /// Display a bunch of Markdown items. /// /// You can obtain the items with [`parse`]. -pub fn view<'a, Renderer>( +pub fn view<'a, Theme, Renderer>( items: impl IntoIterator<Item = &'a Item>, settings: Settings, ) -> Element<'a, Url, Theme, Renderer> where + Theme: Catalog + 'a, Renderer: core::text::Renderer<Font = Font> + 'a, { let Settings { @@ -426,9 +427,23 @@ where ) .width(Length::Fill) .padding(spacing.0 / 2.0) - .style(container::dark) + .class(Theme::code_block()) .into(), }); Element::new(column(blocks).width(Length::Fill).spacing(text_size)) } + +/// The theme catalog of Markdown items. +pub trait Catalog: + container::Catalog + scrollable::Catalog + text::Catalog +{ + /// The styling class of a Markdown code block. + fn code_block<'a>() -> <Self as container::Catalog>::Class<'a>; +} + +impl Catalog for Theme { + fn code_block<'a>() -> <Self as container::Catalog>::Class<'a> { + Box::new(container::dark) + } +} |