From ddcf02f9d0377afe6a35dbbb09a29b4bd52efe2e Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Tue, 23 Jul 2024 13:36:40 -0700 Subject: Add background styling to span / rich text --- widget/src/markdown.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'widget/src/markdown.rs') diff --git a/widget/src/markdown.rs b/widget/src/markdown.rs index 9cfd3c33..6cd8535e 100644 --- a/widget/src/markdown.rs +++ b/widget/src/markdown.rs @@ -4,9 +4,12 @@ //! in code blocks. //! //! Only the variants of [`Item`] are currently supported. +use crate::core::border; use crate::core::font::{self, Font}; use crate::core::padding; -use crate::core::theme::{self, Theme}; +use crate::core::text::Background; +use crate::core::theme::palette; +use crate::core::theme::Theme; use crate::core::{self, Element, Length, Pixels}; use crate::{column, container, rich_text, row, scrollable, span, text}; @@ -34,10 +37,10 @@ pub enum Item { } /// Parse the given Markdown content. -pub fn parse( - markdown: &str, - palette: theme::Palette, -) -> impl Iterator + '_ { +pub fn parse<'a>( + markdown: &'a str, + palette: &'a palette::Extended, +) -> impl Iterator + 'a { struct List { start: Option, items: Vec>, @@ -247,7 +250,7 @@ pub fn parse( }; let span = if let Some(link) = link.as_ref() { - span.color(palette.primary).link(link.clone()) + span.color(palette.primary.base.color).link(link.clone()) } else { span }; @@ -257,10 +260,15 @@ pub fn parse( None } pulldown_cmark::Event::Code(code) if !metadata && !table => { - let span = span(code.into_string()).font(Font::MONOSPACE); + let span = span(code.into_string()) + .font(Font::MONOSPACE) + .background(Background { + color: palette.background.weak.color, + border: border::rounded(2), + }); let span = if let Some(link) = link.as_ref() { - span.color(palette.primary).link(link.clone()) + span.color(palette.primary.base.color).link(link.clone()) } else { span }; -- cgit From 4dc7b9b9619010b50ec6df837bd945ff0f675781 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 28 Jul 2024 13:15:04 +0200 Subject: Use dark background for inline code in `markdown` widget --- widget/src/markdown.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'widget/src/markdown.rs') diff --git a/widget/src/markdown.rs b/widget/src/markdown.rs index 6cd8535e..362aba67 100644 --- a/widget/src/markdown.rs +++ b/widget/src/markdown.rs @@ -8,9 +8,8 @@ use crate::core::border; use crate::core::font::{self, Font}; use crate::core::padding; use crate::core::text::Background; -use crate::core::theme::palette; -use crate::core::theme::Theme; -use crate::core::{self, Element, Length, Pixels}; +use crate::core::theme::{self, Theme}; +use crate::core::{self, color, Color, Element, Length, Pixels}; use crate::{column, container, rich_text, row, scrollable, span, text}; pub use pulldown_cmark::HeadingLevel; @@ -39,7 +38,7 @@ pub enum Item { /// Parse the given Markdown content. pub fn parse<'a>( markdown: &'a str, - palette: &'a palette::Extended, + palette: &'a theme::Palette, ) -> impl Iterator + 'a { struct List { start: Option, @@ -250,7 +249,7 @@ pub fn parse<'a>( }; let span = if let Some(link) = link.as_ref() { - span.color(palette.primary.base.color).link(link.clone()) + span.color(palette.primary).link(link.clone()) } else { span }; @@ -262,13 +261,14 @@ pub fn parse<'a>( pulldown_cmark::Event::Code(code) if !metadata && !table => { let span = span(code.into_string()) .font(Font::MONOSPACE) + .color(Color::WHITE) .background(Background { - color: palette.background.weak.color, + color: color!(0x111111), border: border::rounded(2), }); let span = if let Some(link) = link.as_ref() { - span.color(palette.primary.base.color).link(link.clone()) + span.color(palette.primary).link(link.clone()) } else { span }; -- cgit From f7fe1edcbbfde71d801379805b4605ff36075b11 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 28 Jul 2024 13:44:08 +0200 Subject: Improve ergonomics of `span` background highlighting --- widget/src/markdown.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'widget/src/markdown.rs') diff --git a/widget/src/markdown.rs b/widget/src/markdown.rs index 362aba67..cb3e9cfc 100644 --- a/widget/src/markdown.rs +++ b/widget/src/markdown.rs @@ -7,7 +7,6 @@ use crate::core::border; use crate::core::font::{self, Font}; use crate::core::padding; -use crate::core::text::Background; use crate::core::theme::{self, Theme}; use crate::core::{self, color, Color, Element, Length, Pixels}; use crate::{column, container, rich_text, row, scrollable, span, text}; @@ -262,10 +261,8 @@ pub fn parse<'a>( let span = span(code.into_string()) .font(Font::MONOSPACE) .color(Color::WHITE) - .background(Background { - color: color!(0x111111), - border: border::rounded(2), - }); + .background(color!(0x111111)) + .border(border::rounded(2)); let span = if let Some(link) = link.as_ref() { span.color(palette.primary).link(link.clone()) -- cgit From 2796a6bc974d847580ab23c6a5f58db994883ec5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 28 Jul 2024 13:56:39 +0200 Subject: Add `padding` to `text::Span` --- widget/src/markdown.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'widget/src/markdown.rs') diff --git a/widget/src/markdown.rs b/widget/src/markdown.rs index cb3e9cfc..c5eeaea9 100644 --- a/widget/src/markdown.rs +++ b/widget/src/markdown.rs @@ -262,7 +262,8 @@ pub fn parse<'a>( .font(Font::MONOSPACE) .color(Color::WHITE) .background(color!(0x111111)) - .border(border::rounded(2)); + .border(border::rounded(2)) + .padding(padding::left(2).right(2)); let span = if let Some(link) = link.as_ref() { span.color(palette.primary).link(link.clone()) -- cgit From 2d69464846e6e1a7c59f78d894d8801ff82c5929 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 28 Jul 2024 13:59:11 +0200 Subject: Make `markdown::parse` take a `Palette` value --- widget/src/markdown.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'widget/src/markdown.rs') diff --git a/widget/src/markdown.rs b/widget/src/markdown.rs index c5eeaea9..9cd4a62f 100644 --- a/widget/src/markdown.rs +++ b/widget/src/markdown.rs @@ -35,10 +35,10 @@ pub enum Item { } /// Parse the given Markdown content. -pub fn parse<'a>( - markdown: &'a str, - palette: &'a theme::Palette, -) -> impl Iterator + 'a { +pub fn parse( + markdown: &str, + palette: theme::Palette, +) -> impl Iterator + '_ { struct List { start: Option, items: Vec>, -- cgit