Fix declare_class! indentation (#2461)

* Fix NSWindow delegate indentation

* Fix NSView delegate indentation
This commit is contained in:
Mads Marquart 2022-09-02 19:38:32 +02:00 committed by GitHub
parent d67c928120
commit e517e468f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1178 additions and 1176 deletions

View file

@ -289,7 +289,7 @@ fn mouse_motion(this: &Object, event: id) {
}
}
declare_class! {
declare_class!(
#[derive(Debug)]
#[allow(non_snake_case)]
struct WinitView {
@ -391,7 +391,8 @@ fn frame_did_change(&self, _event: id) {
// Emit resize event here rather than from windowDidResize because:
// 1. When a new window is created as a tab, the frame size may change without a window resize occurring.
// 2. Even when a window resize does occur on a new tabbed window, it contains the wrong size (includes tab height).
let logical_size = LogicalSize::new(rect.size.width as f64, rect.size.height as f64);
let logical_size =
LogicalSize::new(rect.size.width as f64, rect.size.height as f64);
let size = logical_size.to_physical::<u32>(state.get_scale_factor());
AppState::queue_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: WindowId(get_window_id(state.ns_window)),
@ -451,7 +452,6 @@ fn reset_cursor_rects(&self) {
}
unsafe impl Protocol<NSTextInputClient> for WinitView {
#[sel(hasMarkedText)]
fn has_marked_text(&self) -> bool {
trace_scope!("hasMarkedText");
@ -599,8 +599,10 @@ fn first_rect_for_character_range(
unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState");
let state = &mut *(state_ptr as *mut ViewState);
let content_rect =
NSWindow::contentRectForFrameRect_(state.ns_window, NSWindow::frame(state.ns_window));
let content_rect = NSWindow::contentRectForFrameRect_(
state.ns_window,
NSWindow::frame(state.ns_window),
);
let base_x = content_rect.origin.x as f64;
let base_y = (content_rect.origin.y + content_rect.size.height) as f64;
let x = base_x + state.ime_position.x;
@ -665,7 +667,6 @@ fn do_command_by_selector(&self, _command: Sel) {
}
unsafe impl WinitView {
#[sel(keyDown:)]
fn key_down(&self, event: id) {
trace_scope!("keyDown:");
@ -1020,7 +1021,8 @@ fn scroll_wheel(&self, event: id) {
let delta = {
let (x, y) = (event.scrollingDeltaX(), event.scrollingDeltaY());
if Bool::from_raw(event.hasPreciseScrollingDeltas()).as_bool() {
let delta = LogicalPosition::new(x, y).to_physical(state.get_scale_factor());
let delta =
LogicalPosition::new(x, y).to_physical(state.get_scale_factor());
MouseScrollDelta::PixelDelta(delta)
} else {
MouseScrollDelta::LineDelta(x as f32, y as f32)
@ -1031,7 +1033,8 @@ fn scroll_wheel(&self, event: id) {
// be mutually exclusive anyhow, which is why the API is rather incoherent). If no momentum
// phase is recorded (or rather, the started/ended cases of the momentum phase) then we
// report the touch phase.
let phase = match event.momentumPhase() {
let phase =
match event.momentumPhase() {
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
TouchPhase::Started
}
@ -1039,12 +1042,10 @@ fn scroll_wheel(&self, event: id) {
TouchPhase::Ended
}
_ => match event.phase() {
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
TouchPhase::Started
}
NSEventPhase::NSEventPhaseEnded | NSEventPhase::NSEventPhaseCancelled => {
TouchPhase::Ended
}
NSEventPhase::NSEventPhaseMayBegin
| NSEventPhase::NSEventPhaseBegan => TouchPhase::Started,
NSEventPhase::NSEventPhaseEnded
| NSEventPhase::NSEventPhaseCancelled => TouchPhase::Ended,
_ => TouchPhase::Moved,
},
};
@ -1175,7 +1176,7 @@ fn accepts_first_mouse(&self, _event: id) -> bool {
true
}
}
}
);
impl WinitView {
fn current_input_source(&self) -> String {

View file

@ -128,7 +128,7 @@ pub fn new_delegate(window: &Arc<UnownedWindow>, initial_fullscreen: bool) -> Id
}
}
declare_class! {
declare_class!(
#[derive(Debug)]
struct WinitWindowDelegate {
state: *mut c_void,
@ -258,7 +258,8 @@ fn dragging_entered(&self, sender: id) -> bool {
use std::path::PathBuf;
let pb: id = unsafe { msg_send![sender, draggingPasteboard] };
let filenames = unsafe { NSPasteboard::propertyListForType(pb, appkit::NSFilenamesPboardType) };
let filenames =
unsafe { NSPasteboard::propertyListForType(pb, appkit::NSFilenamesPboardType) };
for file in unsafe { filenames.iter() } {
use cocoa::foundation::NSString;
@ -293,7 +294,8 @@ fn perform_drag_operation(&self, sender: id) -> bool {
use std::path::PathBuf;
let pb: id = unsafe { msg_send![sender, draggingPasteboard] };
let filenames = unsafe { NSPasteboard::propertyListForType(pb, appkit::NSFilenamesPboardType) };
let filenames =
unsafe { NSPasteboard::propertyListForType(pb, appkit::NSFilenamesPboardType) };
for file in unsafe { filenames.iter() } {
use cocoa::foundation::NSString;
@ -322,9 +324,7 @@ fn conclude_drag_operation(&self, _: id) {
#[sel(draggingExited:)]
fn dragging_exited(&self, _: id) {
trace_scope!("draggingExited:");
self.with_state(|state| {
state.emit_event(WindowEvent::HoveredFileCancelled)
});
self.with_state(|state| state.emit_event(WindowEvent::HoveredFileCancelled));
}
/// Invoked when before enter fullscreen
@ -461,7 +461,8 @@ fn window_did_fail_to_enter_fullscreen(&self, _: id) {
trace_scope!("windowDidFailToEnterFullscreen:");
self.with_state(|state| {
state.with_window(|window| {
let mut shared_state = window.lock_shared_state("window_did_fail_to_enter_fullscreen");
let mut shared_state =
window.lock_shared_state("window_did_fail_to_enter_fullscreen");
shared_state.in_fullscreen_transition = false;
shared_state.target_fullscreen = None;
});
@ -495,7 +496,7 @@ fn window_did_change_occlusion_state(&self, _: id) {
}
}
}
}
);
impl WinitWindowDelegate {
// This function is definitely unsafe (&self -> &mut state), but labeling that