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
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
cmp,
|
cmp::{self, Ordering},
|
||||||
fmt,
|
fmt,
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
@ -364,7 +364,7 @@ impl<'a> TextBuffer<'a> {
|
||||||
fn set_layout_cursor(&mut self, cursor: LayoutCursor) {
|
fn set_layout_cursor(&mut self, cursor: LayoutCursor) {
|
||||||
let line = &mut self.lines[cursor.line.get()];
|
let line = &mut self.lines[cursor.line.get()];
|
||||||
let layout = line.layout(
|
let layout = line.layout(
|
||||||
&mut self.font_matches,
|
self.font_matches,
|
||||||
self.metrics.font_size,
|
self.metrics.font_size,
|
||||||
self.width
|
self.width
|
||||||
);
|
);
|
||||||
|
|
@ -543,7 +543,7 @@ impl<'a> TextBuffer<'a> {
|
||||||
let layout_len = {
|
let layout_len = {
|
||||||
let line = &mut self.lines[cursor.line.get()];
|
let line = &mut self.lines[cursor.line.get()];
|
||||||
let layout = line.layout(
|
let layout = line.layout(
|
||||||
&mut self.font_matches,
|
self.font_matches,
|
||||||
self.metrics.font_size,
|
self.metrics.font_size,
|
||||||
self.width
|
self.width
|
||||||
);
|
);
|
||||||
|
|
@ -733,7 +733,7 @@ impl<'a> TextBuffer<'a> {
|
||||||
new_cursor_char = egc_i;
|
new_cursor_char = egc_i;
|
||||||
|
|
||||||
let right_half = mouse_x >= (egc_x + egc_w / 2.0) as i32;
|
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
|
// If clicking on last half of glyph, move cursor past glyph
|
||||||
new_cursor_char += egc.len();
|
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;
|
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
|
// If clicking on last half of glyph, move cursor past glyph
|
||||||
new_cursor_char = cluster.len();
|
new_cursor_char = cluster.len();
|
||||||
}
|
}
|
||||||
|
|
@ -758,14 +758,9 @@ impl<'a> TextBuffer<'a> {
|
||||||
// Position at glyph
|
// Position at glyph
|
||||||
new_cursor.index = glyph.start + new_cursor_char;
|
new_cursor.index = glyph.start + new_cursor_char;
|
||||||
},
|
},
|
||||||
None => match layout_line.glyphs.last() {
|
None => if let Some(glyph) = layout_line.glyphs.last() {
|
||||||
Some(glyph) => {
|
// Position at end of line
|
||||||
// Position at end of line
|
new_cursor.index = glyph.end;
|
||||||
new_cursor.index = glyph.end;
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
// Keep at start of empty line
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -872,17 +867,17 @@ impl<'a> TextBuffer<'a> {
|
||||||
|
|
||||||
// Highlight selection (TODO: HIGHLIGHT COLOR!)
|
// Highlight selection (TODO: HIGHLIGHT COLOR!)
|
||||||
if let Some(select) = self.select_opt {
|
if let Some(select) = self.select_opt {
|
||||||
let (start, end) = if select.line < self.cursor.line {
|
let (start, end) = match select.line.cmp(&self.cursor.line) {
|
||||||
(select, self.cursor)
|
Ordering::Greater => (self.cursor, select),
|
||||||
} else if select.line > self.cursor.line {
|
Ordering::Less => (select, self.cursor),
|
||||||
(self.cursor, select)
|
Ordering::Equal => {
|
||||||
} else {
|
/* select.line == self.cursor.line */
|
||||||
/* select.line == self.cursor.line */
|
if select.index < self.cursor.index {
|
||||||
if select.index < self.cursor.index {
|
(select, self.cursor)
|
||||||
(select, self.cursor)
|
} else {
|
||||||
} else {
|
/* select.index >= self.cursor.index */
|
||||||
/* select.index >= self.cursor.index */
|
(self.cursor, select)
|
||||||
(self.cursor, select)
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -909,43 +904,35 @@ impl<'a> TextBuffer<'a> {
|
||||||
(c_x + c_w) as i32,
|
(c_x + c_w) as i32,
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
} else {
|
} else if let Some((min, max)) = range_opt.take() {
|
||||||
match range_opt.take() {
|
f(
|
||||||
Some((min, max)) => {
|
min,
|
||||||
f(
|
line_y - font_size,
|
||||||
min,
|
cmp::max(0, max - min) as u32,
|
||||||
line_y - font_size,
|
line_height as u32,
|
||||||
cmp::max(0, max - min) as u32,
|
0x33_00_00_00 | (color & 0xFF_FF_FF)
|
||||||
line_height as u32,
|
);
|
||||||
0x33_00_00_00 | (color & 0xFF_FF_FF)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
None => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
c_x += c_w;
|
c_x += c_w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match range_opt.take() {
|
if let Some((mut min, mut max)) = range_opt.take() {
|
||||||
Some((mut min, mut max)) => {
|
if end.line.get() > line_i {
|
||||||
if end.line.get() > line_i {
|
// Draw to end of line
|
||||||
// Draw to end of line
|
if shape.rtl {
|
||||||
if shape.rtl {
|
min = 0;
|
||||||
min = 0;
|
} else {
|
||||||
} else {
|
max = self.width;
|
||||||
max = self.width;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
f(
|
}
|
||||||
min,
|
f(
|
||||||
line_y - font_size,
|
min,
|
||||||
cmp::max(0, max - min) as u32,
|
line_y - font_size,
|
||||||
line_height as u32,
|
cmp::max(0, max - min) as u32,
|
||||||
0x33_00_00_00 | (color & 0xFF_FF_FF)
|
line_height as u32,
|
||||||
);
|
0x33_00_00_00 | (color & 0xFF_FF_FF)
|
||||||
},
|
);
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,12 @@ pub struct CacheKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 (x, x_bin) = SubpixelBin::new(pos.0);
|
||||||
let (y, y_bin) = SubpixelBin::new(pos.1);
|
let (y, y_bin) = SubpixelBin::new(pos.1);
|
||||||
(
|
(
|
||||||
|
|
@ -54,6 +59,7 @@ impl SubpixelBin {
|
||||||
(trunc - 1, Self::Zero)
|
(trunc - 1, Self::Zero)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#[allow(clippy::collapsible_else_if)]
|
||||||
if fract < 0.125 {
|
if fract < 0.125 {
|
||||||
(trunc, Self::Zero)
|
(trunc, Self::Zero)
|
||||||
} else if fract < 0.375 {
|
} else if fract < 0.375 {
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ impl<'a> FontMatches<'a> {
|
||||||
&self.fonts,
|
&self.fonts,
|
||||||
&["Fira Sans", "Fira Mono"],
|
&["Fira Sans", "Fira Mono"],
|
||||||
scripts,
|
scripts,
|
||||||
&self.locale
|
self.locale
|
||||||
);
|
);
|
||||||
|
|
||||||
let (mut glyphs, mut missing) = self.shape_fallback(
|
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);
|
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 start = 0;
|
||||||
let mut span_rtl = line_rtl;
|
let mut span_rtl = line_rtl;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ impl<'a> FontShapeGlyph<'a> {
|
||||||
FontLayoutGlyph {
|
FontLayoutGlyph {
|
||||||
start: self.start,
|
start: self.start,
|
||||||
end: self.end,
|
end: self.end,
|
||||||
x: x,
|
x,
|
||||||
w: x_advance,
|
w: x_advance,
|
||||||
rtl,
|
rtl,
|
||||||
font: self.font,
|
font: self.font,
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,10 @@ impl FontSystem {
|
||||||
Self { locale, db }
|
Self { locale, db }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn matches<'a, F: Fn(&fontdb::FaceInfo) -> bool>(
|
pub fn matches<F: Fn(&fontdb::FaceInfo) -> bool>(
|
||||||
&'a self,
|
&self,
|
||||||
f: F,
|
f: F,
|
||||||
) -> Option<FontMatches<'a>> {
|
) -> Option<FontMatches<'_>> {
|
||||||
let mut fonts = Vec::new();
|
let mut fonts = Vec::new();
|
||||||
for face in self.db.faces() {
|
for face in self.db.faces() {
|
||||||
if !f(face) {
|
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