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)] #[derive(Debug)]
#[allow(non_snake_case)] #[allow(non_snake_case)]
struct WinitView { struct WinitView {
@ -391,7 +391,8 @@ fn frame_did_change(&self, _event: id) {
// Emit resize event here rather than from windowDidResize because: // 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. // 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). // 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()); let size = logical_size.to_physical::<u32>(state.get_scale_factor());
AppState::queue_event(EventWrapper::StaticEvent(Event::WindowEvent { AppState::queue_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: WindowId(get_window_id(state.ns_window)), window_id: WindowId(get_window_id(state.ns_window)),
@ -451,7 +452,6 @@ fn reset_cursor_rects(&self) {
} }
unsafe impl Protocol<NSTextInputClient> for WinitView { unsafe impl Protocol<NSTextInputClient> for WinitView {
#[sel(hasMarkedText)] #[sel(hasMarkedText)]
fn has_marked_text(&self) -> bool { fn has_marked_text(&self) -> bool {
trace_scope!("hasMarkedText"); trace_scope!("hasMarkedText");
@ -599,8 +599,10 @@ fn first_rect_for_character_range(
unsafe { unsafe {
let state_ptr: *mut c_void = *self.ivar("winitState"); let state_ptr: *mut c_void = *self.ivar("winitState");
let state = &mut *(state_ptr as *mut ViewState); let state = &mut *(state_ptr as *mut ViewState);
let content_rect = let content_rect = NSWindow::contentRectForFrameRect_(
NSWindow::contentRectForFrameRect_(state.ns_window, NSWindow::frame(state.ns_window)); state.ns_window,
NSWindow::frame(state.ns_window),
);
let base_x = content_rect.origin.x as f64; let base_x = content_rect.origin.x as f64;
let base_y = (content_rect.origin.y + content_rect.size.height) as f64; let base_y = (content_rect.origin.y + content_rect.size.height) as f64;
let x = base_x + state.ime_position.x; let x = base_x + state.ime_position.x;
@ -665,7 +667,6 @@ fn do_command_by_selector(&self, _command: Sel) {
} }
unsafe impl WinitView { unsafe impl WinitView {
#[sel(keyDown:)] #[sel(keyDown:)]
fn key_down(&self, event: id) { fn key_down(&self, event: id) {
trace_scope!("keyDown:"); trace_scope!("keyDown:");
@ -1020,7 +1021,8 @@ fn scroll_wheel(&self, event: id) {
let delta = { let delta = {
let (x, y) = (event.scrollingDeltaX(), event.scrollingDeltaY()); let (x, y) = (event.scrollingDeltaX(), event.scrollingDeltaY());
if Bool::from_raw(event.hasPreciseScrollingDeltas()).as_bool() { 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) MouseScrollDelta::PixelDelta(delta)
} else { } else {
MouseScrollDelta::LineDelta(x as f32, y as f32) 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 // 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 // phase is recorded (or rather, the started/ended cases of the momentum phase) then we
// report the touch phase. // report the touch phase.
let phase = match event.momentumPhase() { let phase =
match event.momentumPhase() {
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => { NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
TouchPhase::Started TouchPhase::Started
} }
@ -1039,12 +1042,10 @@ fn scroll_wheel(&self, event: id) {
TouchPhase::Ended TouchPhase::Ended
} }
_ => match event.phase() { _ => match event.phase() {
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => { NSEventPhase::NSEventPhaseMayBegin
TouchPhase::Started | NSEventPhase::NSEventPhaseBegan => TouchPhase::Started,
} NSEventPhase::NSEventPhaseEnded
NSEventPhase::NSEventPhaseEnded | NSEventPhase::NSEventPhaseCancelled => { | NSEventPhase::NSEventPhaseCancelled => TouchPhase::Ended,
TouchPhase::Ended
}
_ => TouchPhase::Moved, _ => TouchPhase::Moved,
}, },
}; };
@ -1175,7 +1176,7 @@ fn accepts_first_mouse(&self, _event: id) -> bool {
true true
} }
} }
} );
impl WinitView { impl WinitView {
fn current_input_source(&self) -> String { 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)] #[derive(Debug)]
struct WinitWindowDelegate { struct WinitWindowDelegate {
state: *mut c_void, state: *mut c_void,
@ -258,7 +258,8 @@ fn dragging_entered(&self, sender: id) -> bool {
use std::path::PathBuf; use std::path::PathBuf;
let pb: id = unsafe { msg_send![sender, draggingPasteboard] }; 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() } { for file in unsafe { filenames.iter() } {
use cocoa::foundation::NSString; use cocoa::foundation::NSString;
@ -293,7 +294,8 @@ fn perform_drag_operation(&self, sender: id) -> bool {
use std::path::PathBuf; use std::path::PathBuf;
let pb: id = unsafe { msg_send![sender, draggingPasteboard] }; 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() } { for file in unsafe { filenames.iter() } {
use cocoa::foundation::NSString; use cocoa::foundation::NSString;
@ -322,9 +324,7 @@ fn conclude_drag_operation(&self, _: id) {
#[sel(draggingExited:)] #[sel(draggingExited:)]
fn dragging_exited(&self, _: id) { fn dragging_exited(&self, _: id) {
trace_scope!("draggingExited:"); trace_scope!("draggingExited:");
self.with_state(|state| { self.with_state(|state| state.emit_event(WindowEvent::HoveredFileCancelled));
state.emit_event(WindowEvent::HoveredFileCancelled)
});
} }
/// Invoked when before enter fullscreen /// Invoked when before enter fullscreen
@ -461,7 +461,8 @@ fn window_did_fail_to_enter_fullscreen(&self, _: id) {
trace_scope!("windowDidFailToEnterFullscreen:"); trace_scope!("windowDidFailToEnterFullscreen:");
self.with_state(|state| { self.with_state(|state| {
state.with_window(|window| { 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.in_fullscreen_transition = false;
shared_state.target_fullscreen = None; shared_state.target_fullscreen = None;
}); });
@ -495,7 +496,7 @@ fn window_did_change_occlusion_state(&self, _: id) {
} }
} }
} }
} );
impl WinitWindowDelegate { impl WinitWindowDelegate {
// This function is definitely unsafe (&self -> &mut state), but labeling that // This function is definitely unsafe (&self -> &mut state), but labeling that