enforce and fix a bunch of clippy issues
This commit is contained in:
parent
077cc3d8d1
commit
87e3aacf35
25 changed files with 90 additions and 67 deletions
|
@ -3,6 +3,6 @@ set -eu
|
|||
|
||||
cargo fmt --all -- --check
|
||||
cargo check --all-features
|
||||
cargo clippy
|
||||
cargo clean -p emigui && cargo clippy
|
||||
|
||||
cargo run --bin example_glium --release
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/// 0-255 sRGBA
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Serialize)]
|
||||
/// 0-255 `sRGBA`. TODO: rename `sRGBA` for clarity.
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd, serde_derive::Serialize)]
|
||||
pub struct Color {
|
||||
pub r: u8,
|
||||
pub g: u8,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{layout::Direction, *};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||
#[serde(default)]
|
||||
pub(crate) struct State {
|
||||
open: bool,
|
||||
|
@ -136,8 +136,8 @@ impl CollapsingHeader {
|
|||
}
|
||||
|
||||
fn paint_icon(region: &mut Region, state: &State, interact: &InteractInfo) {
|
||||
let stroke_color = region.style().interact_stroke_color(&interact);
|
||||
let stroke_width = region.style().interact_stroke_width(&interact);
|
||||
let stroke_color = region.style().interact_stroke_color(interact);
|
||||
let stroke_width = region.style().interact_stroke_width(interact);
|
||||
|
||||
let (mut small_icon_rect, _) = region.style().icon_rectangles(interact.rect);
|
||||
small_icon_rect.set_center(pos2(
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::{fmt::Debug, hash::Hash, sync::Arc};
|
|||
|
||||
use crate::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||
pub(crate) struct State {
|
||||
/// Last known pos
|
||||
pub pos: Pos2,
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#![allow(unused_variables)] // TODO
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Copy, Debug, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||
pub(crate) struct State {
|
||||
size: Vec2,
|
||||
}
|
||||
|
@ -142,7 +143,7 @@ impl Resize {
|
|||
self.max_size = self.max_size.max(self.min_size);
|
||||
|
||||
let (is_new, mut state) = match region.memory().resize.get(&id) {
|
||||
Some(state) => (false, state.clone()),
|
||||
Some(state) => (false, *state),
|
||||
None => {
|
||||
let default_size = self.default_size.clamp(self.min_size..=self.max_size);
|
||||
(true, State { size: default_size })
|
||||
|
@ -234,8 +235,8 @@ impl Resize {
|
|||
}
|
||||
|
||||
fn paint_resize_corner(region: &mut Region, interact: &InteractInfo) {
|
||||
let color = region.style().interact_stroke_color(&interact);
|
||||
let width = region.style().interact_stroke_width(&interact);
|
||||
let color = region.style().interact_stroke_color(interact);
|
||||
let width = region.style().interact_stroke_width(interact);
|
||||
|
||||
let corner = interact.rect.right_bottom().round(); // TODO: round to pixels
|
||||
let mut w = 2.0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
|
||||
#[derive(Clone, Copy, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||
#[serde(default)]
|
||||
pub(crate) struct State {
|
||||
/// Positive offset means scrolling down/right
|
||||
|
|
|
@ -59,15 +59,15 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn memory(&self) -> parking_lot::MutexGuard<Memory> {
|
||||
pub fn memory(&self) -> parking_lot::MutexGuard<'_, Memory> {
|
||||
self.memory.lock()
|
||||
}
|
||||
|
||||
pub fn graphics(&self) -> parking_lot::MutexGuard<GraphicLayers> {
|
||||
pub fn graphics(&self) -> parking_lot::MutexGuard<'_, GraphicLayers> {
|
||||
self.graphics.lock()
|
||||
}
|
||||
|
||||
pub fn output(&self) -> parking_lot::MutexGuard<Output> {
|
||||
pub fn output(&self) -> parking_lot::MutexGuard<'_, Output> {
|
||||
self.output.lock()
|
||||
}
|
||||
|
||||
|
|
|
@ -288,7 +288,7 @@ impl Font {
|
|||
let mut cursor_y = 0.0;
|
||||
let mut text_fragments = Vec::new();
|
||||
for line in text.split('\n') {
|
||||
let mut line_fragments = self.layout_paragraph_max_width(&line, max_width_in_points);
|
||||
let mut line_fragments = self.layout_paragraph_max_width(line, max_width_in_points);
|
||||
if let Some(last_word) = line_fragments.last() {
|
||||
let line_height = last_word.y_offset + line_spacing;
|
||||
for fragment in &mut line_fragments {
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use {parking_lot::Mutex, serde_derive::Serialize};
|
||||
|
||||
use crate::{
|
||||
font::Font,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
//! Emigui tracks widgets frame-to-frame using `Id`s.
|
||||
//!
|
||||
//! For instance, if you start dragging a slider one frame, emigui stores
|
||||
//! the sldiers Id as the current interact_id so that next frame when
|
||||
//! the sldiers Id as the current `interact_id` so that next frame when
|
||||
//! you move the mouse the same slider changes, even if the mouse has
|
||||
//! moved outside the slider.
|
||||
//!
|
||||
//! For some widgets `Id`s are also used to GUIpersist some state about the
|
||||
//! For some widgets `Id`s are also used to persist some state about the
|
||||
//! widgets, such as Window position or wether not a collapsing header region is open.
|
||||
//!
|
||||
//! This implicated that the `Id`s must be unqiue.
|
||||
|
@ -24,14 +24,16 @@
|
|||
//! Then there are widgets that need no identifiers at all, like labels,
|
||||
//! because they have no state nor are interacted with.
|
||||
//!
|
||||
//! So we have two type of Ids: PositionId and UniqueId.
|
||||
//! TODO: have separate types for PositionId and UniqueId.
|
||||
//! So we have two type of Ids: `PositionId` and `UniqueId`.
|
||||
//! TODO: have separate types for `PositionId` and `UniqueId`.
|
||||
|
||||
use std::{collections::hash_map::DefaultHasher, hash::Hash};
|
||||
|
||||
use crate::math::Pos2;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Hash, Eq, PartialEq, serde_derive::Deserialize, serde_derive::Serialize,
|
||||
)]
|
||||
pub struct Id(u64);
|
||||
|
||||
impl Id {
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::math::*;
|
|||
|
||||
/// What the integration gives to the gui.
|
||||
/// All coordinates in emigui is in point/logical coordinates.
|
||||
#[derive(Clone, Debug, Default, Deserialize)]
|
||||
#[derive(Clone, Debug, Default, serde_derive::Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct RawInput {
|
||||
/// Is the button currently down?
|
||||
|
@ -84,7 +84,7 @@ pub struct GuiInput {
|
|||
pub events: Vec<Event>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize)]
|
||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde_derive::Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Event {
|
||||
Copy,
|
||||
|
@ -97,7 +97,7 @@ pub enum Event {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize)]
|
||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde_derive::Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Key {
|
||||
Alt,
|
||||
|
|
|
@ -13,7 +13,7 @@ pub enum Layer {
|
|||
Debug,
|
||||
}
|
||||
|
||||
/// Each PaintCmd is paired with a clip rectangle.
|
||||
/// Each `PaintCmd` is paired with a clip rectangle.
|
||||
type PaintList = Vec<(Rect, PaintCmd)>;
|
||||
|
||||
/// TODO: improve this
|
||||
|
|
|
@ -1,10 +1,26 @@
|
|||
#![deny(warnings)]
|
||||
|
||||
extern crate rusttype;
|
||||
extern crate serde;
|
||||
|
||||
#[macro_use] // TODO: get rid of this
|
||||
extern crate serde_derive;
|
||||
#![warn(
|
||||
clippy::all,
|
||||
clippy::dbg_macro,
|
||||
clippy::doc_markdown,
|
||||
clippy::empty_enum,
|
||||
clippy::enum_glob_use,
|
||||
clippy::filter_map_next,
|
||||
clippy::fn_params_excessive_bools,
|
||||
clippy::imprecise_flops,
|
||||
clippy::lossy_float_literal,
|
||||
clippy::mem_forget,
|
||||
clippy::needless_borrow,
|
||||
clippy::needless_continue,
|
||||
clippy::pub_enum_variant_names,
|
||||
clippy::rest_pat_in_fully_bound_structs,
|
||||
// clippy::suboptimal_flops, // TODO
|
||||
clippy::todo,
|
||||
// clippy::use_self,
|
||||
future_incompatible,
|
||||
nonstandard_style,
|
||||
rust_2018_idioms,
|
||||
)]
|
||||
|
||||
pub mod color;
|
||||
pub mod containers;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, RangeInclusive, Sub, SubAssign};
|
||||
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Default, Deserialize, Serialize)]
|
||||
pub struct Vec2 {
|
||||
pub x: f32,
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
Id, Layer, Pos2, Rect,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Default, serde_derive::Deserialize, serde_derive::Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct Memory {
|
||||
/// The widget being interacted with (e.g. dragged, in case of a slider).
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
|||
|
||||
const WHITE_UV: (u16, u16) = (1, 1);
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Serialize)]
|
||||
#[derive(Clone, Copy, Debug, Default, serde_derive::Serialize)]
|
||||
pub struct Vertex {
|
||||
/// Pixel coordinates
|
||||
pub pos: Pos2,
|
||||
|
@ -21,7 +21,7 @@ pub struct Vertex {
|
|||
pub color: Color,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize)]
|
||||
#[derive(Clone, Debug, Default, serde_derive::Serialize)]
|
||||
pub struct Mesh {
|
||||
/// Draw as triangles (i.e. the length is a multiple of three)
|
||||
pub indices: Vec<u32>,
|
||||
|
@ -238,7 +238,7 @@ pub enum PathType {
|
|||
Open,
|
||||
Closed,
|
||||
}
|
||||
use self::PathType::*;
|
||||
use self::PathType::{Closed, Open};
|
||||
|
||||
pub struct MesherOptions {
|
||||
pub anti_alias: bool,
|
||||
|
|
|
@ -50,7 +50,7 @@ where
|
|||
self.flush(now);
|
||||
}
|
||||
|
||||
/// Mean time difference between values in this MovementTracker.
|
||||
/// Mean time difference between values in this `MovementTracker`.
|
||||
pub fn mean_time_interval(&self) -> Option<f32> {
|
||||
if let (Some(first), Some(last)) = (self.values.front(), self.values.back()) {
|
||||
let n = self.len();
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{color::*, containers::*, font::TextFragment, layout::*, widgets::*,
|
|||
|
||||
/// Represents a region of the screen
|
||||
/// with a type of layout (horizontal or vertical).
|
||||
/// TODO: make Region a trait so we can have type-safe HorizontalRegion etc?
|
||||
/// TODO: make Region a trait so we can have type-safe `HorizontalRegion` etc?
|
||||
pub struct Region {
|
||||
/// How we access input, output and memory
|
||||
ctx: Arc<Context>,
|
||||
|
@ -122,11 +122,11 @@ impl Region {
|
|||
self.ctx.input()
|
||||
}
|
||||
|
||||
pub fn memory(&self) -> parking_lot::MutexGuard<Memory> {
|
||||
pub fn memory(&self) -> parking_lot::MutexGuard<'_, Memory> {
|
||||
self.ctx.memory()
|
||||
}
|
||||
|
||||
pub fn output(&self) -> parking_lot::MutexGuard<Output> {
|
||||
pub fn output(&self) -> parking_lot::MutexGuard<'_, Output> {
|
||||
self.ctx.output()
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ impl Region {
|
|||
|
||||
/// Will warn if the returned id is not guaranteed unique.
|
||||
/// Use this to generate widget ids for widgets that have persistent state in Memory.
|
||||
/// If the id_source is not unique within this region
|
||||
/// If the `id_source` is not unique within this region
|
||||
/// then an error will be printed at the current cursor position.
|
||||
pub fn make_unique_id<IdSource>(&self, id_source: &IdSource) -> Id
|
||||
where
|
||||
|
@ -304,7 +304,7 @@ impl Region {
|
|||
/// # How sizes are negotiated
|
||||
/// Each widget should have a *minimum desired size* and a *desired size*.
|
||||
/// When asking for space, ask AT LEAST for you minimum, and don't ask for more than you need.
|
||||
/// If you want to fill the space, ask about available_space() and use that.
|
||||
/// If you want to fill the space, ask about `available_space()` and use that.
|
||||
/// NOTE: we always get the size we ask for (at the moment).
|
||||
pub fn reserve_space(&mut self, child_size: Vec2, interaction_id: Option<Id>) -> InteractInfo {
|
||||
let child_size = self.round_vec_to_pixels(child_size);
|
||||
|
@ -431,7 +431,7 @@ impl Region {
|
|||
/// Show some text anywhere in the region.
|
||||
/// To center the text at the given position, use `align: (Center, Center)`.
|
||||
/// If you want to draw text floating on top of everything,
|
||||
/// consider using Context.floating_text instead.
|
||||
/// consider using `Context.floating_text` instead.
|
||||
pub fn floating_text(
|
||||
&mut self,
|
||||
pos: Pos2,
|
||||
|
@ -584,10 +584,10 @@ impl Region {
|
|||
&mut self,
|
||||
dir: Direction,
|
||||
align: Align,
|
||||
add_contents: impl FnOnce(&mut Region),
|
||||
add_contents: impl FnOnce(&mut Self),
|
||||
) {
|
||||
let child_rect = Rect::from_min_max(self.cursor, self.bottom_right());
|
||||
let mut child_region = Region {
|
||||
let mut child_region = Self {
|
||||
dir,
|
||||
align,
|
||||
..self.child_region(child_rect)
|
||||
|
@ -599,26 +599,28 @@ impl Region {
|
|||
|
||||
/// Temporarily split split a vertical layout into several columns.
|
||||
///
|
||||
/// ``` ignore
|
||||
/// region.columns(2, |columns| {
|
||||
/// columns[0].add(emigui::widgets::label!("First column"));
|
||||
/// columns[1].add(emigui::widgets::label!("Second column"));
|
||||
/// });
|
||||
/// ```
|
||||
pub fn columns<F, R>(&mut self, num_columns: usize, add_contents: F) -> R
|
||||
where
|
||||
F: FnOnce(&mut [Region]) -> R,
|
||||
F: FnOnce(&mut [Self]) -> R,
|
||||
{
|
||||
// TODO: ensure there is space
|
||||
let spacing = self.style.item_spacing.x;
|
||||
let total_spacing = spacing * (num_columns as f32 - 1.0);
|
||||
let column_width = (self.available_width() - total_spacing) / (num_columns as f32);
|
||||
|
||||
let mut columns: Vec<Region> = (0..num_columns)
|
||||
let mut columns: Vec<Self> = (0..num_columns)
|
||||
.map(|col_idx| {
|
||||
let pos = self.cursor + vec2((col_idx as f32) * (column_width + spacing), 0.0);
|
||||
let child_rect =
|
||||
Rect::from_min_max(pos, pos2(pos.x + column_width, self.bottom_right().y));
|
||||
|
||||
Region {
|
||||
Self {
|
||||
id: self.make_child_id(&("column", col_idx)),
|
||||
dir: Direction::Vertical,
|
||||
..self.child_region(child_rect)
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#![allow(clippy::if_same_then_else)]
|
||||
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use crate::{color::*, math::*, types::*};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
pub struct Style {
|
||||
/// Horizontal and vertical padding within a window frame.
|
||||
pub window_padding: Vec2,
|
||||
|
@ -45,14 +47,14 @@ pub struct Style {
|
|||
pub debug_regions: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize)]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
pub struct Window {
|
||||
pub corner_radius: f32,
|
||||
}
|
||||
|
||||
impl Default for Style {
|
||||
fn default() -> Self {
|
||||
Style {
|
||||
Self {
|
||||
window_padding: vec2(6.0, 6.0),
|
||||
button_padding: vec2(5.0, 3.0),
|
||||
item_spacing: vec2(8.0, 4.0),
|
||||
|
@ -72,7 +74,7 @@ impl Default for Style {
|
|||
|
||||
impl Default for Window {
|
||||
fn default() -> Self {
|
||||
Window {
|
||||
Self {
|
||||
corner_radius: 10.0,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ pub struct TextureAtlas {
|
|||
|
||||
impl TextureAtlas {
|
||||
pub fn new(width: usize, height: usize) -> Self {
|
||||
TextureAtlas {
|
||||
Self {
|
||||
texture: Texture {
|
||||
id: 0,
|
||||
width,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use serde_derive::Serialize;
|
||||
|
||||
use crate::{
|
||||
color::Color,
|
||||
fonts::TextStyle,
|
||||
|
@ -30,7 +32,7 @@ pub enum CursorIcon {
|
|||
|
||||
impl Default for CursorIcon {
|
||||
fn default() -> Self {
|
||||
CursorIcon::Default
|
||||
Self::Default
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ pub use {slider::*, text_edit::*};
|
|||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// Anything implementing Widget can be added to a Region with Region::add
|
||||
/// Anything implementing Widget can be added to a Region with `Region::add`
|
||||
pub trait Widget {
|
||||
fn ui(self, region: &mut Region) -> GuiResponse;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ pub struct Label {
|
|||
|
||||
impl Label {
|
||||
pub fn new(text: impl Into<String>) -> Self {
|
||||
Label {
|
||||
Self {
|
||||
text: text.into(),
|
||||
multiline: true,
|
||||
text_style: TextStyle::Body,
|
||||
|
@ -138,7 +138,7 @@ pub struct Button {
|
|||
|
||||
impl Button {
|
||||
pub fn new(text: impl Into<String>) -> Self {
|
||||
Button {
|
||||
Self {
|
||||
text: text.into(),
|
||||
text_color: None,
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ pub struct RadioButton {
|
|||
|
||||
impl RadioButton {
|
||||
pub fn new(checked: bool, text: impl Into<String>) -> Self {
|
||||
RadioButton {
|
||||
Self {
|
||||
checked,
|
||||
text: text.into(),
|
||||
text_color: None,
|
||||
|
@ -328,8 +328,8 @@ pub struct Separator {
|
|||
}
|
||||
|
||||
impl Separator {
|
||||
pub fn new() -> Separator {
|
||||
Separator {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
line_width: 2.0,
|
||||
min_length: 6.0,
|
||||
extra: 0.0,
|
||||
|
|
|
@ -67,12 +67,9 @@ impl<'t> Widget for TextEdit<'t> {
|
|||
}
|
||||
}
|
||||
Event::Key { key, pressed: true } => {
|
||||
match key {
|
||||
Key::Backspace => {
|
||||
if *key == Key::Backspace {
|
||||
self.text.pop(); // TODO: unicode aware
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#![deny(warnings)]
|
||||
|
||||
#![allow(clippy::single_match)]
|
||||
mod painter;
|
||||
|
||||
pub use painter::Painter;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#![deny(warnings)]
|
||||
#[allow(clippy::single_match)]
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use {
|
||||
|
|
Loading…
Reference in a new issue