Fix clippy warnings
This commit is contained in:
parent
2b991129e3
commit
6c501c6640
9 changed files with 80 additions and 59 deletions
|
|
@ -74,7 +74,7 @@ impl fmt::Display for FontSize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static WRAP_MODE: &'static [Wrap] = &[Wrap::None, Wrap::Glyph, Wrap::Word];
|
static WRAP_MODE: &[Wrap] = &[Wrap::None, Wrap::Glyph, Wrap::Word];
|
||||||
|
|
||||||
fn main() -> cosmic::iced::Result {
|
fn main() -> cosmic::iced::Result {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
@ -274,7 +274,7 @@ impl Application for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<Message> {
|
fn view(&self) -> Element<Message> {
|
||||||
static THEMES: &'static [&'static str] = &["Dark", "Light"];
|
static THEMES: &[&str] = &["Dark", "Light"];
|
||||||
let theme_picker = pick_list(
|
let theme_picker = pick_list(
|
||||||
THEMES,
|
THEMES,
|
||||||
Some(match self.theme {
|
Some(match self.theme {
|
||||||
|
|
@ -375,11 +375,11 @@ fn update_alignment<'a, T: Edit<'a>>(editor: &mut T, align: Align) {
|
||||||
std::cmp::Ordering::Less => (select.line, current_line),
|
std::cmp::Ordering::Less => (select.line, current_line),
|
||||||
std::cmp::Ordering::Equal => (current_line, current_line),
|
std::cmp::Ordering::Equal => (current_line, current_line),
|
||||||
};
|
};
|
||||||
editor.buffer_mut().lines.get_mut(start..=end).map(|lines| {
|
if let Some(lines) = editor.buffer_mut().lines.get_mut(start..=end) {
|
||||||
for line in lines.iter_mut() {
|
for line in lines.iter_mut() {
|
||||||
line.set_align(Some(align));
|
line.set_align(Some(align));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} else if let Some(line) = editor.buffer_mut().lines.get_mut(current_line) {
|
} else if let Some(line) = editor.buffer_mut().lines.get_mut(current_line) {
|
||||||
line.set_align(Some(align));
|
line.set_align(Some(align));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ pub fn draw_pixel(
|
||||||
|
|
||||||
let mut current = buffer[offset + 2] as u32
|
let mut current = buffer[offset + 2] as u32
|
||||||
| (buffer[offset + 1] as u32) << 8
|
| (buffer[offset + 1] as u32) << 8
|
||||||
| (buffer[offset + 0] as u32) << 16
|
| (buffer[offset] as u32) << 16
|
||||||
| (buffer[offset + 3] as u32) << 24;
|
| (buffer[offset + 3] as u32) << 24;
|
||||||
|
|
||||||
if alpha >= 255 || current == 0 {
|
if alpha >= 255 || current == 0 {
|
||||||
|
|
@ -244,7 +244,7 @@ pub fn draw_pixel(
|
||||||
|
|
||||||
buffer[offset + 2] = current as u8;
|
buffer[offset + 2] = current as u8;
|
||||||
buffer[offset + 1] = (current >> 8) as u8;
|
buffer[offset + 1] = (current >> 8) as u8;
|
||||||
buffer[offset + 0] = (current >> 16) as u8;
|
buffer[offset] = (current >> 16) as u8;
|
||||||
buffer[offset + 3] = (current >> 24) as u8;
|
buffer[offset + 3] = (current >> 24) as u8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ impl<'a, Editor> TextBox<'a, Editor> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_box<'a, Editor>(editor: &'a Mutex<Editor>) -> TextBox<'a, Editor> {
|
pub fn text_box<Editor>(editor: &Mutex<Editor>) -> TextBox<Editor> {
|
||||||
TextBox::new(editor)
|
TextBox::new(editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -174,7 +174,7 @@ where
|
||||||
&mut state.cache.lock().unwrap(),
|
&mut state.cache.lock().unwrap(),
|
||||||
text_color,
|
text_color,
|
||||||
|x, y, w, h, color| {
|
|x, y, w, h, color| {
|
||||||
if w <= 0 || h <= 0 {
|
if w == 0 || h == 0 {
|
||||||
// Do not draw invalid sized rectangles
|
// Do not draw invalid sized rectangles
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -235,10 +235,7 @@ where
|
||||||
|
|
||||||
let mut status = Status::Ignored;
|
let mut status = Status::Ignored;
|
||||||
match event {
|
match event {
|
||||||
Event::Keyboard(KeyEvent::KeyPressed {
|
Event::Keyboard(KeyEvent::KeyPressed { key_code, .. }) => match key_code {
|
||||||
key_code,
|
|
||||||
modifiers,
|
|
||||||
}) => match key_code {
|
|
||||||
KeyCode::Left => {
|
KeyCode::Left => {
|
||||||
editor.action(Action::Left);
|
editor.action(Action::Left);
|
||||||
status = Status::Captured;
|
status = Status::Captured;
|
||||||
|
|
@ -318,15 +315,14 @@ where
|
||||||
status = Status::Captured;
|
status = Status::Captured;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Mouse(MouseEvent::WheelScrolled { delta }) => match delta {
|
Event::Mouse(MouseEvent::WheelScrolled {
|
||||||
ScrollDelta::Lines { x, y } => {
|
delta: ScrollDelta::Lines { y, .. },
|
||||||
editor.action(Action::Scroll {
|
}) => {
|
||||||
lines: (-y * 6.0) as i32,
|
editor.action(Action::Scroll {
|
||||||
});
|
lines: (-y * 6.0) as i32,
|
||||||
status = Status::Captured;
|
});
|
||||||
}
|
status = Status::Captured;
|
||||||
_ => (),
|
}
|
||||||
},
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let path = if let Some(arg) = env::args().nth(1) {
|
let path = if let Some(arg) = env::args().nth(1) {
|
||||||
arg.clone()
|
arg
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
|
|
@ -35,7 +35,7 @@ fn main() {
|
||||||
-1,
|
-1,
|
||||||
1024 * display_scale as u32,
|
1024 * display_scale as u32,
|
||||||
768 * display_scale as u32,
|
768 * display_scale as u32,
|
||||||
&format!("COSMIC Text - {}", path),
|
&format!("COSMIC Text - {path}"),
|
||||||
&[WindowFlag::Resizable],
|
&[WindowFlag::Resizable],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -110,7 +110,7 @@ fn main() {
|
||||||
let mut end_line = 0;
|
let mut end_line = 0;
|
||||||
for run in editor.buffer().layout_runs() {
|
for run in editor.buffer().layout_runs() {
|
||||||
end_line = run.line_i;
|
end_line = run.line_i;
|
||||||
if start_line_opt == None {
|
if start_line_opt.is_none() {
|
||||||
start_line_opt = Some(end_line);
|
start_line_opt = Some(end_line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -131,9 +131,8 @@ fn main() {
|
||||||
redraw(&mut window, &mut editor, &mut swash_cache);
|
redraw(&mut window, &mut editor, &mut swash_cache);
|
||||||
|
|
||||||
for event in window.events() {
|
for event in window.events() {
|
||||||
match event.to_option() {
|
if let EventOption::Quit(_) = event.to_option() {
|
||||||
EventOption::Quit(_) => process::exit(1),
|
process::exit(1)
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use cosmic_text::{Attrs, Buffer, Color, FontSystem, Metrics, SwashCache};
|
use cosmic_text::{Attrs, Buffer, Color, FontSystem, Metrics, SwashCache};
|
||||||
use std::cmp;
|
use std::cmp::{self, Ordering};
|
||||||
use termion::{color, cursor};
|
use termion::{color, cursor};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
@ -66,21 +66,29 @@ fn main() {
|
||||||
let scale = |c: u8| cmp::max(0, cmp::min(255, ((c as i32) * (a as i32)) / 255)) as u8;
|
let scale = |c: u8| cmp::max(0, cmp::min(255, ((c as i32) * (a as i32)) / 255)) as u8;
|
||||||
|
|
||||||
// Navigate to x coordinate
|
// Navigate to x coordinate
|
||||||
if x > last_x {
|
match x.cmp(&last_x) {
|
||||||
print!("{}", cursor::Right((x - last_x) as u16));
|
Ordering::Greater => {
|
||||||
last_x = x;
|
print!("{}", cursor::Right((x - last_x) as u16));
|
||||||
} else if x < last_x {
|
last_x = x;
|
||||||
print!("{}", cursor::Left((last_x - x) as u16));
|
}
|
||||||
last_x = x;
|
Ordering::Less => {
|
||||||
|
print!("{}", cursor::Left((last_x - x) as u16));
|
||||||
|
last_x = x;
|
||||||
|
}
|
||||||
|
Ordering::Equal => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Navigate to y coordinate
|
// Navigate to y coordinate
|
||||||
if y > last_y {
|
match y.cmp(&last_y) {
|
||||||
print!("{}", cursor::Down((y - last_y) as u16));
|
Ordering::Greater => {
|
||||||
last_y = y;
|
print!("{}", cursor::Down((y - last_y) as u16));
|
||||||
} else if y < last_y {
|
last_y = y;
|
||||||
print!("{}", cursor::Up((last_y - y) as u16));
|
}
|
||||||
last_y = y;
|
Ordering::Less => {
|
||||||
|
print!("{}", cursor::Up((last_y - y) as u16));
|
||||||
|
last_y = y;
|
||||||
|
}
|
||||||
|
Ordering::Equal => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print a space with the expected color as the background
|
// Print a space with the expected color as the background
|
||||||
|
|
|
||||||
|
|
@ -113,9 +113,9 @@ pub struct LayoutRun<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LayoutRun<'a> {
|
impl<'a> LayoutRun<'a> {
|
||||||
/// Return the pixel span Some((x_left, x_width)) of the highlighted area between cursor_start
|
/// 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.
|
/// 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
|
/// 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.
|
/// 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)> {
|
pub fn highlight(&self, cursor_start: Cursor, cursor_end: Cursor) -> Option<(f32, f32)> {
|
||||||
let mut x_start = None;
|
let mut x_start = None;
|
||||||
|
|
@ -208,7 +208,7 @@ impl<'a, 'b> LayoutRunIter<'a, 'b> {
|
||||||
buffer,
|
buffer,
|
||||||
line_i: 0,
|
line_i: 0,
|
||||||
layout_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(),
|
line_y: buffer.metrics.y_offset(),
|
||||||
total_layout: 0,
|
total_layout: 0,
|
||||||
}
|
}
|
||||||
|
|
@ -311,6 +311,10 @@ pub struct Buffer<'a> {
|
||||||
|
|
||||||
impl<'a> Buffer<'a> {
|
impl<'a> Buffer<'a> {
|
||||||
/// Create a new [`Buffer`] with the provided [`FontSystem`] and [`Metrics`]
|
/// 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 {
|
pub fn new(font_system: &'a FontSystem, metrics: Metrics) -> Self {
|
||||||
assert_ne!(metrics.line_height, 0.0, "line height cannot be 0");
|
assert_ne!(metrics.line_height, 0.0, "line height cannot be 0");
|
||||||
|
|
||||||
|
|
@ -497,6 +501,10 @@ impl<'a> Buffer<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the current [`Metrics`]
|
/// Set the current [`Metrics`]
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Will panic if `metrics.font_size` is zero.
|
||||||
pub fn set_metrics(&mut self, metrics: Metrics) {
|
pub fn set_metrics(&mut self, metrics: Metrics) {
|
||||||
if metrics != self.metrics {
|
if metrics != self.metrics {
|
||||||
assert_ne!(metrics.font_size, 0.0, "font size cannot be 0");
|
assert_ne!(metrics.font_size, 0.0, "font size cannot be 0");
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use core::{cmp, iter::once};
|
use core::{
|
||||||
|
cmp::{self, Ordering},
|
||||||
|
iter::once,
|
||||||
|
};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
#[cfg(feature = "swash")]
|
#[cfg(feature = "swash")]
|
||||||
|
|
@ -432,14 +435,18 @@ impl<'a> Edit<'a> for Editor<'a> {
|
||||||
Action::Vertical(px) => {
|
Action::Vertical(px) => {
|
||||||
// TODO more efficient
|
// TODO more efficient
|
||||||
let lines = px / self.buffer.metrics().line_height as i32;
|
let lines = px / self.buffer.metrics().line_height as i32;
|
||||||
if lines < 0 {
|
match lines.cmp(&0) {
|
||||||
for _ in 0..-lines {
|
Ordering::Less => {
|
||||||
self.action(Action::Up);
|
for _ in 0..-lines {
|
||||||
|
self.action(Action::Up);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if lines > 0 {
|
Ordering::Greater => {
|
||||||
for _ in 0..lines {
|
for _ in 0..lines {
|
||||||
self.action(Action::Down);
|
self.action(Action::Down);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Ordering::Equal => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::Escape => {
|
Action::Escape => {
|
||||||
|
|
@ -583,7 +590,7 @@ impl<'a> Edit<'a> for Editor<'a> {
|
||||||
} else if self.cursor.line > 0 {
|
} else if self.cursor.line > 0 {
|
||||||
self.cursor.line -= 1;
|
self.cursor.line -= 1;
|
||||||
self.cursor.index = self.buffer.lines[self.cursor.line].text().len();
|
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;
|
self.cursor_x_opt = None;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
src/shape.rs
17
src/shape.rs
|
|
@ -98,8 +98,8 @@ fn shape_fallback(
|
||||||
(glyphs, missing)
|
(glyphs, missing)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shape_run<'a>(
|
fn shape_run(
|
||||||
font_system: &'a FontSystem,
|
font_system: &FontSystem,
|
||||||
line: &str,
|
line: &str,
|
||||||
attrs_list: &AttrsList,
|
attrs_list: &AttrsList,
|
||||||
start_run: usize,
|
start_run: usize,
|
||||||
|
|
@ -278,8 +278,8 @@ pub struct ShapeWord {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShapeWord {
|
impl ShapeWord {
|
||||||
pub fn new<'a>(
|
pub fn new(
|
||||||
font_system: &'a FontSystem,
|
font_system: &FontSystem,
|
||||||
line: &str,
|
line: &str,
|
||||||
attrs_list: &AttrsList,
|
attrs_list: &AttrsList,
|
||||||
word_range: Range<usize>,
|
word_range: Range<usize>,
|
||||||
|
|
@ -352,8 +352,8 @@ pub struct ShapeSpan {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShapeSpan {
|
impl ShapeSpan {
|
||||||
pub fn new<'a>(
|
pub fn new(
|
||||||
font_system: &'a FontSystem,
|
font_system: &FontSystem,
|
||||||
line: &str,
|
line: &str,
|
||||||
attrs_list: &AttrsList,
|
attrs_list: &AttrsList,
|
||||||
span_range: Range<usize>,
|
span_range: Range<usize>,
|
||||||
|
|
@ -434,7 +434,10 @@ pub struct ShapeLine {
|
||||||
type VlRange = (usize, (usize, usize), (usize, usize));
|
type VlRange = (usize, (usize, usize), (usize, usize));
|
||||||
|
|
||||||
impl ShapeLine {
|
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 mut spans = Vec::new();
|
||||||
|
|
||||||
let bidi = unicode_bidi::BidiInfo::new(line, None);
|
let bidi = unicode_bidi::BidiInfo::new(line, None);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue