Skip to content

Commit

Permalink
Merge pull request #165 from BroderickCarlin/remove-rgb888-bounds
Browse files Browse the repository at this point in the history
Remove `From<Rgb888>` bounds in favor of `Default`
  • Loading branch information
bugadani authored Oct 29, 2023
2 parents feb9a35 + 4859331 commit 042b128
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ use crate::{
};
use embedded_graphics::{
geometry::{Dimensions, Point},
pixelcolor::Rgb888,
primitives::Rectangle,
text::{
renderer::{CharacterStyle, TextRenderer},
Expand Down Expand Up @@ -242,7 +241,6 @@ where

impl<'a, S> TextBox<'a, S, NoPlugin<<S as TextRenderer>::Color>>
where
<S as TextRenderer>::Color: From<Rgb888>,
S: TextRenderer + CharacterStyle,
{
/// Creates a new `TextBox` instance with a given bounding `Rectangle`.
Expand Down Expand Up @@ -409,7 +407,6 @@ where

impl<'a, S, P> TextBox<'a, S, P>
where
<S as TextRenderer>::Color: From<Rgb888>,
S: TextRenderer + CharacterStyle,
P: Plugin<'a, <S as TextRenderer>::Color> + ChainElement,
{
Expand Down Expand Up @@ -476,7 +473,6 @@ impl<'a, S, M> TextBox<'a, S, M>
where
S: TextRenderer,
M: Plugin<'a, S::Color>,
S::Color: From<Rgb888>,
{
/// Sets the height of the [`TextBox`] to the height of the text.
#[inline]
Expand Down
16 changes: 7 additions & 9 deletions src/rendering/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
use embedded_graphics::{
draw_target::DrawTarget,
geometry::Point,
pixelcolor::{BinaryColor, Rgb888},
prelude::{PixelColor, Size},
primitives::Rectangle,
text::{
Expand All @@ -24,12 +23,12 @@ use embedded_graphics::{

impl<C> ChangeTextStyle<C>
where
C: PixelColor + From<Rgb888>,
C: PixelColor + Default,
{
pub(crate) fn apply<S: CharacterStyle<Color = C>>(self, text_renderer: &mut S) {
match self {
ChangeTextStyle::Reset => {
text_renderer.set_text_color(Some(Into::<Rgb888>::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);
Expand Down Expand Up @@ -79,7 +78,6 @@ where
impl<'a, 'b, F, D, M> RenderElementHandler<'a, 'b, F, D, M>
where
F: CharacterStyle + TextRenderer,
<F as CharacterStyle>::Color: From<Rgb888>,
D: DrawTarget<Color = <F as TextRenderer>::Color>,
M: Plugin<'a, <F as TextRenderer>::Color>,
{
Expand All @@ -96,9 +94,9 @@ where
impl<'a, 'c, F, D, M> ElementHandler for RenderElementHandler<'a, 'c, F, D, M>
where
F: CharacterStyle + TextRenderer,
<F as CharacterStyle>::Color: From<Rgb888>,
D: DrawTarget<Color = <F as TextRenderer>::Color>,
M: Plugin<'a, <F as TextRenderer>::Color>,
<F as CharacterStyle>::Color: Default,
{
type Error = D::Error;
type Color = <F as CharacterStyle>::Color;
Expand Down Expand Up @@ -144,8 +142,8 @@ where
impl<'a, 'b, 'c, F, M> StyledLineRenderer<'a, 'b, 'c, F, M>
where
F: TextRenderer<Color = <F as CharacterStyle>::Color> + CharacterStyle,
<F as CharacterStyle>::Color: From<Rgb888>,
M: Plugin<'a, <F as TextRenderer>::Color> + Plugin<'a, <F as CharacterStyle>::Color>,
<F as CharacterStyle>::Color: Default,
{
#[inline]
pub(crate) fn draw<D>(mut self, display: &mut D) -> Result<(), D::Error>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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},
};
Expand All @@ -232,7 +230,7 @@ mod test {
pattern: &[&str],
) where
S: TextRenderer<Color = <S as CharacterStyle>::Color> + CharacterStyle,
<S as CharacterStyle>::Color: From<Rgb888> + embedded_graphics::mock_display::ColorMapping,
<S as CharacterStyle>::Color: embedded_graphics::mock_display::ColorMapping + Default,
{
let parser = Parser::parse(text);
let cursor = LineCursor::new(
Expand Down
6 changes: 3 additions & 3 deletions src/rendering/line_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -72,7 +72,7 @@ pub trait ElementHandler {

impl<'a, 'b, M, C> LineElementParser<'a, 'b, M, C>
where
C: PixelColor + From<Rgb888>,
C: PixelColor,
M: Plugin<'a, C>,
{
/// Creates a new element parser.
Expand Down Expand Up @@ -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},
};
Expand Down
3 changes: 1 addition & 2 deletions src/rendering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -47,8 +46,8 @@ pub struct TextBoxProperties<'a, S> {
impl<'a, F, M> Drawable for TextBox<'a, F, M>
where
F: TextRenderer<Color = <F as CharacterStyle>::Color> + CharacterStyle,
<F as CharacterStyle>::Color: From<Rgb888>,
M: Plugin<'a, <F as TextRenderer>::Color> + Plugin<'a, <F as CharacterStyle>::Color>,
<F as CharacterStyle>::Color: Default,
{
type Color = <F as CharacterStyle>::Color;
type Output = &'a str;
Expand Down
3 changes: 1 addition & 2 deletions src/style/height_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -184,7 +184,6 @@ impl HeightMode {
where
F: TextRenderer,
M: Plugin<'a, F::Color>,
F::Color: From<Rgb888>,
{
match self {
HeightMode::Exact(_) => {}
Expand Down
8 changes: 1 addition & 7 deletions src/style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -431,7 +428,6 @@ impl TextBoxStyle {
where
S: TextRenderer,
M: Plugin<'a, S::Color>,
S::Color: From<Rgb888>,
{
let cursor = LineCursor::new(max_line_width, self.tab_size.into_pixels(character_style));

Expand Down Expand Up @@ -503,7 +499,6 @@ impl TextBoxStyle {
pub fn measure_text_height<S>(&self, character_style: &S, text: &str, max_width: u32) -> u32
where
S: TextRenderer,
S::Color: From<Rgb888>,
{
let plugin = PluginWrapper::new(NoPlugin::new());
self.measure_text_height_impl(plugin, character_style, text, max_width)
Expand All @@ -519,7 +514,6 @@ impl TextBoxStyle {
where
S: TextRenderer,
M: Plugin<'a, S::Color>,
S::Color: From<Rgb888>,
{
let mut parser = Parser::parse(text);
let base_line_height = character_style.line_height();
Expand Down

0 comments on commit 042b128

Please sign in to comment.