Skip to content

Commit

Permalink
Merge pull request #123 from embedded-graphics/clippy
Browse files Browse the repository at this point in the history
Clean up
  • Loading branch information
bugadani authored Jun 3, 2021
2 parents da8394b + ac6a4ee commit 154f2bb
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 40 deletions.
6 changes: 3 additions & 3 deletions src/alignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl HorizontalAlignment {
}

/// Calculate offset from the left side and whitespace information.
pub fn place_line(
pub(crate) fn place_line(
self,
line: &str,
renderer: &impl TextRenderer,
Expand Down Expand Up @@ -113,10 +113,10 @@ pub enum VerticalAlignment {

impl VerticalAlignment {
/// Set the cursor's initial vertical position
pub fn apply_vertical_alignment<'a, 'b, S>(
pub(crate) fn apply_vertical_alignment<'a, S>(
self,
cursor: &mut Cursor,
styled_text_box: &'b TextBox<'a, S>,
styled_text_box: &TextBox<'a, S>,
) where
S: TextRenderer,
{
Expand Down
7 changes: 1 addition & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ use embedded_graphics::{
/// [module-level documentation]: index.html
/// [`draw`]: #method.draw
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[must_use]
pub struct TextBox<'a, S> {
/// The text to be displayed in this `TextBox`
pub text: &'a str,
Expand All @@ -163,7 +164,6 @@ where
{
/// Creates a new `TextBox` instance with a given bounding `Rectangle`.
#[inline]
#[must_use]
pub fn new(text: &'a str, bounds: Rectangle, character_style: S) -> Self {
TextBox::with_textbox_style(text, bounds, character_style, TextBoxStyle::default())
}
Expand All @@ -175,7 +175,6 @@ where
{
/// Creates a new `TextBox` instance with a given bounding `Rectangle` and a given `TextBoxStyle`.
#[inline]
#[must_use]
pub fn with_textbox_style(
text: &'a str,
bounds: Rectangle,
Expand All @@ -197,7 +196,6 @@ where

/// Creates a new `TextBox` instance with a given bounding `Rectangle` and a given `TextBoxStyle`.
#[inline]
#[must_use]
pub fn with_alignment(
text: &'a str,
bounds: Rectangle,
Expand All @@ -214,7 +212,6 @@ where

/// Creates a new `TextBox` instance with a given bounding `Rectangle` and a given `TextBoxStyle`.
#[inline]
#[must_use]
pub fn with_vertical_alignment(
text: &'a str,
bounds: Rectangle,
Expand Down Expand Up @@ -242,7 +239,6 @@ where
Self: Clone,
{
#[inline]
#[must_use]
fn translate(&self, by: Point) -> Self {
Self {
bounds: self.bounds.translate(by),
Expand All @@ -260,7 +256,6 @@ where

impl<S> Dimensions for TextBox<'_, S> {
#[inline]
#[must_use]
fn bounding_box(&self) -> Rectangle {
self.bounds
}
Expand Down
1 change: 1 addition & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl<'a> Parser<'a> {
/// Create a new parser object to process the given piece of text.
#[inline]
#[must_use]

pub fn parse(text: &'a str) -> Self {
Self {
inner: text.chars(),
Expand Down
19 changes: 2 additions & 17 deletions src/rendering/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,27 @@ impl LineCursor {
}

/// Returns the distance to the next tab position.
#[inline]
pub fn next_tab_width(&self) -> u32 {
let next_tab_pos = (self.position / self.tab_width + 1) * self.tab_width;
next_tab_pos - self.position
}

/// Returns the width of the textbox
#[inline]
#[must_use]
/// Returns the width of the text box.
pub fn line_width(&self) -> u32 {
self.width
}

/// Moves the cursor back to the start of the line.
#[inline]
pub fn carriage_return(&mut self) {
self.position = 0;
}

/// Returns whether the current line has enough space to also include an object of given width.
#[inline]
#[must_use]
pub fn fits_in_line(&self, width: u32) -> bool {
width <= self.space()
}

/// Returns the amount of empty space in the line.
#[inline]
#[must_use]
pub fn space(&self) -> u32 {
self.width - self.position
}

/// Moves the cursor by a given amount.
#[inline]
pub fn move_cursor(&mut self, by: i32) -> Result<i32, i32> {
if by < 0 {
let abs = by.abs() as u32;
Expand Down Expand Up @@ -120,6 +106,7 @@ impl Cursor {
}
}

#[must_use]
pub fn line(&self) -> LineCursor {
LineCursor {
start: Point::new(self.bounds.top_left.x, self.y),
Expand All @@ -143,14 +130,12 @@ impl Cursor {

/// Returns the width of the text box.
#[inline]
#[must_use]
pub fn line_width(&self) -> u32 {
self.bounds.size.width
}

/// Returns the height of a line.
#[inline]
#[must_use]
pub fn line_height(&self) -> i32 {
self.line_height
}
Expand Down
1 change: 0 additions & 1 deletion src/rendering/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ where
<F as CharacterStyle>::Color: From<Rgb888>,
{
/// Creates a new line renderer.
#[inline]
pub fn new(cursor: LineCursor, state: LineRenderState<'a, F>) -> Self {
Self { cursor, state }
}
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/line_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use as_slice::AsSlice;

/// Parser to break down a line into primitive elements used by measurement and rendering.
#[derive(Debug)]
#[must_use]
pub struct LineElementParser<'a, 'b> {
/// Position information.
cursor: LineCursor,
Expand Down Expand Up @@ -63,7 +64,6 @@ pub trait ElementHandler {
impl<'a, 'b> LineElementParser<'a, 'b> {
/// Creates a new element parser.
#[inline]
#[must_use]
pub fn new(
parser: &'b mut Parser<'a>,
cursor: LineCursor,
Expand Down
9 changes: 1 addition & 8 deletions src/style/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
///
/// [`TextBoxStyle`]: struct.TextBoxStyle.html
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[must_use]
pub struct TextBoxStyleBuilder {
style: TextBoxStyle,
}
Expand All @@ -24,7 +25,6 @@ impl Default for TextBoxStyleBuilder {
impl TextBoxStyleBuilder {
/// Creates a new text box style builder object.
#[inline]
#[must_use]
pub const fn new() -> Self {
Self {
style: TextBoxStyle {
Expand Down Expand Up @@ -54,7 +54,6 @@ impl TextBoxStyleBuilder {
/// .build();
/// ```
#[inline]
#[must_use]
pub const fn line_height(mut self, line_height: LineHeight) -> Self {
self.style.line_height = line_height;

Expand All @@ -74,7 +73,6 @@ impl TextBoxStyleBuilder {
/// .build();
/// ```
#[inline]
#[must_use]
pub const fn paragraph_spacing(mut self, paragraph_spacing: u32) -> Self {
self.style.paragraph_spacing = paragraph_spacing;

Expand All @@ -83,7 +81,6 @@ impl TextBoxStyleBuilder {

/// Sets the horizontal text alignment.
#[inline]
#[must_use]
pub const fn alignment(mut self, alignment: HorizontalAlignment) -> TextBoxStyleBuilder {
self.style.alignment = alignment;

Expand All @@ -92,7 +89,6 @@ impl TextBoxStyleBuilder {

/// Sets the vertical text alignment.
#[inline]
#[must_use]
pub const fn vertical_alignment(
mut self,
vertical_alignment: VerticalAlignment,
Expand All @@ -104,7 +100,6 @@ impl TextBoxStyleBuilder {

/// Sets the height mode.
#[inline]
#[must_use]
pub const fn height_mode(mut self, height_mode: HeightMode) -> TextBoxStyleBuilder {
self.style.height_mode = height_mode;

Expand All @@ -113,7 +108,6 @@ impl TextBoxStyleBuilder {

/// Sets the tab size.
#[inline]
#[must_use]
pub const fn tab_size(mut self, tab_size: TabSize) -> Self {
self.style.tab_size = tab_size;

Expand All @@ -124,7 +118,6 @@ impl TextBoxStyleBuilder {
///
/// [`TextBoxStyle`]: struct.TextBoxStyle.html
#[inline]
#[must_use]
pub const fn build(self) -> TextBoxStyle {
self.style
}
Expand Down
4 changes: 2 additions & 2 deletions src/style/height_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl HeightMode {
/// Apply the height mode to the text box.
///
/// *Note:* This function normally does not need to be called manually.
pub fn apply<F>(self, text_box: &mut TextBox<'_, F>)
pub(crate) fn apply<F>(self, text_box: &mut TextBox<'_, F>)
where
F: TextRenderer,
{
Expand All @@ -216,7 +216,7 @@ impl HeightMode {
/// If a line does not fully fit in the bounding box, some `HeightMode` options allow drawing
/// partial lines. For a partial line, this function calculates, which rows of each character
/// should be displayed.
pub fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range<i32> {
pub(crate) fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range<i32> {
let overdraw = match self {
HeightMode::Exact(overdraw) | HeightMode::ShrinkToText(overdraw) => overdraw,
HeightMode::FitToText => VerticalOverdraw::Visible,
Expand Down
3 changes: 2 additions & 1 deletion src/style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ impl TabSize {
/// [`from_text_style`]: #method.from_text_style
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[non_exhaustive]
#[must_use]
pub struct TextBoxStyle {
/// Horizontal text alignment.
pub alignment: HorizontalAlignment,
Expand Down Expand Up @@ -252,6 +253,7 @@ impl Default for TextBoxStyle {

/// Information about a line.
#[derive(Debug)]
#[must_use]
pub struct LineMeasurement {
/// Maximum line width in pixels.
pub max_line_width: u32,
Expand Down Expand Up @@ -306,7 +308,6 @@ impl TextBoxStyle {
/// processing a token. If a token opens a new line, it will be returned as the carried token.
/// If the carried token is `None`, the parser has finished processing the text.
#[inline]
#[must_use]
pub(crate) fn measure_line<'a, S>(
&self,
character_style: &S,
Expand Down
2 changes: 1 addition & 1 deletion src/style/vertical_overdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum VerticalOverdraw {

impl VerticalOverdraw {
/// Calculate the range of rows of the current line that can be drawn.
pub fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range<i32> {
pub(crate) fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range<i32> {
match self {
VerticalOverdraw::FullRowsOnly => {
if cursor.in_display_area() {
Expand Down

0 comments on commit 154f2bb

Please sign in to comment.