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

style: simplify string formatting for readability #987

Merged
merged 2 commits into from
Oct 11, 2024
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
10 changes: 5 additions & 5 deletions examples/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() {

event_loop.run(move |event, _, control_flow| {
use tao::event::StartCause;
println!("{:?}", event);
println!("{event:?}");
match event {
Event::NewEvents(start_cause) => {
wait_cancelled = match start_cause {
Expand All @@ -69,19 +69,19 @@ fn main() {
// See the `key_binding` example
if Key::Character("1") == logical_key {
mode = Mode::Wait;
println!("\nmode: {:?}\n", mode);
println!("\nmode: {mode:?}\n");
}
if Key::Character("2") == logical_key {
mode = Mode::WaitUntil;
println!("\nmode: {:?}\n", mode);
println!("\nmode: {mode:?}\n");
}
if Key::Character("3") == logical_key {
mode = Mode::Poll;
println!("\nmode: {:?}\n", mode);
println!("\nmode: {mode:?}\n");
}
if Key::Character("r") == logical_key {
request_redraw = !request_redraw;
println!("\nrequest_redraw: {}\n", request_redraw);
println!("\nrequest_redraw: {request_redraw}\n");
}
if Key::Escape == logical_key {
close_requested = true;
Expand Down
6 changes: 3 additions & 3 deletions examples/cursor_grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ fn main() {
_ => (),
},
Event::DeviceEvent { event, .. } => match event {
DeviceEvent::MouseMotion { delta, .. } => println!("mouse moved: {:?}", delta),
DeviceEvent::MouseMotion { delta, .. } => println!("mouse moved: {delta:?}"),
DeviceEvent::Button { button, state, .. } => match state {
ElementState::Pressed => println!("mouse button {} pressed", button),
ElementState::Released => println!("mouse button {} released", button),
ElementState::Pressed => println!("mouse button {button} pressed"),
ElementState::Released => println!("mouse button {button} released"),
_ => (),
},
_ => (),
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() {
*control_flow = ControlFlow::Wait;

match event {
Event::UserEvent(event) => println!("user event: {:?}", event),
Event::UserEvent(event) => println!("user event: {event:?}"),
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
Expand Down
2 changes: 1 addition & 1 deletion examples/decorations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() {
..
} => {
decorations = !decorations;
println!("Decorations: {}", decorations);
println!("Decorations: {decorations}");
window.set_decorations(decorations);
}
_ => (),
Expand Down
4 changes: 2 additions & 2 deletions examples/fullscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn prompt_for_monitor(event_loop: &EventLoop<()>) -> MonitorHandle {

fn prompt_for_video_mode(monitor: &MonitorHandle) -> VideoMode {
for (i, video_mode) in monitor.video_modes().enumerate() {
println!("Video mode #{}: {}", i, video_mode);
println!("Video mode #{i}: {video_mode}");
}

print!("Please write the number of the video mode to use: ");
Expand All @@ -123,7 +123,7 @@ fn prompt_for_video_mode(monitor: &MonitorHandle) -> VideoMode {
.nth(num)
.expect("Please enter a valid ID");

println!("Using {}", video_mode);
println!("Using {video_mode}");

video_mode
}
2 changes: 1 addition & 1 deletion examples/mouse_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {
Event::DeviceEvent { event, .. } => match event {
DeviceEvent::MouseWheel { delta, .. } => match delta {
tao::event::MouseScrollDelta::LineDelta(x, y) => {
println!("mouse wheel Line Delta: ({},{})", x, y);
println!("mouse wheel Line Delta: ({x},{y})");
let pixels_per_line = 120.0;
let mut pos = window.outer_position().unwrap();
pos.x -= (x * pixels_per_line) as i32;
Expand Down
2 changes: 1 addition & 1 deletion examples/multithreaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn main() {
..
} => {
use Key::{ArrowLeft, ArrowRight, Character};
window.set_title(&format!("{:?}", key));
window.set_title(&format!("{key:?}"));
let state = !modifiers.shift_key();
match &key {
// WARNING: Consider using `key_without_modifers()` if available on your platform.
Expand Down
2 changes: 1 addition & 1 deletion examples/multiwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
{
match event {
WindowEvent::CloseRequested => {
println!("Window {:?} has received the signal to close", window_id);
println!("Window {window_id:?} has received the signal to close");

// This drops the window, causing it to close.
windows.remove(&window_id);
Expand Down
2 changes: 1 addition & 1 deletion examples/parentwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn main() {
Event::WindowEvent {
event, window_id, ..
} if event == WindowEvent::CloseRequested => {
println!("Window {:?} has received the signal to close", window_id);
println!("Window {window_id:?} has received the signal to close");
// This drop the window, causing it to close.
windows.remove(&window_id);
if windows.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion examples/request_redraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
.unwrap();

event_loop.run(move |event, _, control_flow| {
println!("{:?}", event);
println!("{event:?}");

*control_flow = ControlFlow::Wait;

Expand Down
2 changes: 1 addition & 1 deletion examples/request_redraw_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() {
});

event_loop.run(move |event, _, control_flow| {
println!("{:?}", event);
println!("{event:?}");

*control_flow = ControlFlow::Wait;

Expand Down
2 changes: 1 addition & 1 deletion examples/resizable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() {
..
} => {
resizable = !resizable;
println!("Resizable: {}", resizable);
println!("Resizable: {resizable}");
window.set_resizable(resizable);
}
_ => (),
Expand Down
2 changes: 1 addition & 1 deletion examples/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {
let timer_length = Duration::new(1, 0);

event_loop.run(move |event, _, control_flow| {
println!("{:?}", event);
println!("{event:?}");

match event {
Event::NewEvents(StartCause::Init) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn main() {

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
println!("{:?}", event);
println!("{event:?}");

match event {
Event::WindowEvent {
Expand Down
2 changes: 1 addition & 1 deletion examples/video_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ fn main() {
println!("Listing available video modes:");

for mode in monitor.video_modes() {
println!("{}", mode);
println!("{mode}");
}
}
2 changes: 1 addition & 1 deletion examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
println!("{:?}", event);
println!("{event:?}");

match event {
Event::WindowEvent {
Expand Down
2 changes: 1 addition & 1 deletion examples/window_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn main() {
"r" => {
resizable = !resizable;
window.set_resizable(resizable);
println!("Resizable: {}", resizable);
println!("Resizable: {resizable}");
}
"m" => {
window.set_minimized(!window.is_minimized());
Expand Down
14 changes: 5 additions & 9 deletions src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,29 @@ impl fmt::Display for BadIcon {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BadIcon::ByteCountNotDivisibleBy4 { byte_count } => write!(f,
"The length of the `rgba` argument ({:?}) isn't divisible by 4, making it impossible to interpret as 32bpp RGBA pixels.",
byte_count,
"The length of the `rgba` argument ({byte_count:?}) isn't divisible by 4, making it impossible to interpret as 32bpp RGBA pixels.",
),
BadIcon::DimensionsVsPixelCount {
width,
height,
width_x_height,
pixel_count,
} => write!(f,
"The specified dimensions ({:?}x{:?}) don't match the number of pixels supplied by the `rgba` argument ({:?}). For those dimensions, the expected pixel count is {:?}.",
width, height, pixel_count, width_x_height,
"The specified dimensions ({width:?}x{height:?}) don't match the number of pixels supplied by the `rgba` argument ({pixel_count:?}). For those dimensions, the expected pixel count is {width_x_height:?}.",
),
BadIcon::DimensionsZero {
width,
height,
} => write!(f,
"The specified dimensions ({:?}x{:?}) must be greater than zero.",
width, height
"The specified dimensions ({width:?}x{height:?}) must be greater than zero."
),
BadIcon::DimensionsMultiplyOverflow {
width,
height,
} => write!(f,
"The specified dimensions multiplication has overflowed ({:?}x{:?}).",
width, height
"The specified dimensions multiplication has overflowed ({width:?}x{height:?})."
),
BadIcon::OsError(e) => write!(f, "OS error when instantiating the icon: {:?}", e),
BadIcon::OsError(e) => write!(f, "OS error when instantiating the icon: {e:?}"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ impl fmt::Display for KeyCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
&KeyCode::Unidentified(_) => write!(f, "{:?}", "Unidentified"),
val => write!(f, "{:?}", val),
val => write!(f, "{val:?}"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pub mod prelude {
pub use crate::platform_impl::ndk_glue::*;
pub use tao_macros::{android_fn, generate_package_name};
}
use crate::platform_impl::ndk_glue::Rect;
use crate::{
event_loop::{EventLoop, EventLoopWindowTarget},
platform_impl::ndk_glue::Rect,
window::{Window, WindowBuilder},
};
use ndk::configuration::Configuration;
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/android/ndk_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ macro_rules! android_binding {
::tao::android_binding!($domain, $package, $activity, $setup, $main, ::tao)
};
($domain:ident, $package:ident, $activity:ident, $setup:path, $main:ident, $tao:path) => {{
use $tao::{platform::android::prelude::android_fn, platform::android::prelude::*};
use $tao::platform::android::prelude::{android_fn, *};
fn _____tao_store_package_name__() {
PACKAGE.get_or_init(move || generate_package_name!($domain, $package));
}
Expand Down
3 changes: 1 addition & 2 deletions src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,8 +1124,7 @@ fn assert_is_main_thread(suggested_method: &str) {
is_main_thread(),
"Initializing the event loop outside of the main thread is a significant \
cross-platform compatibility hazard. If you really, absolutely need to create an \
EventLoop on a different thread, please use the `EventLoopExtUnix::{}` function.",
suggested_method
EventLoop on a different thread, please use the `EventLoopExtUnix::{suggested_method}` function."
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub(crate) fn make_key_event(
});
} else {
#[cfg(debug_assertions)]
eprintln!("Couldn't get key from code: {:?}", physical_key);
eprintln!("Couldn't get key from code: {physical_key:?}");
}
None
}
Expand Down
13 changes: 6 additions & 7 deletions src/platform_impl/linux/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ use crate::{
error::ExternalError,
window::WindowSizeConstraints,
};
use gtk::gdk::{
self,
prelude::{DeviceExt, SeatExt},
Display,
};
use gtk::{
gdk::{
self,
prelude::{DeviceExt, SeatExt},
Display,
},
glib::{self},
traits::{GtkWindowExt, WidgetExt},
};
use std::cell::RefCell;
use std::rc::Rc;
use std::{cell::RefCell, rc::Rc};

#[inline]
pub fn cursor_position(is_wayland: bool) -> Result<PhysicalPosition<f64>, ExternalError> {
Expand Down
3 changes: 2 additions & 1 deletion src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use std::{
use gtk::{
gdk::WindowState,
glib::{self, translate::ToGlibPtr},
prelude::*,
Settings,
};
use gtk::{prelude::*, Settings};

use crate::{
dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size},
Expand Down
18 changes: 10 additions & 8 deletions src/platform_impl/macos/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ use crate::{
event::Event,
event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootWindowTarget},
monitor::MonitorHandle as RootMonitorHandle,
platform_impl::platform::{
app::APP_CLASS,
app_delegate::APP_DELEGATE_CLASS,
app_state::AppState,
monitor::{self, MonitorHandle},
observer::*,
util::{self, IdRef},
platform_impl::{
platform::{
app::APP_CLASS,
app_delegate::APP_DELEGATE_CLASS,
app_state::AppState,
monitor::{self, MonitorHandle},
observer::*,
util::{self, IdRef},
},
set_progress_indicator,
},
platform_impl::set_progress_indicator,
window::{ProgressBarState, Theme},
};

Expand Down
6 changes: 4 additions & 2 deletions src/platform_impl/macos/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ use cocoa::{
foundation::{NSAutoreleasePool, NSPoint, NSRect, NSString, NSUInteger},
};
use core_graphics::display::CGDisplay;
use objc::class;
use objc::runtime::{Class, Object, Sel, BOOL, YES};
use objc::{
class,
runtime::{Class, Object, Sel, BOOL, YES},
};

use crate::{
dpi::{LogicalPosition, PhysicalPosition},
Expand Down
20 changes: 11 additions & 9 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ use crate::{
icon::Icon,
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
platform::macos::WindowExtMacOS,
platform_impl::platform::{
app_state::AppState,
ffi,
monitor::{self, MonitorHandle, VideoMode},
util::{self, IdRef},
view::{self, new_view, CursorState},
window_delegate::new_delegate,
OsError,
platform_impl::{
platform::{
app_state::AppState,
ffi,
monitor::{self, MonitorHandle, VideoMode},
util::{self, IdRef},
view::{self, new_view, CursorState},
window_delegate::new_delegate,
OsError,
},
set_progress_indicator,
},
platform_impl::set_progress_indicator,
window::{
CursorIcon, Fullscreen, ProgressBarState, ResizeDirection, Theme, UserAttentionType,
WindowAttributes, WindowId as RootWindowId, WindowSizeConstraints,
Expand Down
Loading