Clippy Fixes
This commit is contained in:
parent
e39f8eabd5
commit
5200f67196
5 changed files with 61 additions and 62 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||
|
||||
use std::{
|
||||
cmp,
|
||||
cmp::{self, Ordering},
|
||||
fmt,
|
||||
time::Instant,
|
||||
};
|
||||
|
|
@ -364,7 +364,7 @@ impl<'a> TextBuffer<'a> {
|
|||
fn set_layout_cursor(&mut self, cursor: LayoutCursor) {
|
||||
let line = &mut self.lines[cursor.line.get()];
|
||||
let layout = line.layout(
|
||||
&mut self.font_matches,
|
||||
self.font_matches,
|
||||
self.metrics.font_size,
|
||||
self.width
|
||||
);
|
||||
|
|
@ -543,7 +543,7 @@ impl<'a> TextBuffer<'a> {
|
|||
let layout_len = {
|
||||
let line = &mut self.lines[cursor.line.get()];
|
||||
let layout = line.layout(
|
||||
&mut self.font_matches,
|
||||
self.font_matches,
|
||||
self.metrics.font_size,
|
||||
self.width
|
||||
);
|
||||
|
|
@ -733,7 +733,7 @@ impl<'a> TextBuffer<'a> {
|
|||
new_cursor_char = egc_i;
|
||||
|
||||
let right_half = mouse_x >= (egc_x + egc_w / 2.0) as i32;
|
||||
if right_half == !glyph.rtl {
|
||||
if right_half != glyph.rtl {
|
||||
// If clicking on last half of glyph, move cursor past glyph
|
||||
new_cursor_char += egc.len();
|
||||
}
|
||||
|
|
@ -743,7 +743,7 @@ impl<'a> TextBuffer<'a> {
|
|||
}
|
||||
|
||||
let right_half = mouse_x >= (glyph.x + glyph.w / 2.0) as i32;
|
||||
if right_half == !glyph.rtl {
|
||||
if right_half != glyph.rtl {
|
||||
// If clicking on last half of glyph, move cursor past glyph
|
||||
new_cursor_char = cluster.len();
|
||||
}
|
||||
|
|
@ -758,14 +758,9 @@ impl<'a> TextBuffer<'a> {
|
|||
// Position at glyph
|
||||
new_cursor.index = glyph.start + new_cursor_char;
|
||||
},
|
||||
None => match layout_line.glyphs.last() {
|
||||
Some(glyph) => {
|
||||
// Position at end of line
|
||||
new_cursor.index = glyph.end;
|
||||
},
|
||||
None => {
|
||||
// Keep at start of empty line
|
||||
},
|
||||
None => if let Some(glyph) = layout_line.glyphs.last() {
|
||||
// Position at end of line
|
||||
new_cursor.index = glyph.end;
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -872,17 +867,17 @@ impl<'a> TextBuffer<'a> {
|
|||
|
||||
// Highlight selection (TODO: HIGHLIGHT COLOR!)
|
||||
if let Some(select) = self.select_opt {
|
||||
let (start, end) = if select.line < self.cursor.line {
|
||||
(select, self.cursor)
|
||||
} else if select.line > self.cursor.line {
|
||||
(self.cursor, select)
|
||||
} else {
|
||||
/* select.line == self.cursor.line */
|
||||
if select.index < self.cursor.index {
|
||||
(select, self.cursor)
|
||||
} else {
|
||||
/* select.index >= self.cursor.index */
|
||||
(self.cursor, select)
|
||||
let (start, end) = match select.line.cmp(&self.cursor.line) {
|
||||
Ordering::Greater => (self.cursor, select),
|
||||
Ordering::Less => (select, self.cursor),
|
||||
Ordering::Equal => {
|
||||
/* select.line == self.cursor.line */
|
||||
if select.index < self.cursor.index {
|
||||
(select, self.cursor)
|
||||
} else {
|
||||
/* select.index >= self.cursor.index */
|
||||
(self.cursor, select)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -909,43 +904,35 @@ impl<'a> TextBuffer<'a> {
|
|||
(c_x + c_w) as i32,
|
||||
))
|
||||
};
|
||||
} else {
|
||||
match range_opt.take() {
|
||||
Some((min, max)) => {
|
||||
f(
|
||||
min,
|
||||
line_y - font_size,
|
||||
cmp::max(0, max - min) as u32,
|
||||
line_height as u32,
|
||||
0x33_00_00_00 | (color & 0xFF_FF_FF)
|
||||
);
|
||||
},
|
||||
None => (),
|
||||
}
|
||||
} else if let Some((min, max)) = range_opt.take() {
|
||||
f(
|
||||
min,
|
||||
line_y - font_size,
|
||||
cmp::max(0, max - min) as u32,
|
||||
line_height as u32,
|
||||
0x33_00_00_00 | (color & 0xFF_FF_FF)
|
||||
);
|
||||
}
|
||||
c_x += c_w;
|
||||
}
|
||||
}
|
||||
|
||||
match range_opt.take() {
|
||||
Some((mut min, mut max)) => {
|
||||
if end.line.get() > line_i {
|
||||
// Draw to end of line
|
||||
if shape.rtl {
|
||||
min = 0;
|
||||
} else {
|
||||
max = self.width;
|
||||
}
|
||||
if let Some((mut min, mut max)) = range_opt.take() {
|
||||
if end.line.get() > line_i {
|
||||
// Draw to end of line
|
||||
if shape.rtl {
|
||||
min = 0;
|
||||
} else {
|
||||
max = self.width;
|
||||
}
|
||||
f(
|
||||
min,
|
||||
line_y - font_size,
|
||||
cmp::max(0, max - min) as u32,
|
||||
line_height as u32,
|
||||
0x33_00_00_00 | (color & 0xFF_FF_FF)
|
||||
);
|
||||
},
|
||||
None => (),
|
||||
}
|
||||
f(
|
||||
min,
|
||||
line_y - font_size,
|
||||
cmp::max(0, max - min) as u32,
|
||||
line_height as u32,
|
||||
0x33_00_00_00 | (color & 0xFF_FF_FF)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,12 @@ pub struct CacheKey {
|
|||
}
|
||||
|
||||
impl CacheKey {
|
||||
pub fn new(font_id: fontdb::ID, glyph_id: u16, font_size: i32, pos: (f32, f32)) -> (Self, i32, i32) {
|
||||
pub fn new(
|
||||
font_id: fontdb::ID,
|
||||
glyph_id: u16,
|
||||
font_size: i32,
|
||||
pos: (f32, f32),
|
||||
) -> (Self, i32, i32) {
|
||||
let (x, x_bin) = SubpixelBin::new(pos.0);
|
||||
let (y, y_bin) = SubpixelBin::new(pos.1);
|
||||
(
|
||||
|
|
@ -54,6 +59,7 @@ impl SubpixelBin {
|
|||
(trunc - 1, Self::Zero)
|
||||
}
|
||||
} else {
|
||||
#[allow(clippy::collapsible_else_if)]
|
||||
if fract < 0.125 {
|
||||
(trunc, Self::Zero)
|
||||
} else if fract < 0.375 {
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ impl<'a> FontMatches<'a> {
|
|||
&self.fonts,
|
||||
&["Fira Sans", "Fira Mono"],
|
||||
scripts,
|
||||
&self.locale
|
||||
self.locale
|
||||
);
|
||||
|
||||
let (mut glyphs, mut missing) = self.shape_fallback(
|
||||
|
|
@ -306,7 +306,7 @@ impl<'a> FontMatches<'a> {
|
|||
|
||||
log::trace!("Line {}: '{}'", if line_rtl { "RTL" } else { "LTR" }, line);
|
||||
|
||||
let paragraph = unicode_bidi::Paragraph::new(&bidi, ¶_info);
|
||||
let paragraph = unicode_bidi::Paragraph::new(&bidi, para_info);
|
||||
|
||||
let mut start = 0;
|
||||
let mut span_rtl = line_rtl;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ impl<'a> FontShapeGlyph<'a> {
|
|||
FontLayoutGlyph {
|
||||
start: self.start,
|
||||
end: self.end,
|
||||
x: x,
|
||||
x,
|
||||
w: x_advance,
|
||||
rtl,
|
||||
font: self.font,
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ impl FontSystem {
|
|||
Self { locale, db }
|
||||
}
|
||||
|
||||
pub fn matches<'a, F: Fn(&fontdb::FaceInfo) -> bool>(
|
||||
&'a self,
|
||||
pub fn matches<F: Fn(&fontdb::FaceInfo) -> bool>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> Option<FontMatches<'a>> {
|
||||
) -> Option<FontMatches<'_>> {
|
||||
let mut fonts = Vec::new();
|
||||
for face in self.db.faces() {
|
||||
if !f(face) {
|
||||
|
|
@ -84,3 +84,9 @@ impl FontSystem {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for FontSystem {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue