From 485933179c7d8b22a9443853ccc6447d87d755de Mon Sep 17 00:00:00 2001 From: Broderick Carlin Date: Sun, 29 Oct 2023 16:54:57 -0500 Subject: [PATCH] Switch From bounds to Default --- src/lib.rs | 4 ---- src/rendering/line.rs | 16 +++++++--------- src/rendering/line_iter.rs | 6 +++--- src/rendering/mod.rs | 3 +-- src/style/height_mode.rs | 3 +-- src/style/mod.rs | 8 +------- 6 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f0a4d5d1..9e7d1e84 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -121,7 +121,6 @@ use crate::{ }; use embedded_graphics::{ geometry::{Dimensions, Point}, - pixelcolor::Rgb888, primitives::Rectangle, text::{ renderer::{CharacterStyle, TextRenderer}, @@ -242,7 +241,6 @@ where impl<'a, S> TextBox<'a, S, NoPlugin<::Color>> where - ::Color: From, S: TextRenderer + CharacterStyle, { /// Creates a new `TextBox` instance with a given bounding `Rectangle`. @@ -409,7 +407,6 @@ where impl<'a, S, P> TextBox<'a, S, P> where - ::Color: From, S: TextRenderer + CharacterStyle, P: Plugin<'a, ::Color> + ChainElement, { @@ -476,7 +473,6 @@ impl<'a, S, M> TextBox<'a, S, M> where S: TextRenderer, M: Plugin<'a, S::Color>, - S::Color: From, { /// Sets the height of the [`TextBox`] to the height of the text. #[inline] diff --git a/src/rendering/line.rs b/src/rendering/line.rs index 7ad0daa2..b05a7f06 100644 --- a/src/rendering/line.rs +++ b/src/rendering/line.rs @@ -13,7 +13,6 @@ use crate::{ use embedded_graphics::{ draw_target::DrawTarget, geometry::Point, - pixelcolor::{BinaryColor, Rgb888}, prelude::{PixelColor, Size}, primitives::Rectangle, text::{ @@ -24,12 +23,12 @@ use embedded_graphics::{ impl ChangeTextStyle where - C: PixelColor + From, + C: PixelColor + Default, { pub(crate) fn apply>(self, text_renderer: &mut S) { match self { ChangeTextStyle::Reset => { - text_renderer.set_text_color(Some(Into::::into(BinaryColor::On).into())); + text_renderer.set_text_color(Some(C::default())); text_renderer.set_background_color(None); text_renderer.set_underline_color(DecorationColor::None); text_renderer.set_strikethrough_color(DecorationColor::None); @@ -79,7 +78,6 @@ where impl<'a, 'b, F, D, M> RenderElementHandler<'a, 'b, F, D, M> where F: CharacterStyle + TextRenderer, - ::Color: From, D: DrawTarget::Color>, M: Plugin<'a, ::Color>, { @@ -96,9 +94,9 @@ where impl<'a, 'c, F, D, M> ElementHandler for RenderElementHandler<'a, 'c, F, D, M> where F: CharacterStyle + TextRenderer, - ::Color: From, D: DrawTarget::Color>, M: Plugin<'a, ::Color>, + ::Color: Default, { type Error = D::Error; type Color = ::Color; @@ -144,8 +142,8 @@ where impl<'a, 'b, 'c, F, M> StyledLineRenderer<'a, 'b, 'c, F, M> where F: TextRenderer::Color> + CharacterStyle, - ::Color: From, M: Plugin<'a, ::Color> + Plugin<'a, ::Color>, + ::Color: Default, { #[inline] pub(crate) fn draw(mut self, display: &mut D) -> Result<(), D::Error> @@ -174,7 +172,7 @@ where let (left, space_config) = self.style.alignment.place_line(text_renderer, lm); - self.cursor.move_cursor(left as i32).ok(); + self.cursor.move_cursor(left).ok(); let mut render_element_handler = RenderElementHandler { text_renderer, @@ -219,7 +217,7 @@ mod test { geometry::Point, mock_display::MockDisplay, mono_font::{ascii::FONT_6X9, MonoTextStyleBuilder}, - pixelcolor::{BinaryColor, Rgb888}, + pixelcolor::BinaryColor, primitives::Rectangle, text::renderer::{CharacterStyle, TextRenderer}, }; @@ -232,7 +230,7 @@ mod test { pattern: &[&str], ) where S: TextRenderer::Color> + CharacterStyle, - ::Color: From + embedded_graphics::mock_display::ColorMapping, + ::Color: embedded_graphics::mock_display::ColorMapping + Default, { let parser = Parser::parse(text); let cursor = LineCursor::new( diff --git a/src/rendering/line_iter.rs b/src/rendering/line_iter.rs index 6846fd28..a13e1ce4 100644 --- a/src/rendering/line_iter.rs +++ b/src/rendering/line_iter.rs @@ -11,7 +11,7 @@ use crate::{ style::TextBoxStyle, }; use az::SaturatingAs; -use embedded_graphics::{pixelcolor::Rgb888, prelude::PixelColor}; +use embedded_graphics::prelude::PixelColor; /// Parser to break down a line into primitive elements used by measurement and rendering. #[derive(Debug)] @@ -72,7 +72,7 @@ pub trait ElementHandler { impl<'a, 'b, M, C> LineElementParser<'a, 'b, M, C> where - C: PixelColor + From, + C: PixelColor, M: Plugin<'a, C>, { /// Creates a new element parser. @@ -464,7 +464,7 @@ pub(crate) mod test { use embedded_graphics::{ geometry::{Point, Size}, mono_font::{ascii::FONT_6X9, MonoTextStyle}, - pixelcolor::BinaryColor, + pixelcolor::{BinaryColor, Rgb888}, primitives::Rectangle, text::{renderer::TextRenderer, LineHeight}, }; diff --git a/src/rendering/mod.rs b/src/rendering/mod.rs index eb0c8ce5..b59df776 100644 --- a/src/rendering/mod.rs +++ b/src/rendering/mod.rs @@ -18,7 +18,6 @@ use crate::{ use az::SaturatingAs; use embedded_graphics::{ draw_target::{DrawTarget, DrawTargetExt}, - pixelcolor::Rgb888, prelude::{Dimensions, Point, Size}, primitives::Rectangle, text::renderer::{CharacterStyle, TextRenderer}, @@ -47,8 +46,8 @@ pub struct TextBoxProperties<'a, S> { impl<'a, F, M> Drawable for TextBox<'a, F, M> where F: TextRenderer::Color> + CharacterStyle, - ::Color: From, M: Plugin<'a, ::Color> + Plugin<'a, ::Color>, + ::Color: Default, { type Color = ::Color; type Output = &'a str; diff --git a/src/style/height_mode.rs b/src/style/height_mode.rs index d3fce6c5..30a22094 100644 --- a/src/style/height_mode.rs +++ b/src/style/height_mode.rs @@ -7,7 +7,7 @@ use crate::{ plugin::PluginMarker as Plugin, rendering::cursor::Cursor, style::VerticalOverdraw, TextBox, }; use core::ops::Range; -use embedded_graphics::{geometry::Dimensions, pixelcolor::Rgb888, text::renderer::TextRenderer}; +use embedded_graphics::{geometry::Dimensions, text::renderer::TextRenderer}; /// Specifies how the [`TextBox`]'s height should be adjusted. #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] @@ -184,7 +184,6 @@ impl HeightMode { where F: TextRenderer, M: Plugin<'a, F::Color>, - F::Color: From, { match self { HeightMode::Exact(_) => {} diff --git a/src/style/mod.rs b/src/style/mod.rs index c2646917..1ff35b0f 100644 --- a/src/style/mod.rs +++ b/src/style/mod.rs @@ -194,10 +194,7 @@ use crate::{ }, utils::str_width, }; -use embedded_graphics::{ - pixelcolor::Rgb888, - text::{renderer::TextRenderer, LineHeight}, -}; +use embedded_graphics::text::{renderer::TextRenderer, LineHeight}; pub use self::{ builder::TextBoxStyleBuilder, height_mode::HeightMode, vertical_overdraw::VerticalOverdraw, @@ -431,7 +428,6 @@ impl TextBoxStyle { where S: TextRenderer, M: Plugin<'a, S::Color>, - S::Color: From, { let cursor = LineCursor::new(max_line_width, self.tab_size.into_pixels(character_style)); @@ -503,7 +499,6 @@ impl TextBoxStyle { pub fn measure_text_height(&self, character_style: &S, text: &str, max_width: u32) -> u32 where S: TextRenderer, - S::Color: From, { let plugin = PluginWrapper::new(NoPlugin::new()); self.measure_text_height_impl(plugin, character_style, text, max_width) @@ -519,7 +514,6 @@ impl TextBoxStyle { where S: TextRenderer, M: Plugin<'a, S::Color>, - S::Color: From, { let mut parser = Parser::parse(text); let base_line_height = character_style.line_height();