Skip to content

Commit 2a894c6

Browse files
authored
Run cargo fmt on source files (#106)
* Run cargo fmt on source files * Update with rustfmt.toml * Change rustfmt configuration and run it again
1 parent 9fbfe18 commit 2a894c6

19 files changed

Lines changed: 227 additions & 501 deletions

.rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
fn_args_layout = "Compressed"
2+
use_small_heuristics = "Max"
23
use_field_init_shorthand = true

examples/open_window.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::time::Duration;
22

3-
use rtrb::{RingBuffer, Consumer};
3+
use rtrb::{Consumer, RingBuffer};
44

55
use baseview::{Event, EventStatus, Window, WindowHandler, WindowScalePolicy};
66

77
#[derive(Debug, Clone)]
88
enum Message {
9-
Hello
9+
Hello,
1010
}
1111

1212
struct OpenWindowExample {
@@ -40,18 +40,13 @@ fn main() {
4040

4141
let (mut tx, rx) = RingBuffer::new(128).split();
4242

43-
::std::thread::spawn(move || {
44-
loop {
45-
::std::thread::sleep(Duration::from_secs(5));
43+
::std::thread::spawn(move || loop {
44+
::std::thread::sleep(Duration::from_secs(5));
4645

47-
if let Err(_) = tx.push(Message::Hello) {
48-
println!("Failed sending message");
49-
}
46+
if let Err(_) = tx.push(Message::Hello) {
47+
println!("Failed sending message");
5048
}
5149
});
5250

53-
Window::open_blocking(
54-
window_open_options,
55-
|_| OpenWindowExample { rx }
56-
);
51+
Window::open_blocking(window_open_options, |_| OpenWindowExample { rx });
5752
}

src/event.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use keyboard_types::KeyboardEvent;
22

3-
use crate::{WindowInfo, Point};
4-
3+
use crate::{Point, WindowInfo};
54

65
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
76
pub enum MouseButton {
@@ -83,7 +82,6 @@ pub enum Event {
8382
Window(WindowEvent),
8483
}
8584

86-
8785
/// Return value for [WindowHandler::on_event](`crate::WindowHandler::on_event()`),
8886
/// indicating whether the event was handled by your window or should be passed
8987
/// back to the platform.

src/keyboard.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
2020
use keyboard_types::{Code, Location};
2121

22-
2322
#[cfg(any(target_os = "linux", target_os = "macos"))]
2423
/// Map key code to location.
2524
///
@@ -52,4 +51,4 @@ pub fn code_to_location(code: Code) -> Location {
5251
| Code::NumpadSubtract => Location::Numpad,
5352
_ => Location::Standard,
5453
}
55-
}
54+
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
#[cfg(target_os = "macos")]
2+
mod macos;
13
#[cfg(target_os = "windows")]
24
mod win;
35
#[cfg(target_os = "linux")]
46
mod x11;
5-
#[cfg(target_os = "macos")]
6-
mod macos;
77

88
mod event;
99
mod keyboard;

src/macos/keyboard.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
//! Conversion of platform keyboard event into cross-platform event.
2020
2121
use cocoa::appkit::{NSEvent, NSEventModifierFlags, NSEventType};
22-
use cocoa::foundation::NSString;
2322
use cocoa::base::id;
24-
use keyboard_types::{Code, KeyState, Key, KeyboardEvent, Modifiers};
23+
use cocoa::foundation::NSString;
24+
use keyboard_types::{Code, Key, KeyState, KeyboardEvent, Modifiers};
2525
use objc::{msg_send, sel, sel_impl};
2626

2727
use crate::keyboard::code_to_location;
2828

29-
3029
pub(crate) fn from_nsstring(s: id) -> String {
3130
unsafe {
3231
let slice = std::slice::from_raw_parts(s.UTF8String() as *const _, s.len());
@@ -245,15 +244,13 @@ fn code_to_key(code: Code) -> Option<Key> {
245244
})
246245
}
247246

248-
249247
fn is_valid_key(s: &str) -> bool {
250248
match s.chars().next() {
251249
None => false,
252250
Some(c) => c >= ' ' && c != '\x7f' && !('\u{e000}'..'\u{f900}').contains(&c),
253251
}
254252
}
255253

256-
257254
fn is_modifier_code(code: Code) -> bool {
258255
matches!(
259256
code,
@@ -270,7 +267,6 @@ fn is_modifier_code(code: Code) -> bool {
270267
)
271268
}
272269

273-
274270
impl KeyboardState {
275271
pub(crate) fn new() -> KeyboardState {
276272
let last_mods = NSEventModifierFlags::empty();
@@ -329,33 +325,21 @@ impl KeyboardState {
329325
}
330326
}
331327
};
332-
let event = KeyboardEvent {
333-
code,
334-
key,
335-
location,
336-
modifiers,
337-
state,
338-
is_composing,
339-
repeat,
340-
};
328+
let event =
329+
KeyboardEvent { code, key, location, modifiers, state, is_composing, repeat };
341330
Some(event)
342331
}
343332
}
344333
}
345334

346-
347335
const MODIFIER_MAP: &[(NSEventModifierFlags, Modifiers)] = &[
348336
(NSEventModifierFlags::NSShiftKeyMask, Modifiers::SHIFT),
349337
(NSEventModifierFlags::NSAlternateKeyMask, Modifiers::ALT),
350338
(NSEventModifierFlags::NSControlKeyMask, Modifiers::CONTROL),
351339
(NSEventModifierFlags::NSCommandKeyMask, Modifiers::META),
352-
(
353-
NSEventModifierFlags::NSAlphaShiftKeyMask,
354-
Modifiers::CAPS_LOCK,
355-
),
340+
(NSEventModifierFlags::NSAlphaShiftKeyMask, Modifiers::CAPS_LOCK),
356341
];
357342

358-
359343
pub(crate) fn make_modifiers(raw: NSEventModifierFlags) -> Modifiers {
360344
let mut modifiers = Modifiers::empty();
361345
for &(flags, mods) in MODIFIER_MAP {
@@ -364,4 +348,4 @@ pub(crate) fn make_modifiers(raw: NSEventModifierFlags) -> Modifiers {
364348
}
365349
}
366350
modifiers
367-
}
351+
}

src/macos/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod keyboard;
2-
mod window;
32
mod view;
3+
mod window;
44

55
pub use window::*;

0 commit comments

Comments
 (0)