Fix clippy warnings

This commit is contained in:
Edgar Geier 2023-02-28 19:42:53 +01:00
parent 2b991129e3
commit 6c501c6640
No known key found for this signature in database
GPG key ID: 7A65B51FD6B75EF5
9 changed files with 80 additions and 59 deletions

View file

@ -113,9 +113,9 @@ pub struct LayoutRun<'a> {
}
impl<'a> LayoutRun<'a> {
/// Return the pixel span Some((x_left, x_width)) of the highlighted area between cursor_start
/// and cursor_end within this run, or None if the cursor range does not intersect this run.
/// This may return widths of zero if cursor_start == cursor_end, if the run is empty, or if the
/// Return the pixel span `Some((x_left, x_width))` of the highlighted area between `cursor_start`
/// and `cursor_end` within this run, or None if the cursor range does not intersect this run.
/// This may return widths of zero if `cursor_start == cursor_end`, if the run is empty, or if the
/// region's left start boundary is the same as the cursor's end boundary or vice versa.
pub fn highlight(&self, cursor_start: Cursor, cursor_end: Cursor) -> Option<(f32, f32)> {
let mut x_start = None;
@ -208,7 +208,7 @@ impl<'a, 'b> LayoutRunIter<'a, 'b> {
buffer,
line_i: 0,
layout_i: 0,
remaining_len: bottom_cropped_layout_lines as usize,
remaining_len: bottom_cropped_layout_lines,
line_y: buffer.metrics.y_offset(),
total_layout: 0,
}
@ -311,6 +311,10 @@ pub struct Buffer<'a> {
impl<'a> Buffer<'a> {
/// Create a new [`Buffer`] with the provided [`FontSystem`] and [`Metrics`]
///
/// # Panics
///
/// Will panic if `metrics.line_height` is zero.
pub fn new(font_system: &'a FontSystem, metrics: Metrics) -> Self {
assert_ne!(metrics.line_height, 0.0, "line height cannot be 0");
@ -497,6 +501,10 @@ impl<'a> Buffer<'a> {
}
/// Set the current [`Metrics`]
///
/// # Panics
///
/// Will panic if `metrics.font_size` is zero.
pub fn set_metrics(&mut self, metrics: Metrics) {
if metrics != self.metrics {
assert_ne!(metrics.font_size, 0.0, "font size cannot be 0");

View file

@ -2,7 +2,10 @@
#[cfg(not(feature = "std"))]
use alloc::string::String;
use core::{cmp, iter::once};
use core::{
cmp::{self, Ordering},
iter::once,
};
use unicode_segmentation::UnicodeSegmentation;
#[cfg(feature = "swash")]
@ -432,14 +435,18 @@ impl<'a> Edit<'a> for Editor<'a> {
Action::Vertical(px) => {
// TODO more efficient
let lines = px / self.buffer.metrics().line_height as i32;
if lines < 0 {
for _ in 0..-lines {
self.action(Action::Up);
match lines.cmp(&0) {
Ordering::Less => {
for _ in 0..-lines {
self.action(Action::Up);
}
}
} else if lines > 0 {
for _ in 0..lines {
self.action(Action::Down);
Ordering::Greater => {
for _ in 0..lines {
self.action(Action::Down);
}
}
Ordering::Equal => {}
}
}
Action::Escape => {
@ -583,7 +590,7 @@ impl<'a> Edit<'a> for Editor<'a> {
} else if self.cursor.line > 0 {
self.cursor.line -= 1;
self.cursor.index = self.buffer.lines[self.cursor.line].text().len();
self.buffer.set_redraw(true)
self.buffer.set_redraw(true);
}
self.cursor_x_opt = None;
}

View file

@ -98,8 +98,8 @@ fn shape_fallback(
(glyphs, missing)
}
fn shape_run<'a>(
font_system: &'a FontSystem,
fn shape_run(
font_system: &FontSystem,
line: &str,
attrs_list: &AttrsList,
start_run: usize,
@ -278,8 +278,8 @@ pub struct ShapeWord {
}
impl ShapeWord {
pub fn new<'a>(
font_system: &'a FontSystem,
pub fn new(
font_system: &FontSystem,
line: &str,
attrs_list: &AttrsList,
word_range: Range<usize>,
@ -352,8 +352,8 @@ pub struct ShapeSpan {
}
impl ShapeSpan {
pub fn new<'a>(
font_system: &'a FontSystem,
pub fn new(
font_system: &FontSystem,
line: &str,
attrs_list: &AttrsList,
span_range: Range<usize>,
@ -434,7 +434,10 @@ pub struct ShapeLine {
type VlRange = (usize, (usize, usize), (usize, usize));
impl ShapeLine {
pub fn new<'a>(font_system: &'a FontSystem, line: &str, attrs_list: &AttrsList) -> Self {
/// # Panics
///
/// Will panic if `line` contains more than one paragraph.
pub fn new(font_system: &FontSystem, line: &str, attrs_list: &AttrsList) -> Self {
let mut spans = Vec::new();
let bidi = unicode_bidi::BidiInfo::new(line, None);