diff --git a/src/alignment/mod.rs b/src/alignment/mod.rs index db2642f4..5f1441fc 100644 --- a/src/alignment/mod.rs +++ b/src/alignment/mod.rs @@ -31,14 +31,14 @@ impl HorizontalAlignment { self, renderer: &impl TextRenderer, measurement: LineMeasurement, - ) -> (u32, SpaceConfig) { + ) -> (i32, SpaceConfig) { let space_width = str_width(renderer, " "); let space_config = SpaceConfig::new(space_width, None); let remaining_space = measurement.max_line_width - measurement.width; match self { HorizontalAlignment::Left => (0, space_config), - HorizontalAlignment::Center => ((remaining_space + 1) / 2, space_config), - HorizontalAlignment::Right => (remaining_space, space_config), + HorizontalAlignment::Center => ((remaining_space as i32 + 1) / 2, space_config), + HorizontalAlignment::Right => (remaining_space as i32, space_config), HorizontalAlignment::Justified => { let space_count = measurement.space_count; let space_info = if !measurement.last_line() && space_count != 0 { diff --git a/src/rendering/cursor.rs b/src/rendering/cursor.rs index beff8b26..a332c820 100644 --- a/src/rendering/cursor.rs +++ b/src/rendering/cursor.rs @@ -60,10 +60,10 @@ impl LineCursor { self.position -= abs; Ok(by) } else { - Err(-self.position.saturating_as::()) + Err(-(self.position as i32)) } } else { - let space = self.space().saturating_as(); + let space = self.space() as i32; if by <= space { // Here we know by > 0, cast is safe self.position += by as u32; diff --git a/src/rendering/line.rs b/src/rendering/line.rs index 328384c4..7ad0daa2 100644 --- a/src/rendering/line.rs +++ b/src/rendering/line.rs @@ -10,7 +10,6 @@ use crate::{ style::TextBoxStyle, utils::str_width, }; -use az::SaturatingAs; use embedded_graphics::{ draw_target::DrawTarget, geometry::Point, @@ -175,7 +174,7 @@ where let (left, space_config) = self.style.alignment.place_line(text_renderer, lm); - self.cursor.move_cursor(left.saturating_as()).ok(); + self.cursor.move_cursor(left as i32).ok(); let mut render_element_handler = RenderElementHandler { text_renderer, diff --git a/src/rendering/line_iter.rs b/src/rendering/line_iter.rs index 008b60c3..6846fd28 100644 --- a/src/rendering/line_iter.rs +++ b/src/rendering/line_iter.rs @@ -266,7 +266,7 @@ where handler.whitespace("\t", 0, moved)? } - Ok(moved) | Err(moved) => handler.move_cursor(moved.saturating_as())?, + Ok(moved) | Err(moved) => handler.move_cursor(moved as i32)?, } Ok(()) } diff --git a/src/style/mod.rs b/src/style/mod.rs index 918c1346..c2646917 100644 --- a/src/style/mod.rs +++ b/src/style/mod.rs @@ -194,7 +194,6 @@ use crate::{ }, utils::str_width, }; -use az::SaturatingAs; use embedded_graphics::{ pixelcolor::Rgb888, text::{renderer::TextRenderer, LineHeight}, @@ -407,7 +406,7 @@ impl<'a, S: TextRenderer> ElementHandler for MeasureLineElementHandler<'a, S> { } fn move_cursor(&mut self, by: i32) -> Result<(), Self::Error> { - self.cursor = (self.cursor.saturating_as::() + by) as u32; + self.cursor = (self.cursor as i32 + by) as u32; Ok(()) } diff --git a/src/utils.rs b/src/utils.rs index f25c92ff..16ca47f2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,5 @@ //! Misc utilities -use az::SaturatingAs; use embedded_graphics::{ prelude::Point, text::{renderer::TextRenderer, Baseline}, @@ -11,8 +10,7 @@ pub fn str_width(renderer: &impl TextRenderer, s: &str) -> u32 { renderer .measure_string(s, Point::zero(), Baseline::Top) .next_position - .x - .saturating_as() + .x as u32 } #[cfg(test)]