Fix some clippy issues

This commit is contained in:
Emil Ernerfeldt 2020-05-30 11:16:31 +02:00
parent b80baf4039
commit 598564cecc
12 changed files with 38 additions and 39 deletions

View file

@ -31,14 +31,10 @@ impl Default for State {
impl State { impl State {
pub fn from_memory_with_default_open(ui: &Ui, id: Id, default_open: bool) -> Self { pub fn from_memory_with_default_open(ui: &Ui, id: Id, default_open: bool) -> Self {
ui.memory() *ui.memory().collapsing_headers.entry(id).or_insert(State {
.collapsing_headers
.entry(id)
.or_insert(State {
open: default_open, open: default_open,
..Default::default() ..Default::default()
}) })
.clone()
} }
// Helper // Helper

View file

@ -193,7 +193,7 @@ impl<'open> Window<'open> {
let default_expanded = true; let default_expanded = true;
let mut collapsing = collapsing_header::State::from_memory_with_default_open( let mut collapsing = collapsing_header::State::from_memory_with_default_open(
&mut frame.content_ui, &frame.content_ui,
collapsing_id, collapsing_id,
default_expanded, default_expanded,
); );
@ -244,15 +244,13 @@ impl<'open> Window<'open> {
interaction, interaction,
ctx.style().interact.active, ctx.style().interact.active,
); );
} else { } else if let Some(hover_interaction) = hover_interaction {
if let Some(hover_interaction) = hover_interaction { paint_frame_interaction(
paint_frame_interaction( &mut area_content_ui,
&mut area_content_ui, outer_rect,
outer_rect, hover_interaction,
hover_interaction, ctx.style().interact.hovered,
ctx.style().interact.hovered, );
);
}
} }
} }
let full_interact = area.end(ctx, area_content_ui); let full_interact = area.end(ctx, area_content_ui);
@ -357,7 +355,7 @@ fn resize_window(ctx: &Context, window_interaction: &WindowInteraction) -> Optio
rect = rect.translate(mouse_pos - ctx.input().mouse.press_origin?); rect = rect.translate(mouse_pos - ctx.input().mouse.press_origin?);
} }
return Some(rect); Some(rect)
} }
fn window_interaction( fn window_interaction(
@ -375,7 +373,7 @@ fn window_interaction(
} }
} }
let mut window_interaction = { ctx.memory().window_interaction.clone() }; let mut window_interaction = { ctx.memory().window_interaction };
if window_interaction.is_none() { if window_interaction.is_none() {
if let Some(hover_window_interaction) = resize_hover(ctx, possible, area_layer, rect) { if let Some(hover_window_interaction) = resize_hover(ctx, possible, area_layer, rect) {

View file

@ -106,7 +106,7 @@ impl Context {
// TODO: return MutexGuard // TODO: return MutexGuard
pub fn style(&self) -> Style { pub fn style(&self) -> Style {
*self.style.try_lock().expect("style already locked") self.style.try_lock().expect("style already locked").clone()
} }
pub fn set_style(&self, style: Style) { pub fn set_style(&self, style: Style) {
@ -303,14 +303,14 @@ impl Context {
active: false, active: false,
}; };
if sense.click && !memory.interaction.click_id.is_some() { if sense.click && memory.interaction.click_id.is_none() {
// start of a click // start of a click
memory.interaction.click_id = Some(interaction_id); memory.interaction.click_id = Some(interaction_id);
info.active = true; info.active = true;
} }
if sense.drag if sense.drag
&& (!memory.interaction.drag_id.is_some() || memory.interaction.drag_is_window) && (memory.interaction.drag_id.is_none() || memory.interaction.drag_is_window)
{ {
// start of a drag // start of a drag
memory.interaction.drag_id = Some(interaction_id); memory.interaction.drag_id = Some(interaction_id);

View file

@ -90,7 +90,6 @@ impl ExampleApp {
struct OpenWindows { struct OpenWindows {
// examples: // examples:
examples: bool, examples: bool,
example_tree: bool,
fractal_clock: bool, fractal_clock: bool,
// egui stuff: // egui stuff:
@ -112,7 +111,6 @@ impl OpenWindows {
fn none() -> Self { fn none() -> Self {
Self { Self {
examples: false, examples: false,
example_tree: true,
fractal_clock: false, fractal_clock: false,
settings: false, settings: false,

View file

@ -125,17 +125,17 @@ impl Layout {
} }
} }
pub fn dir(&self) -> Direction { pub fn dir(self) -> Direction {
self.dir self.dir
} }
pub fn is_reversed(&self) -> bool { pub fn is_reversed(self) -> bool {
self.reversed self.reversed
} }
/// Given the cursor in the region, how much space is available /// Given the cursor in the region, how much space is available
/// for the next widget? /// for the next widget?
pub fn available(&self, cursor: Pos2, rect: Rect) -> Rect { pub fn available(self, cursor: Pos2, rect: Rect) -> Rect {
if self.reversed { if self.reversed {
Rect::from_min_max(rect.min, cursor) Rect::from_min_max(rect.min, cursor)
} else { } else {
@ -156,7 +156,7 @@ impl Layout {
/// ///
/// You may get LESS space than you asked for if the current layout won't fit what you asked for. /// You may get LESS space than you asked for if the current layout won't fit what you asked for.
pub fn allocate_space( pub fn allocate_space(
&self, self,
cursor: &mut Pos2, cursor: &mut Pos2,
style: &Style, style: &Style,
available_size: Vec2, available_size: Vec2,

View file

@ -65,7 +65,7 @@ impl Vec2 {
} }
/// Use this vector as a rotor, rotating something else. /// Use this vector as a rotor, rotating something else.
/// Example: Vec2::angled(angle).rotate_other(some_vec) /// Example: `Vec2::angled(angle).rotate_other(some_vec)`
#[must_use] #[must_use]
pub fn rotate_other(self, v: Vec2) -> Self { pub fn rotate_other(self, v: Vec2) -> Self {
Self { Self {

View file

@ -98,7 +98,7 @@ impl Memory {
if window_interaction.is_pure_move() { if window_interaction.is_pure_move() {
// Throw windows because it is fun: // Throw windows because it is fun:
let area_layer = window_interaction.area_layer; let area_layer = window_interaction.area_layer;
let area_state = self.areas.get(area_layer.id).clone(); let area_state = self.areas.get(area_layer.id);
if let Some(mut area_state) = area_state { if let Some(mut area_state) = area_state {
area_state.vel = prev_input.mouse.velocity; area_state.vel = prev_input.mouse.velocity;
self.areas.set_state(area_layer, area_state); self.areas.set_state(area_layer, area_state);

View file

@ -133,7 +133,7 @@ impl Line {
*self.x_offsets.last().unwrap() *self.x_offsets.last().unwrap()
} }
/// Closest char at the desired x coordinate. return [0, char_count()] /// Closest char at the desired x coordinate. returns something in the range `[0, char_count()]`
pub fn char_at(&self, desired_x: f32) -> usize { pub fn char_at(&self, desired_x: f32) -> usize {
for (i, char_x_bounds) in self.x_offsets.windows(2).enumerate() { for (i, char_x_bounds) in self.x_offsets.windows(2).enumerate() {
let char_center_x = 0.5 * (char_x_bounds[0] + char_x_bounds[1]); let char_center_x = 0.5 * (char_x_bounds[0] + char_x_bounds[1]);
@ -382,7 +382,7 @@ impl Font {
/// Typeset the given text onto one line. /// Typeset the given text onto one line.
/// Assumes there are no \n in the text. /// Assumes there are no \n in the text.
/// Return x_offsets, one longer than the number of characters in the text. /// Return `x_offsets`, one longer than the number of characters in the text.
fn layout_single_line_fragment(&self, text: &str) -> Vec<f32> { fn layout_single_line_fragment(&self, text: &str) -> Vec<f32> {
let scale_in_pixels = Scale::uniform(self.scale_in_pixels); let scale_in_pixels = Scale::uniform(self.scale_in_pixels);
@ -417,7 +417,12 @@ impl Font {
let full_x_offsets = self.layout_single_line_fragment(text); let full_x_offsets = self.layout_single_line_fragment(text);
let mut line_start_x = full_x_offsets[0]; let mut line_start_x = full_x_offsets[0];
assert_eq!(line_start_x, 0.0);
{
#![allow(clippy::float_cmp)]
assert_eq!(line_start_x, 0.0);
}
let mut cursor_y = 0.0; let mut cursor_y = 0.0;
let mut line_start_idx = 0; let mut line_start_idx = 0;

View file

@ -1,3 +1,5 @@
// TODO: rename tessellator
#![allow(clippy::identity_op)] #![allow(clippy::identity_op)]
/// Outputs render info in a format suitable for e.g. OpenGL. /// Outputs render info in a format suitable for e.g. OpenGL.
@ -380,7 +382,7 @@ pub fn paint_path_outline(
options: PaintOptions, options: PaintOptions,
path_type: PathType, path_type: PathType,
path: &[PathPoint], path: &[PathPoint],
style: &LineStyle, style: LineStyle,
) { ) {
if style.color == color::TRANSPARENT { if style.color == color::TRANSPARENT {
return; return;
@ -574,7 +576,7 @@ pub fn paint_command_into_triangles(
fill_closed_path(out, options, &path.0, fill); fill_closed_path(out, options, &path.0, fill);
} }
if let Some(outline) = outline { if let Some(outline) = outline {
paint_path_outline(out, options, Closed, &path.0, &outline); paint_path_outline(out, options, Closed, &path.0, outline);
} }
} }
PaintCmd::Triangles(triangles) => { PaintCmd::Triangles(triangles) => {
@ -582,7 +584,7 @@ pub fn paint_command_into_triangles(
} }
PaintCmd::LineSegment { points, style } => { PaintCmd::LineSegment { points, style } => {
path.add_line_segment(points); path.add_line_segment(points);
paint_path_outline(out, options, Open, &path.0, &style); paint_path_outline(out, options, Open, &path.0, style);
} }
PaintCmd::Path { PaintCmd::Path {
path, path,
@ -600,7 +602,7 @@ pub fn paint_command_into_triangles(
} }
if let Some(outline) = outline { if let Some(outline) = outline {
let typ = if closed { Closed } else { Open }; let typ = if closed { Closed } else { Open };
paint_path_outline(out, options, typ, &path.0, &outline); paint_path_outline(out, options, typ, &path.0, outline);
} }
} }
} }
@ -620,7 +622,7 @@ pub fn paint_command_into_triangles(
fill_closed_path(out, options, &path.0, fill); fill_closed_path(out, options, &path.0, fill);
} }
if let Some(outline) = outline { if let Some(outline) = outline {
paint_path_outline(out, options, Closed, &path.0, &outline); paint_path_outline(out, options, Closed, &path.0, outline);
} }
} }
PaintCmd::Text { PaintCmd::Text {

View file

@ -3,7 +3,7 @@
use crate::{color::*, math::*, paint::LineStyle, types::*}; use crate::{color::*, math::*, paint::LineStyle, types::*};
// TODO: split into Spacing and Style? // TODO: split into Spacing and Style?
#[derive(Clone, Copy, Debug)] #[derive(Clone, Debug)]
#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Style { pub struct Style {
/// Horizontal and vertical padding within a window frame. /// Horizontal and vertical padding within a window frame.

View file

@ -82,7 +82,7 @@ impl Ui {
clip_rect, clip_rect,
desired_rect: child_rect, desired_rect: child_rect,
child_bounds: Rect::from_min_size(child_rect.min, Vec2::zero()), // TODO: Rect::nothing() ? child_bounds: Rect::from_min_size(child_rect.min, Vec2::zero()), // TODO: Rect::nothing() ?
style: self.style, style: self.style.clone(),
layout: self.layout, layout: self.layout,
cursor: child_rect.min, cursor: child_rect.min,
} }

View file

@ -258,5 +258,5 @@ fn line_from_number(s: &str, desired_line_number: usize) -> &str {
return line; return line;
} }
} }
return s; s
} }