Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustfmt: adjust opts and format within macro braces #361

Merged
merged 5 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This may be useful to run occasionally, but has issues:
#format_code_in_doc_comments = true

inline_attribute_width = 60
overflow_delimited_expr = true
single_line_if_else_max_width = 60
use_field_init_shorthand = true
use_try_shorthand = true
6 changes: 2 additions & 4 deletions crates/kas-core/src/core/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@

//! Widget data types

#[allow(unused)]
use super::Layout;
#[allow(unused)] use super::Layout;
use super::{Widget, WidgetId};
use crate::dir::Direction;
use crate::event::EventMgr;
use crate::geom::Rect;

#[cfg(feature = "winit")]
pub use winit::window::Icon;
#[cfg(feature = "winit")] pub use winit::window::Icon;

/// An icon used for the window titlebar, taskbar, etc.
#[cfg(not(feature = "winit"))]
Expand Down
11 changes: 4 additions & 7 deletions crates/kas-core/src/core/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ use crate::util::IdentifyWidget;
use crate::WidgetId;
use kas_macros::autoimpl;

#[allow(unused)]
use crate::event::EventState;
#[allow(unused)] use crate::event::EventState;
#[allow(unused)]
use crate::layout::{self, AlignPair, AutoLayout};
#[allow(unused)]
use crate::TkAction;
#[allow(unused)]
use kas_macros as macros;
#[allow(unused)] use crate::TkAction;
#[allow(unused)] use kas_macros as macros;

/// Base functionality for [`Widget`]s
///
Expand Down Expand Up @@ -309,8 +306,8 @@ pub trait Layout {
/// and [`kas_widgets` code](https://github.com/kas-gui/kas/tree/master/crates/kas-widgets).
/// ```
/// # extern crate kas_core as kas;
/// use kas::prelude::*;
/// use kas::event;
/// use kas::prelude::*;
/// use kas::theme::TextClass;
/// use std::fmt::Debug;
///
Expand Down
16 changes: 6 additions & 10 deletions crates/kas-core/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,12 @@ pub enum Direction {

impl fmt::Display for Direction {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(
f,
"{}",
match self {
Direction::Right => "Right",
Direction::Down => "Down",
Direction::Left => "Left",
Direction::Up => "Up",
}
)
write!(f, "{}", match self {
Direction::Right => "Right",
Direction::Down => "Down",
Direction::Left => "Left",
Direction::Up => "Up",
})
}
}

Expand Down
6 changes: 2 additions & 4 deletions crates/kas-core/src/draw/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
//! Drawing APIs — draw interface

use super::{color::Rgba, AnimationState};
#[allow(unused)]
use super::{DrawRounded, DrawRoundedImpl};
#[allow(unused)] use super::{DrawRounded, DrawRoundedImpl};
use super::{DrawShared, DrawSharedImpl, ImageId, PassId, PassType, SharedState};
use crate::geom::{Offset, Quad, Rect};
#[allow(unused)]
use crate::text::TextApi;
#[allow(unused)] use crate::text::TextApi;
use crate::text::{Effect, TextDisplay};
use std::any::Any;
use std::time::Instant;
Expand Down
6 changes: 2 additions & 4 deletions crates/kas-core/src/draw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@

pub mod color;

#[allow(clippy::module_inception)]
mod draw;
#[allow(clippy::module_inception)] mod draw;
mod draw_rounded;
mod draw_shared;

use crate::cast::Cast;
#[allow(unused)]
use crate::theme::DrawMgr;
#[allow(unused)] use crate::theme::DrawMgr;

pub use draw::{Draw, DrawIface, DrawImpl};
pub use draw_rounded::{DrawRounded, DrawRoundedImpl};
Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/event/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use super::ScrollDelta::{LineDelta, PixelDelta};
use super::{Command, CursorIcon, Event, EventMgr, PressSource, Response, Scroll};
use crate::cast::traits::*;
use crate::geom::{Coord, Offset, Rect, Size, Vec2};
#[allow(unused)]
use crate::text::SelectionHelper;
#[allow(unused)] use crate::text::SelectionHelper;
use crate::{TkAction, WidgetId};
use kas_macros::impl_default;
use std::time::{Duration, Instant};
Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/event/config/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use serde::de::{self, Deserialize, Deserializer, MapAccess, Unexpected, Visitor}
#[cfg(feature = "config")]
use serde::ser::{Serialize, SerializeMap, Serializer};
use std::collections::HashMap;
#[cfg(feature = "config")]
use std::fmt;
#[cfg(feature = "config")] use std::fmt;

/// Shortcut manager
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
5 changes: 2 additions & 3 deletions crates/kas-core/src/event/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use serde::{Deserialize, Serialize};
use super::{EventMgr, EventState, GrabMode, Response}; // for doc-links
use super::{MouseButton, UpdateId, VirtualKeyCode};
use crate::geom::{Coord, DVec2, Offset};
#[allow(unused)]
use crate::Widget;
#[allow(unused)] use crate::Widget;
use crate::{dir::Direction, WidgetId, WindowId};

/// Events addressed to a widget
Expand Down Expand Up @@ -58,7 +57,7 @@ pub enum Event {
/// # use kas_core::cast::{Cast, CastFloat};
/// # use kas_core::geom::{Coord, DVec2};
/// # let (alpha, delta) = (DVec2::ZERO, DVec2::ZERO);
/// let mut p = Coord::ZERO; // or whatever
/// let mut p = Coord::ZERO; // or whatever
/// p = (alpha.complex_mul(p.cast()) + delta).cast_nearest();
/// ```
///
Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/event/manager/config_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use crate::theme::{Feature, SizeMgr, TextClass, ThemeSize};
use crate::{TkAction, Widget, WidgetExt, WidgetId};
use std::ops::{Deref, DerefMut};

#[allow(unused)]
use crate::{event::Event, Layout};
#[allow(unused)] use crate::{event::Event, Layout};

/// Manager used to configure widgets and layout
///
Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/event/manager/mgr_pub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use crate::cast::Conv;
use crate::draw::DrawShared;
use crate::geom::{Coord, Offset, Vec2};
use crate::theme::{SizeMgr, ThemeControl};
#[allow(unused)]
use crate::{Layout, Widget}; // for doc-links
#[allow(unused)] use crate::{Layout, Widget}; // for doc-links
use crate::{TkAction, WidgetId, WindowId};

impl<'a> std::ops::BitOrAssign<TkAction> for EventMgr<'a> {
Expand Down
12 changes: 4 additions & 8 deletions crates/kas-core/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
//! [`Unused`]: Response::Unused

pub mod config;
#[cfg(not(feature = "winit"))]
mod enums;
#[cfg(not(feature = "winit"))] mod enums;
mod events;
mod manager;
mod response;
Expand All @@ -68,13 +67,10 @@ use std::fmt::Debug;

#[cfg(feature = "winit")]
pub use winit::event::{ModifiersState, MouseButton, VirtualKeyCode};
#[cfg(feature = "winit")]
pub use winit::window::CursorIcon;
#[cfg(feature = "winit")] pub use winit::window::CursorIcon;

#[allow(unused)]
use crate::Widget;
#[doc(no_inline)]
pub use config::Config;
#[allow(unused)] use crate::Widget;
#[doc(no_inline)] pub use config::Config;
#[cfg(not(feature = "winit"))]
pub use enums::{CursorIcon, ModifiersState, MouseButton, VirtualKeyCode};
pub use events::*;
Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/layout/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

//! Alignment types

#[allow(unused)]
use super::Stretch; // for doc-links
#[allow(unused)] use super::Stretch; // for doc-links
use crate::dir::Directional;
use crate::geom::{Rect, Size};

Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ use crate::geom::{Coord, Rect};
use crate::theme::{DrawMgr, SizeMgr};
use crate::WidgetId;

#[allow(unused)]
use crate::Layout;
#[allow(unused)] use crate::Layout;

pub use align::{Align, AlignHints, AlignPair};
pub use grid_solver::{DefaultWithLen, GridChildInfo, GridDimensions, GridSetter, GridSolver};
Expand Down
6 changes: 2 additions & 4 deletions crates/kas-core/src/layout/size_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ use crate::dir::Directional;
use crate::geom::Size;

// for doc use
#[allow(unused)]
use super::FrameRules;
#[allow(unused)]
use crate::theme::SizeMgr;
#[allow(unused)] use super::FrameRules;
#[allow(unused)] use crate::theme::SizeMgr;

/// Widget sizing information
///
Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/layout/size_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use crate::theme::MarginStyle;
use kas_macros::impl_scope;

// for doc use
#[allow(unused)]
use crate::theme::SizeMgr;
#[allow(unused)] use crate::theme::SizeMgr;

/// Logical (pre-scaling) pixel size
///
Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

extern crate self as kas;

#[macro_use]
extern crate bitflags;
#[macro_use] extern crate bitflags;

pub extern crate easy_cast as cast;
pub extern crate kas_macros as macros;
Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/model/shared_arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

//! `SharedArc` data type

#[allow(unused)]
use crate::event::Event;
#[allow(unused)] use crate::event::Event;
use crate::event::{EventMgr, UpdateId};
use crate::model::*;
use std::fmt::Debug;
Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/model/shared_rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

//! `SharedRc` data type

#[allow(unused)]
use crate::event::Event;
#[allow(unused)] use crate::event::Event;
use crate::event::{EventMgr, UpdateId};
use crate::model::*;
use std::cell::{Ref, RefCell, RefMut};
Expand Down
18 changes: 6 additions & 12 deletions crates/kas-core/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
//! It is recommended to use `kas::prelude` instead, which is an extension of
//! this crate's prelude.

#[doc(no_inline)]
pub use crate::cast::traits::*;
#[doc(no_inline)]
pub use crate::class::*;
#[doc(no_inline)] pub use crate::cast::traits::*;
#[doc(no_inline)] pub use crate::class::*;
#[doc(no_inline)]
pub use crate::dir::{Direction, Directional};
#[doc(no_inline)]
Expand All @@ -22,16 +20,12 @@ pub use crate::geom::{Coord, Offset, Rect, Size};
pub use crate::layout::{Align, AlignPair, AxisInfo, SizeRules, Stretch};
#[doc(no_inline)]
pub use crate::macros::{autoimpl, impl_default, impl_scope, singleton, widget, widget_index};
#[doc(no_inline)]
pub use crate::text::AccelString;
#[doc(no_inline)] pub use crate::text::AccelString;
#[doc(no_inline)]
pub use crate::text::{EditableTextApi, Text, TextApi, TextApiExt};
#[doc(no_inline)]
pub use crate::theme::{DrawMgr, SizeMgr};
#[doc(no_inline)]
pub use crate::TkAction;
#[doc(no_inline)]
pub use crate::WidgetId;
#[doc(no_inline)] pub use crate::theme::{DrawMgr, SizeMgr};
#[doc(no_inline)] pub use crate::TkAction;
#[doc(no_inline)] pub use crate::WidgetId;
#[doc(no_inline)]
pub use crate::{HasScrollBars, ScrollBarMode, Scrollable};
#[doc(no_inline)]
Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
//!
//! [KAS Text]: https://github.com/kas-gui/kas-text/

#[allow(unused)]
use kas::{event::ConfigMgr, Layout};
#[allow(unused)] use kas::{event::ConfigMgr, Layout};

pub use kas_text::*;

Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ pub use draw::{Background, DrawMgr, ThemeDraw};
pub use size::{SizeMgr, ThemeSize};
pub use style::*;

#[allow(unused)]
use crate::event::EventMgr;
#[allow(unused)] use crate::event::EventMgr;
use crate::TkAction;
use std::ops::{Deref, DerefMut};

Expand Down
3 changes: 1 addition & 2 deletions crates/kas-core/src/theme/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use crate::layout::{AlignPair, AxisInfo, FrameRules, Margins, SizeRules};
use crate::macros::autoimpl;
use crate::text::TextApi;

#[allow(unused)]
use crate::text::TextApiExt;
#[allow(unused)] use crate::text::TextApiExt;
#[allow(unused)]
use crate::{event::ConfigMgr, layout::Stretch, theme::DrawMgr};

Expand Down
3 changes: 1 addition & 2 deletions crates/kas-dylib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#![allow(clippy::single_component_path_imports)]

use kas_core;
#[cfg(feature = "kas-resvg")]
use kas_resvg;
#[cfg(feature = "kas-resvg")] use kas_resvg;
use kas_theme;
use kas_wgpu;
use kas_widgets;
4 changes: 1 addition & 3 deletions crates/kas-macros/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,7 @@ pub fn widget(mut args: WidgetArgs, scope: &mut Scope) -> Result<()> {
set_rect = quote! {
<Self as ::kas::layout::AutoLayout>::set_rect(self, mgr, rect);
};
find_id = quote! {
<Self as ::kas::layout::AutoLayout>::find_id(self, coord)
};
find_id = quote! { <Self as ::kas::layout::AutoLayout>::find_id(self, coord) };
fn_draw = Some(quote! {
fn draw(&mut self, draw: ::kas::theme::DrawMgr) {
<Self as ::kas::layout::AutoLayout>::draw(self, draw);
Expand Down
8 changes: 5 additions & 3 deletions crates/kas-resvg/src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl_scope! {
/// The canvas (re)creates the backing pixmap when the size is set and draws
/// to the new pixmap immediately. If the canvas program is modified then
/// [`Canvas::redraw`] must be called to update the pixmap.
#[derive(Clone, Debug,)]
#[derive(Clone, Debug)]
#[widget]
pub struct Canvas<P: CanvasProgram> {
core: widget_core!(),
Expand Down Expand Up @@ -118,7 +118,8 @@ impl_scope! {
if let Some((pm, h)) = self.pixmap.as_mut().zip(self.image.as_ref()) {
pm.fill(Color::TRANSPARENT);
self.program.draw(pm);
mgr.draw_shared().image_upload(h, pm.data(), ImageFormat::Rgba8);
mgr.draw_shared()
.image_upload(h, pm.data(), ImageFormat::Rgba8);
}
}
}
Expand All @@ -144,7 +145,8 @@ impl_scope! {
program.draw(pm);
let (w, h) = (pm.width(), pm.height());
let handle = mgr.draw_shared().image_alloc((w, h)).unwrap();
mgr.draw_shared().image_upload(&handle, pm.data(), ImageFormat::Rgba8);
mgr.draw_shared()
.image_upload(&handle, pm.data(), ImageFormat::Rgba8);
handle
});
}
Expand Down
6 changes: 2 additions & 4 deletions crates/kas-resvg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ pub extern crate tiny_skia;
mod canvas;
pub use canvas::{Canvas, CanvasProgram};

#[cfg(feature = "svg")]
mod svg;
#[cfg(feature = "svg")]
pub use svg::Svg;
#[cfg(feature = "svg")] mod svg;
#[cfg(feature = "svg")] pub use svg::Svg;
Loading