fix: 'static lifetime elision for examples

Takes advantage of lifetime elision on some examples where the
rule applies.

Refer: https://doc.rust-lang.org/reference/lifetime-elision.html#static-lifetime-elision
This commit is contained in:
Esteban Borai 2022-08-25 22:13:36 -04:00
parent e91e4217cb
commit 399600d443
129 changed files with 942 additions and 843 deletions

View file

@ -15,7 +15,7 @@ use cacao::appkit::{AnimationContext, App, AppDelegate};
use cacao::appkit::{Event, EventMask, EventMonitor};
struct BasicApp {
window: Window<AppWindow>
window: Window<AppWindow>,
}
impl AppDelegate for BasicApp {
@ -54,22 +54,22 @@ const ANIMATIONS: [[[f64; 5]; 4]; 3] = [
[44., 16., 100., 100., 1.],
[128., 84., 144., 124., 1.],
[32., 32., 44., 44., 0.7],
[328., 157., 200., 200., 0.7]
[328., 157., 200., 200., 0.7],
],
// Red
[
[44., 132., 100., 100., 1.],
[40., 47., 80., 64., 0.7],
[84., 220., 600., 109., 1.0],
[48., 600., 340., 44., 0.7]
[48., 600., 340., 44., 0.7],
],
// Green
[
[44., 248., 100., 100., 1.],
[420., 232., 420., 244., 0.7],
[310., 440., 150., 238., 0.7],
[32., 32., 44., 44., 1.]
]
[32., 32., 44., 44., 1.],
],
];
/// A helper method for generating frame constraints that we want to be animating.
@ -84,7 +84,7 @@ fn apply_styles(view: &View, parent: &View, background_color: Color, animation_t
view.top.constraint_equal_to(&parent.top).offset(animation[0]),
view.left.constraint_equal_to(&parent.left).offset(animation[1]),
view.width.constraint_equal_to_constant(animation[2]),
view.height.constraint_equal_to_constant(animation[3])
view.height.constraint_equal_to_constant(animation[3]),
]
}
@ -94,7 +94,7 @@ struct AppWindow {
blue: View,
red: View,
green: View,
key_monitor: Option<EventMonitor>
key_monitor: Option<EventMonitor>,
}
impl WindowDelegate for AppWindow {
@ -139,7 +139,7 @@ impl WindowDelegate for AppWindow {
"a" => 1,
"s" => 2,
"d" => 3,
_ => 4
_ => 4,
};
if animation_index == 4 {
@ -170,8 +170,11 @@ impl WindowDelegate for AppWindow {
}
fn main() {
App::new("com.test.window", BasicApp {
window: Window::with(WindowConfig::default(), AppWindow::default())
})
App::new(
"com.test.window",
BasicApp {
window: Window::with(WindowConfig::default(), AppWindow::default()),
},
)
.run();
}

View file

@ -10,13 +10,15 @@ use cacao::appkit::window::{Window, WindowConfig, WindowDelegate};
use cacao::appkit::{App, AppDelegate};
struct BasicApp {
window: Window<AppWindow>
window: Window<AppWindow>,
}
impl AppDelegate for BasicApp {
fn did_finish_launching(&self) {
App::set_menu(vec![
Menu::new("", vec![
Menu::new(
"",
vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
@ -24,15 +26,19 @@ impl AppDelegate for BasicApp {
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
]),
],
),
Menu::new("File", vec![MenuItem::CloseWindow]),
Menu::new("View", vec![MenuItem::EnterFullScreen]),
Menu::new("Window", vec![
Menu::new(
"Window",
vec![
MenuItem::Minimize,
MenuItem::Zoom,
MenuItem::Separator,
MenuItem::new("Bring All to Front"),
]),
],
),
]);
App::activate();
@ -50,7 +56,7 @@ struct AppWindow {
content: View,
blue: View,
red: View,
green: View
green: View,
}
impl WindowDelegate for AppWindow {
@ -62,7 +68,7 @@ impl WindowDelegate for AppWindow {
let dynamic = Color::dynamic(|style| match (style.theme, style.contrast) {
(Theme::Dark, _) => Color::SystemGreen,
_ => Color::SystemRed
_ => Color::SystemRed,
});
self.blue.set_background_color(Color::SystemBlue);
@ -89,14 +95,17 @@ impl WindowDelegate for AppWindow {
self.green.leading.constraint_equal_to(&self.red.trailing).offset(16.),
self.green.trailing.constraint_equal_to(&self.content.trailing).offset(-16.),
self.green.bottom.constraint_equal_to(&self.content.bottom).offset(-16.),
self.green.width.constraint_equal_to_constant(100.)
self.green.width.constraint_equal_to_constant(100.),
]);
}
}
fn main() {
App::new("com.test.window", BasicApp {
window: Window::with(WindowConfig::default(), AppWindow::default())
})
App::new(
"com.test.window",
BasicApp {
window: Window::with(WindowConfig::default(), AppWindow::default()),
},
)
.run();
}

View file

@ -16,7 +16,7 @@ use toolbar::BrowserToolbar;
pub enum Action {
Back,
Forwards,
Load(String)
Load(String),
}
impl Action {
@ -26,13 +26,15 @@ impl Action {
}
struct BasicApp {
window: Window<AppWindow>
window: Window<AppWindow>,
}
impl AppDelegate for BasicApp {
fn did_finish_launching(&self) {
App::set_menu(vec![
Menu::new("", vec![
Menu::new(
"",
vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
@ -40,9 +42,12 @@ impl AppDelegate for BasicApp {
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
]),
],
),
Menu::new("File", vec![MenuItem::CloseWindow]),
Menu::new("Edit", vec![
Menu::new(
"Edit",
vec![
MenuItem::Undo,
MenuItem::Redo,
MenuItem::Separator,
@ -51,14 +56,18 @@ impl AppDelegate for BasicApp {
MenuItem::Paste,
MenuItem::Separator,
MenuItem::SelectAll,
]),
],
),
Menu::new("View", vec![MenuItem::EnterFullScreen]),
Menu::new("Window", vec![
Menu::new(
"Window",
vec![
MenuItem::Minimize,
MenuItem::Zoom,
MenuItem::Separator,
MenuItem::new("Bring All to Front"),
]),
],
),
Menu::new("Help", vec![]),
]);
@ -83,7 +92,7 @@ impl Dispatcher for BasicApp {
},
Action::Load(url) => {
window.load_url(&url);
}
},
}
}
}
@ -95,14 +104,14 @@ impl WebViewDelegate for WebViewInstance {}
struct AppWindow {
toolbar: Toolbar<BrowserToolbar>,
content: WebView<WebViewInstance>
content: WebView<WebViewInstance>,
}
impl AppWindow {
pub fn new() -> Self {
AppWindow {
toolbar: Toolbar::new("com.example.BrowserToolbar", BrowserToolbar::new()),
content: WebView::with(WebViewConfig::default(), WebViewInstance::default())
content: WebView::with(WebViewConfig::default(), WebViewInstance::default()),
}
}
@ -128,7 +137,9 @@ impl WindowDelegate for AppWindow {
}
fn main() {
App::new("com.test.window", BasicApp {
App::new(
"com.test.window",
BasicApp {
window: Window::with(
{
let mut config = WindowConfig::default();
@ -138,8 +149,9 @@ fn main() {
config
},
AppWindow::new()
AppWindow::new(),
),
},
)
})
.run();
}

View file

@ -7,9 +7,9 @@ use cacao::appkit::toolbar::{ItemIdentifier, Toolbar, ToolbarDelegate, ToolbarDi
use super::Action;
const BACK_BUTTON: &'static str = "BackButton";
const FWDS_BUTTON: &'static str = "FwdsButton";
const URL_BAR: &'static str = "URLBar";
const BACK_BUTTON: &str = "BackButton";
const FWDS_BUTTON: &str = "FwdsButton";
const URL_BAR: &str = "URLBar";
#[derive(Debug)]
pub struct URLBar;
@ -27,7 +27,7 @@ pub struct BrowserToolbar {
back_item: ToolbarItem,
forwards_item: ToolbarItem,
url_bar: TextField<URLBar>,
url_bar_item: ToolbarItem
url_bar_item: ToolbarItem,
}
impl BrowserToolbar {
@ -59,7 +59,7 @@ impl BrowserToolbar {
back_item,
forwards_item,
url_bar,
url_bar_item
url_bar_item,
}
}
@ -100,7 +100,7 @@ impl ToolbarDelegate for BrowserToolbar {
URL_BAR => &self.url_bar_item,
_ => {
std::unreachable!();
}
},
}
}
}

View file

@ -8,7 +8,7 @@ use crate::content_view::{button, BUTTON_HEIGHT, BUTTON_WIDTH};
pub struct ButtonRow {
pub view: View,
pub buttons: Vec<Button>
pub buttons: Vec<Button>,
}
impl ButtonRow {
@ -36,9 +36,9 @@ impl ButtonRow {
Msg::Push(i) if *i == 7 => "7",
Msg::Push(i) if *i == 8 => "8",
Msg::Push(i) if *i == 9 => "9",
_ => "W"
_ => "W",
},
y.clone()
y.clone(),
);
view.add_subview(&button);
@ -71,7 +71,7 @@ impl ButtonRow {
buttons[3].trailing.constraint_equal_to(&view.trailing),
buttons[3].bottom.constraint_equal_to(&view.bottom),
buttons[3].width.constraint_equal_to(&width),
view.height.constraint_equal_to_constant(BUTTON_HEIGHT)
view.height.constraint_equal_to_constant(BUTTON_HEIGHT),
]);
Self { view, buttons }

View file

@ -16,7 +16,7 @@ pub enum Msg {
Clear,
Mod,
Invert,
Equals
Equals,
}
/// Asynchronously calls back through to the top of the application
@ -97,11 +97,11 @@ impl Calculator {
},
Err(e) => {
eprintln!("Error parsing expression: {:?}", e);
}
},
}
},
_ => {}
_ => {},
}
}
}

View file

@ -35,7 +35,7 @@ pub struct CalculatorView {
pub row3: ButtonRow,
pub dot: Button,
pub zero: Button,
pub equals: Button
pub equals: Button,
}
impl CalculatorView {
@ -56,30 +56,30 @@ impl CalculatorView {
row0: ButtonRow::new(
[Msg::Clear, Msg::Invert, Msg::Mod, Msg::Divide],
Color::rgb(69, 69, 69),
Color::rgb(255, 148, 10)
Color::rgb(255, 148, 10),
),
row1: ButtonRow::new(
[Msg::Push(7), Msg::Push(8), Msg::Push(9), Msg::Multiply],
Color::rgb(100, 100, 100),
Color::rgb(255, 148, 10)
Color::rgb(255, 148, 10),
),
row2: ButtonRow::new(
[Msg::Push(4), Msg::Push(5), Msg::Push(6), Msg::Subtract],
Color::rgb(100, 100, 100),
Color::rgb(255, 148, 10)
Color::rgb(255, 148, 10),
),
row3: ButtonRow::new(
[Msg::Push(1), Msg::Push(2), Msg::Push(3), Msg::Add],
Color::rgb(100, 100, 100),
Color::rgb(255, 148, 10)
Color::rgb(255, 148, 10),
),
zero: button("0", Msg::Push(0)),
dot: button(".", Msg::Decimal),
equals: button("=", Msg::Equals)
equals: button("=", Msg::Equals),
}
}
@ -158,7 +158,7 @@ impl ViewDelegate for CalculatorView {
self.equals.trailing.constraint_equal_to(&view.trailing),
self.equals.bottom.constraint_equal_to(&view.bottom),
self.equals.width.constraint_equal_to_constant(BUTTON_WIDTH),
self.equals.height.constraint_equal_to_constant(BUTTON_HEIGHT)
self.equals.height.constraint_equal_to_constant(BUTTON_HEIGHT),
])
}
}

View file

@ -27,7 +27,7 @@ use content_view::CalculatorView;
struct CalculatorApp {
window: Window,
content: View<CalculatorView>,
key_monitor: RwLock<Option<EventMonitor>>
key_monitor: RwLock<Option<EventMonitor>>,
}
impl AppDelegate for CalculatorApp {
@ -105,10 +105,13 @@ fn main() {
let mut config = WindowConfig::default();
config.set_initial_dimensions(100., 100., 240., 300.);
App::new("com.example.calculator", CalculatorApp {
App::new(
"com.example.calculator",
CalculatorApp {
window: Window::new(config),
content: View::with(CalculatorView::new()),
key_monitor: RwLock::new(None)
})
key_monitor: RwLock::new(None),
},
)
.run();
}

View file

@ -15,7 +15,7 @@ struct BasicApp {
window: Window,
content_view: View,
image_view: ImageView,
image: Image
image: Image,
}
impl Default for BasicApp {
@ -23,7 +23,7 @@ impl Default for BasicApp {
let config = DrawConfig {
source: (100., 100.),
target: (800., 800.),
resize: cacao::image::ResizeBehavior::Stretch
resize: cacao::image::ResizeBehavior::Stretch,
};
Self {
@ -91,14 +91,16 @@ impl Default for BasicApp {
context.fill_path();
true
})
}),
}
}
}
impl AppDelegate for BasicApp {
fn did_finish_launching(&self) {
App::set_menu(vec![Menu::new("", vec![
App::set_menu(vec![Menu::new(
"",
vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
@ -106,7 +108,8 @@ impl AppDelegate for BasicApp {
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
])]);
],
)]);
App::activate();
self.window.set_title("Hello World!");
@ -119,7 +122,7 @@ impl AppDelegate for BasicApp {
self.image_view.top.constraint_equal_to(&self.content_view.top),
self.image_view.leading.constraint_equal_to(&self.content_view.leading),
self.image_view.trailing.constraint_equal_to(&self.content_view.trailing),
self.image_view.bottom.constraint_equal_to(&self.content_view.bottom)
self.image_view.bottom.constraint_equal_to(&self.content_view.bottom),
]);
self.window.set_content_view(&self.content_view);

View file

@ -43,7 +43,7 @@ impl AppDelegate for DefaultsTest {
Err(e) => {
eprintln!("Error converting bytes {}", e);
"Error converting bytes"
}
},
};
assert_eq!(s, "BYTES TEST");

View file

@ -17,13 +17,15 @@ const WIDTH: f64 = 100.;
const HEIGHT: f64 = 100.;
struct BasicApp {
window: Window<AppWindow>
window: Window<AppWindow>,
}
impl AppDelegate for BasicApp {
fn did_finish_launching(&self) {
App::set_menu(vec![
Menu::new("", vec![
Menu::new(
"",
vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
@ -31,15 +33,19 @@ impl AppDelegate for BasicApp {
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
]),
],
),
Menu::new("File", vec![MenuItem::CloseWindow]),
Menu::new("View", vec![MenuItem::EnterFullScreen]),
Menu::new("Window", vec![
Menu::new(
"Window",
vec![
MenuItem::Minimize,
MenuItem::Zoom,
MenuItem::Separator,
MenuItem::new("Bring All to Front"),
]),
],
),
]);
App::activate();
@ -58,7 +64,7 @@ struct AppWindow {
content: View,
blue: View,
red: View,
green: View
green: View,
}
impl AppWindow {
@ -68,7 +74,7 @@ impl AppWindow {
top: TOP,
left: SPACING,
width: WIDTH,
height: HEIGHT
height: HEIGHT,
});
self.blue.layer.set_corner_radius(CORNER_RADIUS);
self.content.add_subview(&self.blue);
@ -78,7 +84,7 @@ impl AppWindow {
top: TOP,
left: WIDTH + (SPACING * 2.),
width: WIDTH,
height: HEIGHT
height: HEIGHT,
});
self.red.layer.set_corner_radius(CORNER_RADIUS);
self.content.add_subview(&self.red);
@ -88,7 +94,7 @@ impl AppWindow {
top: TOP,
left: (WIDTH * 2.) + (SPACING * 3.),
width: WIDTH,
height: HEIGHT
height: HEIGHT,
});
self.green.layer.set_corner_radius(CORNER_RADIUS);
self.content.add_subview(&self.green);
@ -106,8 +112,11 @@ impl WindowDelegate for AppWindow {
}
fn main() {
App::new("com.test.window", BasicApp {
window: Window::with(WindowConfig::default(), AppWindow::default())
})
App::new(
"com.test.window",
BasicApp {
window: Window::with(WindowConfig::default(), AppWindow::default()),
},
)
.run();
}

View file

@ -21,7 +21,7 @@ pub struct RootView {
pub red: View,
pub green: View,
pub blue: View,
pub image: ImageView
pub image: ImageView,
}
impl ViewDelegate for RootView {
@ -55,7 +55,7 @@ impl ViewDelegate for RootView {
self.blue.top.constraint_equal_to(&self.green.bottom).offset(16.),
self.blue.leading.constraint_equal_to(&view.leading).offset(16.),
self.blue.trailing.constraint_equal_to(&view.trailing).offset(-16.),
self.blue.bottom.constraint_equal_to(&view.bottom).offset(-16.)
self.blue.bottom.constraint_equal_to(&view.bottom).offset(-16.),
]);
}
}
@ -63,7 +63,7 @@ impl ViewDelegate for RootView {
#[derive(Default)]
pub struct WindowScene {
pub window: RwLock<Option<Window>>,
pub root_view_controller: RwLock<Option<ViewController<RootView>>>
pub root_view_controller: RwLock<Option<ViewController<RootView>>>,
}
impl WindowSceneDelegate for WindowScene {

View file

@ -10,13 +10,15 @@ use cacao::appkit::window::{Window, WindowConfig, WindowDelegate};
use cacao::appkit::{App, AppDelegate};
struct BasicApp {
window: Window<AppWindow>
window: Window<AppWindow>,
}
impl AppDelegate for BasicApp {
fn did_finish_launching(&self) {
App::set_menu(vec![
Menu::new("", vec![
Menu::new(
"",
vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
@ -24,9 +26,12 @@ impl AppDelegate for BasicApp {
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
]),
],
),
Menu::new("File", vec![MenuItem::CloseWindow]),
Menu::new("Edit", vec![
Menu::new(
"Edit",
vec![
MenuItem::Undo,
MenuItem::Redo,
MenuItem::Separator,
@ -35,14 +40,18 @@ impl AppDelegate for BasicApp {
MenuItem::Paste,
MenuItem::Separator,
MenuItem::SelectAll,
]),
],
),
Menu::new("View", vec![MenuItem::EnterFullScreen]),
Menu::new("Window", vec![
Menu::new(
"Window",
vec![
MenuItem::Minimize,
MenuItem::Zoom,
MenuItem::Separator,
MenuItem::new("Bring All to Front"),
]),
],
),
Menu::new("Help", vec![]),
]);
@ -78,14 +87,14 @@ impl TextFieldDelegate for ConsoleLogger {
#[derive(Debug)]
struct AppWindow {
input: TextField<ConsoleLogger>,
content: View
content: View,
}
impl AppWindow {
pub fn new() -> Self {
AppWindow {
input: TextField::with(ConsoleLogger),
content: View::new()
content: View::new(),
}
}
}
@ -103,14 +112,17 @@ impl WindowDelegate for AppWindow {
LayoutConstraint::activate(&[
self.input.center_x.constraint_equal_to(&self.content.center_x),
self.input.center_y.constraint_equal_to(&self.content.center_y),
self.input.width.constraint_equal_to_constant(280.)
self.input.width.constraint_equal_to_constant(280.),
]);
}
}
fn main() {
App::new("com.test.window", BasicApp {
window: Window::with(WindowConfig::default(), AppWindow::new())
})
App::new(
"com.test.window",
BasicApp {
window: Window::with(WindowConfig::default(), AppWindow::new()),
},
)
.run();
}

View file

@ -9,7 +9,7 @@ mod view;
use view::AddNewTodoContentView;
pub struct AddNewTodoWindow {
pub content: ViewController<AddNewTodoContentView>
pub content: ViewController<AddNewTodoContentView>,
}
impl AddNewTodoWindow {

View file

@ -19,7 +19,7 @@ use crate::storage::{dispatch_ui, Message};
pub struct AddNewTodoContentView {
pub view: Option<View>,
pub input: Option<TextField>,
pub button: Option<Button>
pub button: Option<Button>,
}
impl AddNewTodoContentView {
@ -34,7 +34,7 @@ impl AddNewTodoContentView {
}
},
_ => {}
_ => {},
}
}
}
@ -65,7 +65,7 @@ impl ViewDelegate for AddNewTodoContentView {
input.trailing.constraint_equal_to(&view.trailing).offset(-16.),
button.top.constraint_equal_to(&input.bottom).offset(8.),
button.trailing.constraint_equal_to(&view.trailing).offset(-16.),
button.bottom.constraint_equal_to(&view.bottom).offset(-16.)
button.bottom.constraint_equal_to(&view.bottom).offset(-16.),
]);
self.view = Some(view);

View file

@ -11,7 +11,7 @@ use crate::windows::WindowManager;
/// This handles routing lifecycle events, and maintains our `WindowManager`.
#[derive(Default)]
pub struct TodosApp {
pub window_manager: WindowManager
pub window_manager: WindowManager,
}
impl AppDelegate for TodosApp {

View file

@ -11,7 +11,9 @@ use crate::storage::{dispatch_ui, Message};
/// Installs the menu.
pub fn menu() -> Vec<Menu> {
vec![
Menu::new("", vec![
Menu::new(
"",
vec![
MenuItem::About("Todos".to_string()),
MenuItem::Separator,
MenuItem::new("Preferences").key(",").action(|| {
@ -25,8 +27,11 @@ pub fn menu() -> Vec<Menu> {
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
]),
Menu::new("File", vec![
],
),
Menu::new(
"File",
vec![
MenuItem::new("Open/Show Window").key("n").action(|| {
dispatch_ui(Message::OpenMainWindow);
}),
@ -36,8 +41,11 @@ pub fn menu() -> Vec<Menu> {
}),
MenuItem::Separator,
MenuItem::CloseWindow,
]),
Menu::new("Edit", vec![
],
),
Menu::new(
"Edit",
vec![
MenuItem::Undo,
MenuItem::Redo,
MenuItem::Separator,
@ -46,14 +54,18 @@ pub fn menu() -> Vec<Menu> {
MenuItem::Paste,
MenuItem::Separator,
MenuItem::SelectAll,
]),
],
),
Menu::new("View", vec![MenuItem::EnterFullScreen]),
Menu::new("Window", vec![
Menu::new(
"Window",
vec![
MenuItem::Minimize,
MenuItem::Zoom,
MenuItem::Separator,
MenuItem::new("Bring All to Front"),
]),
],
),
Menu::new("Help", vec![]),
]
}

View file

@ -5,7 +5,7 @@ use cacao::view::{View, ViewDelegate};
/// A blank advanced preferences view.
#[derive(Debug, Default)]
pub struct AdvancedPreferencesContentView {
label: Label
label: Label,
}
impl ViewDelegate for AdvancedPreferencesContentView {
@ -21,7 +21,7 @@ impl ViewDelegate for AdvancedPreferencesContentView {
self.label.top.constraint_equal_to(&view.top).offset(100.),
self.label.leading.constraint_equal_to(&view.leading).offset(16.),
self.label.trailing.constraint_equal_to(&view.trailing).offset(-16.),
self.label.bottom.constraint_equal_to(&view.bottom).offset(-100.)
self.label.bottom.constraint_equal_to(&view.bottom).offset(-100.),
]);
}
}

View file

@ -12,7 +12,7 @@ use super::toggle_option_view::ToggleOptionView;
/// A general preferences view.
#[derive(Debug, Default)]
pub struct GeneralPreferencesContentView {
pub example_option: ToggleOptionView
pub example_option: ToggleOptionView,
}
impl ViewDelegate for GeneralPreferencesContentView {
@ -23,7 +23,7 @@ impl ViewDelegate for GeneralPreferencesContentView {
"An example preference",
"This can be true, or it can be false.",
Defaults::should_whatever(), // initial value
Defaults::toggle_should_whatever
Defaults::toggle_should_whatever,
);
view.add_subview(&self.example_option.view);
@ -40,7 +40,7 @@ impl ViewDelegate for GeneralPreferencesContentView {
.trailing
.constraint_equal_to(&view.trailing)
.offset(-22.),
self.example_option.view.bottom.constraint_equal_to(&view.bottom).offset(-22.)
self.example_option.view.bottom.constraint_equal_to(&view.bottom).offset(-22.),
]);
}
}

View file

@ -21,7 +21,7 @@ pub struct PreferencesWindow {
pub toolbar: Toolbar<PreferencesToolbar>,
pub general: ViewController<GeneralPreferencesContentView>,
pub advanced: ViewController<AdvancedPreferencesContentView>,
window: Option<Window>
window: Option<Window>,
}
impl PreferencesWindow {
@ -30,7 +30,7 @@ impl PreferencesWindow {
toolbar: Toolbar::new("PreferencesToolbar", PreferencesToolbar::default()),
general: ViewController::new(GeneralPreferencesContentView::default()),
advanced: ViewController::new(AdvancedPreferencesContentView::default()),
window: None
window: None,
}
}
@ -48,7 +48,7 @@ impl PreferencesWindow {
window.set_content_view_controller(&self.advanced);
},
_ => {}
_ => {},
}
}
}

View file

@ -10,7 +10,7 @@ pub struct ToggleOptionView {
pub view: View,
pub switch: Switch,
pub title: Label,
pub subtitle: Label
pub subtitle: Label,
}
impl Default for ToggleOptionView {
@ -37,14 +37,14 @@ impl Default for ToggleOptionView {
subtitle.top.constraint_equal_to(&title.bottom),
subtitle.leading.constraint_equal_to(&switch.trailing),
subtitle.trailing.constraint_equal_to(&view.trailing),
subtitle.bottom.constraint_equal_to(&view.bottom)
subtitle.bottom.constraint_equal_to(&view.bottom),
]);
ToggleOptionView {
view,
switch,
title,
subtitle
subtitle,
}
}
}
@ -54,7 +54,7 @@ impl ToggleOptionView {
/// can toggle your settings and such there.
pub fn configure<F>(&mut self, text: &str, subtitle: &str, state: bool, handler: F)
where
F: Fn() + Send + Sync + 'static
F: Fn() + Send + Sync + 'static,
{
self.title.set_text(text);
self.subtitle.set_text(subtitle);

View file

@ -37,7 +37,7 @@ impl Default for PreferencesToolbar {
});
item
}
},
))
}
}
@ -67,7 +67,7 @@ impl ToolbarDelegate for PreferencesToolbar {
"advanced" => &self.0 .1,
_ => {
unreachable!();
}
},
}
}
}

View file

@ -2,7 +2,7 @@ use std::collections::HashMap;
use cacao::defaults::{UserDefaults, Value};
const EXAMPLE: &'static str = "exampleSetting";
const EXAMPLE: &str = "exampleSetting";
/// A very basic wrapper around UserDefaults. If I wind up implementing Serde support for
/// UserDefaults, then much of this could be removed or simplified - but I'm not sold on that yet,

View file

@ -45,7 +45,7 @@ pub enum Message {
MarkTodoComplete(usize),
/// Mark a todo as incomplete.
MarkTodoIncomplete(usize)
MarkTodoIncomplete(usize),
}
/// Dispatch a message on a background thread.

View file

@ -12,7 +12,7 @@ pub enum TodoStatus {
Incomplete,
/// Completed. ;P
Complete
Complete,
}
/// A Todo. Represents... something to do.
@ -22,7 +22,7 @@ pub struct Todo {
pub title: String,
/// The status of this todo.
pub status: TodoStatus
pub status: TodoStatus,
}
/// A single-threaded Todos "database".
@ -36,7 +36,7 @@ impl Todos {
let mut todos = vec![Todo {
title: title,
status: TodoStatus::Incomplete
status: TodoStatus::Incomplete,
}];
todos.append(&mut stack);
@ -47,7 +47,7 @@ impl Todos {
/// Edit a Todo at the row specified.
pub fn with_mut<F>(&self, row: usize, handler: F)
where
F: Fn(&mut Todo)
F: Fn(&mut Todo),
{
let mut stack = self.0.borrow_mut();
@ -59,7 +59,7 @@ impl Todos {
/// Run a block with the given Todo.
pub fn with<F>(&self, row: usize, mut handler: F)
where
F: FnMut(&Todo)
F: FnMut(&Todo),
{
let stack = self.0.borrow();

View file

@ -12,13 +12,13 @@ use crate::storage::Message;
#[derive(Debug)]
pub struct TodosContentView {
pub todos_list_view: ListView<TodosListView>
pub todos_list_view: ListView<TodosListView>,
}
impl Default for TodosContentView {
fn default() -> Self {
TodosContentView {
todos_list_view: ListView::with(TodosListView::default())
todos_list_view: ListView::with(TodosListView::default()),
}
}
}
@ -41,7 +41,7 @@ impl ViewDelegate for TodosContentView {
self.todos_list_view.top.constraint_equal_to(&view.top),
self.todos_list_view.leading.constraint_equal_to(&view.leading),
self.todos_list_view.trailing.constraint_equal_to(&view.trailing),
self.todos_list_view.bottom.constraint_equal_to(&view.bottom)
self.todos_list_view.bottom.constraint_equal_to(&view.bottom),
]);
}
}

View file

@ -10,13 +10,13 @@ mod row;
use row::TodoViewRow;
/// An identifier for the cell(s) we dequeue.
const TODO_ROW: &'static str = "TodoViewRowCell";
const TODO_ROW: &str = "TodoViewRowCell";
/// The list view for todos.
#[derive(Debug, Default)]
pub struct TodosListView {
view: Option<ListView>,
todos: Todos
todos: Todos,
}
impl TodosListView {
@ -49,7 +49,7 @@ impl TodosListView {
});
},
_ => {}
_ => {},
}
}
}
@ -99,7 +99,7 @@ impl ListViewDelegate for TodosListView {
RowActionStyle::Destructive,
move |_action, row| {
dispatch_ui(Message::MarkTodoIncomplete(row));
}
},
));
},
@ -109,9 +109,9 @@ impl ListViewDelegate for TodosListView {
RowActionStyle::Regular,
move |_action, row| {
dispatch_ui(Message::MarkTodoComplete(row));
}
},
));
}
},
});
actions

View file

@ -10,7 +10,7 @@ use crate::storage::{Todo, TodoStatus};
#[derive(Default, Debug)]
pub struct TodoViewRow {
pub title: Label,
pub status: Label
pub status: Label,
}
impl TodoViewRow {
@ -27,7 +27,7 @@ impl TodoViewRow {
TodoStatus::Complete => {
self.status.set_text_color(Color::SystemBlue);
self.status.set_text("Complete");
}
},
}
}
}
@ -53,7 +53,7 @@ impl ViewDelegate for TodoViewRow {
self.status.top.constraint_equal_to(&self.title.bottom).offset(8.),
self.status.leading.constraint_equal_to(&view.leading).offset(16.),
self.status.trailing.constraint_equal_to(&view.trailing).offset(-16.),
self.status.bottom.constraint_equal_to(&view.bottom).offset(-16.)
self.status.bottom.constraint_equal_to(&view.bottom).offset(-16.),
]);
}
}

View file

@ -16,14 +16,14 @@ mod list;
pub struct TodosWindow {
pub content: ViewController<TodosContentView>,
pub toolbar: Toolbar<TodosToolbar>
pub toolbar: Toolbar<TodosToolbar>,
}
impl TodosWindow {
pub fn new() -> Self {
TodosWindow {
content: ViewController::new(TodosContentView::default()),
toolbar: Toolbar::new("TodosToolbar", TodosToolbar::default())
toolbar: Toolbar::new("TodosToolbar", TodosToolbar::default()),
}
}

View file

@ -18,7 +18,7 @@ use crate::todos::TodosWindow;
pub struct WindowManager {
pub main: RwLock<Option<Window<TodosWindow>>>,
pub preferences: RwLock<Option<Window<PreferencesWindow>>>,
pub add: RwLock<Option<Window<AddNewTodoWindow>>>
pub add: RwLock<Option<Window<AddNewTodoWindow>>>,
}
/// A helper method to handle checking for window existence, and creating
@ -26,7 +26,7 @@ pub struct WindowManager {
fn open_or_show<T, F>(window: &RwLock<Option<Window<T>>>, vendor: F)
where
T: WindowDelegate + 'static,
F: Fn() -> (WindowConfig, T)
F: Fn() -> (WindowConfig, T),
{
let mut lock = window.write().unwrap();
@ -50,7 +50,7 @@ impl WindowManager {
pub fn begin_sheet<W, F>(&self, window: &Window<W>, completion: F)
where
W: WindowDelegate + 'static,
F: Fn() + Send + Sync + 'static
F: Fn() + Send + Sync + 'static,
{
let main = self.main.write().unwrap();
@ -101,7 +101,7 @@ impl WindowManager {
WindowStyle::Resizable,
WindowStyle::Miniaturizable,
WindowStyle::Closable,
WindowStyle::Titled
WindowStyle::Titled,
]);
config.toolbar_style = WindowToolbarStyle::Preferences;
@ -137,7 +137,7 @@ impl Dispatcher for WindowManager {
self.close_sheet();
},
_ => {}
_ => {},
}
if let Some(w) = &*(self.main.read().unwrap()) {

View file

@ -9,7 +9,7 @@ use cacao::appkit::{App, AppDelegate};
use cacao::webview::{WebView, WebViewConfig, WebViewDelegate};
struct BasicApp {
window: Window<AppWindow>
window: Window<AppWindow>,
}
impl AppDelegate for BasicApp {
@ -56,13 +56,13 @@ impl WebViewDelegate for WebViewInstance {
return match requested_asset_path.as_str() {
"/hello.html" => Some(link_html.as_bytes().into()),
_ => Some(index_html.as_bytes().into())
_ => Some(index_html.as_bytes().into()),
};
}
}
struct AppWindow {
content: WebView<WebViewInstance>
content: WebView<WebViewInstance>,
}
impl AppWindow {
@ -73,7 +73,7 @@ impl AppWindow {
webview_config.add_custom_protocol("cacao");
AppWindow {
content: WebView::with(webview_config, WebViewInstance::default())
content: WebView::with(webview_config, WebViewInstance::default()),
}
}
@ -98,8 +98,11 @@ impl WindowDelegate for AppWindow {
}
fn main() {
App::new("com.test.window", BasicApp {
window: Window::with(WindowConfig::default(), AppWindow::new())
})
App::new(
"com.test.window",
BasicApp {
window: Window::with(WindowConfig::default(), AppWindow::new()),
},
)
.run();
}

View file

@ -6,13 +6,15 @@ use cacao::appkit::{App, AppDelegate};
#[derive(Default)]
struct BasicApp {
window: Window
window: Window,
}
impl AppDelegate for BasicApp {
fn did_finish_launching(&self) {
App::set_menu(vec![
Menu::new("", vec![
Menu::new(
"",
vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
@ -20,15 +22,19 @@ impl AppDelegate for BasicApp {
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
]),
],
),
Menu::new("File", vec![MenuItem::CloseWindow]),
Menu::new("View", vec![MenuItem::EnterFullScreen]),
Menu::new("Window", vec![
Menu::new(
"Window",
vec![
MenuItem::Minimize,
MenuItem::Zoom,
MenuItem::Separator,
MenuItem::new("Bring All to Front"),
]),
],
),
]);
App::activate();

View file

@ -9,13 +9,15 @@ use cacao::appkit::window::{Window, WindowConfig, WindowController, WindowDelega
use cacao::appkit::{App, AppDelegate};
struct BasicApp {
window: WindowController<MyWindow>
window: WindowController<MyWindow>,
}
impl AppDelegate for BasicApp {
fn did_finish_launching(&self) {
App::set_menu(vec![
Menu::new("", vec![
Menu::new(
"",
vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
@ -23,15 +25,19 @@ impl AppDelegate for BasicApp {
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
]),
],
),
Menu::new("File", vec![MenuItem::CloseWindow]),
Menu::new("View", vec![MenuItem::EnterFullScreen]),
Menu::new("Window", vec![
Menu::new(
"Window",
vec![
MenuItem::Minimize,
MenuItem::Zoom,
MenuItem::Separator,
MenuItem::new("Bring All to Front"),
]),
],
),
]);
App::activate();
@ -61,8 +67,11 @@ impl WindowDelegate for MyWindow {
}
fn main() {
App::new("com.test.window-delegate", BasicApp {
window: WindowController::with(WindowConfig::default(), MyWindow::default())
})
App::new(
"com.test.window-delegate",
BasicApp {
window: WindowController::with(WindowConfig::default(), MyWindow::default()),
},
)
.run();
}

View file

@ -6,13 +6,15 @@ use cacao::appkit::window::{Window, WindowConfig, WindowDelegate};
use cacao::appkit::{App, AppDelegate};
struct BasicApp {
window: Window<MyWindow>
window: Window<MyWindow>,
}
impl AppDelegate for BasicApp {
fn did_finish_launching(&self) {
App::set_menu(vec![
Menu::new("", vec![
Menu::new(
"",
vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
@ -20,15 +22,19 @@ impl AppDelegate for BasicApp {
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
]),
],
),
Menu::new("File", vec![MenuItem::CloseWindow]),
Menu::new("View", vec![MenuItem::EnterFullScreen]),
Menu::new("Window", vec![
Menu::new(
"Window",
vec![
MenuItem::Minimize,
MenuItem::Zoom,
MenuItem::Separator,
MenuItem::new("Bring All to Front"),
]),
],
),
]);
App::activate();
@ -71,8 +77,11 @@ impl WindowDelegate for MyWindow {
}
fn main() {
App::new("com.test.window-delegate", BasicApp {
window: Window::with(WindowConfig::default(), MyWindow::default())
})
App::new(
"com.test.window-delegate",
BasicApp {
window: Window::with(WindowConfig::default(), MyWindow::default()),
},
)
.run();
}

View file

@ -29,7 +29,7 @@ impl AnimationContext {
/// the supported methods here.
pub fn run<F>(animation: F)
where
F: Fn(&mut AnimationContext) + Send + Sync + 'static
F: Fn(&mut AnimationContext) + Send + Sync + 'static,
{
let block = ConcreteBlock::new(move |ctx| {
let mut context = AnimationContext(ctx);
@ -53,7 +53,7 @@ impl AnimationContext {
pub fn run_with_completion_handler<F, C>(animation: F, completion_handler: C)
where
F: Fn(&mut AnimationContext) + Send + Sync + 'static,
C: Fn() + Send + Sync + 'static
C: Fn() + Send + Sync + 'static,
{
let block = ConcreteBlock::new(move |ctx| {
let mut context = AnimationContext(ctx);

View file

@ -107,7 +107,7 @@ extern "C" fn did_update<T: AppDelegate>(this: &Object, _: Sel, _: id) {
extern "C" fn should_handle_reopen<T: AppDelegate>(this: &Object, _: Sel, _: id, has_visible_windows: BOOL) -> BOOL {
match app::<T>(this).should_handle_reopen(to_bool(has_visible_windows)) {
true => YES,
false => NO
false => NO,
}
}
@ -116,7 +116,7 @@ extern "C" fn should_handle_reopen<T: AppDelegate>(this: &Object, _: Sel, _: id,
extern "C" fn dock_menu<T: AppDelegate>(this: &Object, _: Sel, _: id) -> id {
match app::<T>(this).dock_menu() {
Some(mut menu) => &mut *menu.0,
None => nil
None => nil,
}
}
@ -138,7 +138,7 @@ extern "C" fn will_continue_user_activity_with_type<T: AppDelegate>(this: &Objec
match app::<T>(this).will_continue_user_activity(activity.to_str()) {
true => YES,
false => NO
false => NO,
}
}
@ -154,7 +154,7 @@ extern "C" fn continue_user_activity<T: AppDelegate>(this: &Object, _: Sel, _: i
(*handler).call((nil,));
}) {
true => YES,
false => NO
false => NO,
}
}
@ -210,7 +210,7 @@ extern "C" fn open_file_without_ui<T: AppDelegate>(this: &Object, _: Sel, _: id,
match app::<T>(this).open_file_without_ui(filename.to_str()) {
true => YES,
false => NO
false => NO,
}
}
@ -218,7 +218,7 @@ extern "C" fn open_file_without_ui<T: AppDelegate>(this: &Object, _: Sel, _: id,
extern "C" fn should_open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _: id) -> BOOL {
match app::<T>(this).should_open_untitled_file() {
true => YES,
false => NO
false => NO,
}
}
@ -226,7 +226,7 @@ extern "C" fn should_open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _
extern "C" fn should_terminate_after_last_window_closed<T: AppDelegate>(this: &Object, _: Sel, _: id) -> BOOL {
match app::<T>(this).should_terminate_after_last_window_closed() {
true => YES,
false => NO
false => NO,
}
}
@ -234,7 +234,7 @@ extern "C" fn should_terminate_after_last_window_closed<T: AppDelegate>(this: &O
extern "C" fn open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _: id) -> BOOL {
match app::<T>(this).open_untitled_file() {
true => YES,
false => NO
false => NO,
}
}
@ -244,7 +244,7 @@ extern "C" fn open_temp_file<T: AppDelegate>(this: &Object, _: Sel, _: id, filen
match app::<T>(this).open_temp_file(filename.to_str()) {
true => YES,
false => NO
false => NO,
}
}
@ -254,7 +254,7 @@ extern "C" fn print_file<T: AppDelegate>(this: &Object, _: Sel, _: id, file: id)
match app::<T>(this).print_file(filename.to_str()) {
true => YES,
false => NO
false => NO,
}
}
@ -266,7 +266,7 @@ extern "C" fn print_files<T: AppDelegate>(
_: id,
files: id,
settings: id,
show_print_panels: BOOL
show_print_panels: BOOL,
) -> NSUInteger {
let files = NSArray::retain(files).map(|file| NSString::retain(file).to_str().to_string());
@ -288,7 +288,7 @@ extern "C" fn delegate_handles_key<T: AppDelegate>(this: &Object, _: Sel, _: id,
match app::<T>(this).delegate_handles_key(key.to_str()) {
true => YES,
false => NO
false => NO,
}
}
@ -307,43 +307,43 @@ pub(crate) fn register_app_delegate_class<T: AppDelegate + AppDelegate>() -> *co
// Launching Applications
decl.add_method(
sel!(applicationWillFinishLaunching:),
will_finish_launching::<T> as extern "C" fn(&Object, _, _)
will_finish_launching::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(applicationDidFinishLaunching:),
did_finish_launching::<T> as extern "C" fn(&Object, _, _)
did_finish_launching::<T> as extern "C" fn(&Object, _, _),
);
// Managing Active Status
decl.add_method(
sel!(applicationWillBecomeActive:),
will_become_active::<T> as extern "C" fn(&Object, _, _)
will_become_active::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(applicationDidBecomeActive:),
did_become_active::<T> as extern "C" fn(&Object, _, _)
did_become_active::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(applicationWillResignActive:),
will_resign_active::<T> as extern "C" fn(&Object, _, _)
will_resign_active::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(applicationDidResignActive:),
did_resign_active::<T> as extern "C" fn(&Object, _, _)
did_resign_active::<T> as extern "C" fn(&Object, _, _),
);
// Terminating Applications
decl.add_method(
sel!(applicationShouldTerminate:),
should_terminate::<T> as extern "C" fn(&Object, _, _) -> NSUInteger
should_terminate::<T> as extern "C" fn(&Object, _, _) -> NSUInteger,
);
decl.add_method(
sel!(applicationWillTerminate:),
will_terminate::<T> as extern "C" fn(&Object, _, _)
will_terminate::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(applicationShouldTerminateAfterLastWindowClosed:),
should_terminate_after_last_window_closed::<T> as extern "C" fn(&Object, _, _) -> BOOL
should_terminate_after_last_window_closed::<T> as extern "C" fn(&Object, _, _) -> BOOL,
);
// Hiding Applications
@ -357,100 +357,100 @@ pub(crate) fn register_app_delegate_class<T: AppDelegate + AppDelegate>() -> *co
decl.add_method(sel!(applicationDidUpdate:), did_update::<T> as extern "C" fn(&Object, _, _));
decl.add_method(
sel!(applicationShouldHandleReopen:hasVisibleWindows:),
should_handle_reopen::<T> as extern "C" fn(&Object, _, _, BOOL) -> BOOL
should_handle_reopen::<T> as extern "C" fn(&Object, _, _, BOOL) -> BOOL,
);
// Dock Menu
decl.add_method(
sel!(applicationDockMenu:),
dock_menu::<T> as extern "C" fn(&Object, _, _) -> id
dock_menu::<T> as extern "C" fn(&Object, _, _) -> id,
);
// Displaying Errors
decl.add_method(
sel!(application:willPresentError:),
will_present_error::<T> as extern "C" fn(&Object, _, _, id) -> id
will_present_error::<T> as extern "C" fn(&Object, _, _, id) -> id,
);
// Managing the Screen
decl.add_method(
sel!(applicationDidChangeScreenParameters:),
did_change_screen_parameters::<T> as extern "C" fn(&Object, _, _)
did_change_screen_parameters::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(applicationDidChangeOcclusionState:),
did_change_occlusion_state::<T> as extern "C" fn(&Object, _, _)
did_change_occlusion_state::<T> as extern "C" fn(&Object, _, _),
);
// User Activities
decl.add_method(
sel!(application:willContinueUserActivityWithType:),
will_continue_user_activity_with_type::<T> as extern "C" fn(&Object, _, _, id) -> BOOL
will_continue_user_activity_with_type::<T> as extern "C" fn(&Object, _, _, id) -> BOOL,
);
decl.add_method(
sel!(application:continueUserActivity:restorationHandler:),
continue_user_activity::<T> as extern "C" fn(&Object, _, _, id, id) -> BOOL
continue_user_activity::<T> as extern "C" fn(&Object, _, _, id, id) -> BOOL,
);
decl.add_method(
sel!(application:didFailToContinueUserActivityWithType:error:),
failed_to_continue_user_activity::<T> as extern "C" fn(&Object, _, _, id, id)
failed_to_continue_user_activity::<T> as extern "C" fn(&Object, _, _, id, id),
);
decl.add_method(
sel!(application:didUpdateUserActivity:),
did_update_user_activity::<T> as extern "C" fn(&Object, _, _, id)
did_update_user_activity::<T> as extern "C" fn(&Object, _, _, id),
);
// Handling push notifications
decl.add_method(
sel!(application:didRegisterForRemoteNotificationsWithDeviceToken:),
registered_for_remote_notifications::<T> as extern "C" fn(&Object, _, _, id)
registered_for_remote_notifications::<T> as extern "C" fn(&Object, _, _, id),
);
decl.add_method(
sel!(application:didFailToRegisterForRemoteNotificationsWithError:),
failed_to_register_for_remote_notifications::<T> as extern "C" fn(&Object, _, _, id)
failed_to_register_for_remote_notifications::<T> as extern "C" fn(&Object, _, _, id),
);
decl.add_method(
sel!(application:didReceiveRemoteNotification:),
did_receive_remote_notification::<T> as extern "C" fn(&Object, _, _, id)
did_receive_remote_notification::<T> as extern "C" fn(&Object, _, _, id),
);
// CloudKit
#[cfg(feature = "cloudkit")]
decl.add_method(
sel!(application:userDidAcceptCloudKitShareWithMetadata:),
accepted_cloudkit_share::<T> as extern "C" fn(&Object, _, _, id)
accepted_cloudkit_share::<T> as extern "C" fn(&Object, _, _, id),
);
// Opening Files
decl.add_method(
sel!(application:openURLs:),
open_urls::<T> as extern "C" fn(&Object, _, _, id)
open_urls::<T> as extern "C" fn(&Object, _, _, id),
);
decl.add_method(
sel!(application:openFileWithoutUI:),
open_file_without_ui::<T> as extern "C" fn(&Object, _, _, id) -> BOOL
open_file_without_ui::<T> as extern "C" fn(&Object, _, _, id) -> BOOL,
);
decl.add_method(
sel!(applicationShouldOpenUntitledFile:),
should_open_untitled_file::<T> as extern "C" fn(&Object, _, _) -> BOOL
should_open_untitled_file::<T> as extern "C" fn(&Object, _, _) -> BOOL,
);
decl.add_method(
sel!(applicationOpenUntitledFile:),
open_untitled_file::<T> as extern "C" fn(&Object, _, _) -> BOOL
open_untitled_file::<T> as extern "C" fn(&Object, _, _) -> BOOL,
);
decl.add_method(
sel!(application:openTempFile:),
open_temp_file::<T> as extern "C" fn(&Object, _, _, id) -> BOOL
open_temp_file::<T> as extern "C" fn(&Object, _, _, id) -> BOOL,
);
// Printing
decl.add_method(
sel!(application:printFile:),
print_file::<T> as extern "C" fn(&Object, _, _, id) -> BOOL
print_file::<T> as extern "C" fn(&Object, _, _, id) -> BOOL,
);
decl.add_method(
sel!(application:printFiles:withSettings:showPrintPanels:),
print_files::<T> as extern "C" fn(&Object, _, id, id, id, BOOL) -> NSUInteger
print_files::<T> as extern "C" fn(&Object, _, id, id, id, BOOL) -> NSUInteger,
);
// @TODO: Restoring Application State
@ -459,7 +459,7 @@ pub(crate) fn register_app_delegate_class<T: AppDelegate + AppDelegate>() -> *co
// Scripting
decl.add_method(
sel!(application:delegateHandlesKey:),
delegate_handles_key::<T> as extern "C" fn(&Object, _, _, id) -> BOOL
delegate_handles_key::<T> as extern "C" fn(&Object, _, _, id) -> BOOL,
);
DELEGATE_CLASS = decl.register();

View file

@ -17,7 +17,7 @@ pub enum TerminateResponse {
///
/// This return value is for primarily for cases where you need to provide alerts
/// in order to decide whether to quit.
Later
Later,
}
impl From<TerminateResponse> for NSUInteger {
@ -25,7 +25,7 @@ impl From<TerminateResponse> for NSUInteger {
match response {
TerminateResponse::Now => 1,
TerminateResponse::Cancel => 0,
TerminateResponse::Later => 2
TerminateResponse::Later => 2,
}
}
}
@ -44,7 +44,7 @@ pub enum AppDelegateResponse {
Success,
/// Failed.
Failure
Failure,
}
impl From<AppDelegateResponse> for NSUInteger {
@ -52,7 +52,7 @@ impl From<AppDelegateResponse> for NSUInteger {
match response {
AppDelegateResponse::Cancelled => 1,
AppDelegateResponse::Success => 0,
AppDelegateResponse::Failure => 2
AppDelegateResponse::Failure => 2,
}
}
}
@ -112,7 +112,7 @@ pub enum PresentationOption {
AutoHideToolbar,
/// The behavior that allows the user to shake the mouse to locate the cursor is disabled.
DisableCursorLocationAssistance
DisableCursorLocationAssistance,
}
impl From<PresentationOption> for NSUInteger {
@ -131,7 +131,7 @@ impl From<PresentationOption> for NSUInteger {
PresentationOption::DisableMenuBarTransparency => (1 << 9),
PresentationOption::FullScreen => (1 << 10),
PresentationOption::AutoHideToolbar => (1 << 11),
PresentationOption::DisableCursorLocationAssistance => (1 << 12)
PresentationOption::DisableCursorLocationAssistance => (1 << 12),
}
}
}
@ -152,7 +152,7 @@ impl From<&PresentationOption> for NSUInteger {
PresentationOption::DisableMenuBarTransparency => (1 << 9),
PresentationOption::FullScreen => (1 << 10),
PresentationOption::AutoHideToolbar => (1 << 11),
PresentationOption::DisableCursorLocationAssistance => (1 << 12)
PresentationOption::DisableCursorLocationAssistance => (1 << 12),
}
}
}

View file

@ -98,7 +98,7 @@ pub struct App<T = (), M = ()> {
/// The main-thread AutoReleasePool. Drains on app exit.
pub pool: AutoReleasePool,
_message: std::marker::PhantomData<M>
_message: std::marker::PhantomData<M>,
}
impl<T, M> fmt::Debug for App<T, M> {
@ -130,7 +130,7 @@ impl<T> App<T> {
impl<T> App<T>
where
T: AppDelegate + 'static
T: AppDelegate + 'static,
{
/// Creates an NSAutoReleasePool, configures various NSApplication properties (e.g, activation
/// policies), injects an `NSObject` delegate wrapper, and retains everything on the
@ -163,7 +163,7 @@ where
objc_delegate,
delegate: app_delegate,
pool,
_message: std::marker::PhantomData
_message: std::marker::PhantomData,
}
}
}
@ -186,7 +186,7 @@ where
impl<T, M> App<T, M>
where
M: Send + Sync + 'static,
T: AppDelegate + Dispatcher<Message = M>
T: AppDelegate + Dispatcher<Message = M>,
{
/// Dispatches a message by grabbing the `sharedApplication`, getting ahold of the delegate,
/// and passing back through there.

View file

@ -65,7 +65,7 @@ pub enum CursorType {
DragCopy,
/// Indicates a context menu will open.
ContextMenu
ContextMenu,
}
/// A wrapper around NSCursor.
@ -127,7 +127,7 @@ impl Cursor {
CursorType::OperationNotAllowed => msg_send![class!(NSCursor), operationNotAllowedCursor],
CursorType::DragLink => msg_send![class!(NSCursor), dragLinkCursor],
CursorType::DragCopy => msg_send![class!(NSCursor), dragCopyCursor],
CursorType::ContextMenu => msg_send![class!(NSCursor), contextualMenuCursor]
CursorType::ContextMenu => msg_send![class!(NSCursor), contextualMenuCursor],
};
let _: () = msg_send![cursor, push];

View file

@ -16,7 +16,7 @@ pub enum FocusRingType {
// Should never be used, but used as a placeholder in case the underlying
// system framework ever opts to return something we don't expect.
Unknown(NSUInteger)
Unknown(NSUInteger),
}
impl From<FocusRingType> for NSUInteger {
@ -25,7 +25,7 @@ impl From<FocusRingType> for NSUInteger {
FocusRingType::Default => 0,
FocusRingType::None => 1,
FocusRingType::Exterior => 2,
FocusRingType::Unknown(i) => i
FocusRingType::Unknown(i) => i,
}
}
}
@ -36,7 +36,7 @@ impl From<NSUInteger> for FocusRingType {
0 => Self::Default,
1 => Self::None,
2 => Self::Exterior,
i => Self::Unknown(i)
i => Self::Unknown(i),
}
}
}

View file

@ -9,7 +9,7 @@ use crate::foundation::{id, nil, NSString};
/// An EventMask describes the type of event.
#[derive(Debug)]
pub enum EventMask {
KeyDown
KeyDown,
}
/// A wrapper over an `NSEvent`.
@ -55,14 +55,14 @@ impl Event {
/// monitors are required - the streams don't mix.
pub fn local_monitor<F>(_mask: EventMask, handler: F) -> EventMonitor
where
F: Fn(Event) -> Option<Event> + Send + Sync + 'static
F: Fn(Event) -> Option<Event> + Send + Sync + 'static,
{
let block = ConcreteBlock::new(move |event: id| {
let evt = Event::new(event);
match handler(evt) {
Some(mut evt) => &mut *evt.0,
None => nil
None => nil,
}
});
let block = block.copy();
@ -82,7 +82,7 @@ pub enum EventModifierFlag {
Control,
Option,
Command,
DeviceIndependentFlagsMask
DeviceIndependentFlagsMask,
}
impl From<EventModifierFlag> for NSUInteger {
@ -92,7 +92,7 @@ impl From<EventModifierFlag> for NSUInteger {
EventModifierFlag::Control => 1 << 18,
EventModifierFlag::Option => 1 << 19,
EventModifierFlag::Command => 1 << 20,
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000,
}
}
}
@ -104,7 +104,7 @@ impl From<&EventModifierFlag> for NSUInteger {
EventModifierFlag::Control => 1 << 18,
EventModifierFlag::Option => 1 << 19,
EventModifierFlag::Command => 1 << 20,
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000,
}
}
}

View file

@ -39,7 +39,7 @@ fn make_menu_item<S: AsRef<str>>(
title: S,
key: Option<&str>,
action: Option<Sel>,
modifiers: Option<&[EventModifierFlag]>
modifiers: Option<&[EventModifierFlag]>,
) -> Id<Object> {
unsafe {
let title = NSString::new(title.as_ref());
@ -47,7 +47,7 @@ fn make_menu_item<S: AsRef<str>>(
// Note that AppKit requires a blank string if nil, not nil.
let key = NSString::new(match key {
Some(s) => s,
None => ""
None => "",
});
// Stock menu items that use selectors targeted at system pieces are just standard
@ -59,7 +59,7 @@ fn make_menu_item<S: AsRef<str>>(
None => msg_send![alloc, initWithTitle:&*title
action:sel!(fireBlockAction:)
keyEquivalent:&*key]
keyEquivalent:&*key],
});
if let Some(modifiers) = modifiers {
@ -147,7 +147,7 @@ pub enum MenuItem {
/// Represents a Separator. It's useful nonetheless for
/// separating out pieces of the `NSMenu` structure.
Separator
Separator,
}
impl MenuItem {
@ -178,7 +178,7 @@ impl MenuItem {
"Hide Others",
Some("h"),
Some(sel!(hide:)),
Some(&[EventModifierFlag::Command, EventModifierFlag::Option])
Some(&[EventModifierFlag::Command, EventModifierFlag::Option]),
),
Self::ShowAll => make_menu_item("Show All", None, Some(sel!(unhideAllApplications:)), None),
@ -195,7 +195,7 @@ impl MenuItem {
"Enter Full Screen",
Some("f"),
Some(sel!(toggleFullScreen:)),
Some(&[EventModifierFlag::Command, EventModifierFlag::Control])
Some(&[EventModifierFlag::Command, EventModifierFlag::Control]),
),
Self::Minimize => make_menu_item("Minimize", Some("m"), Some(sel!(performMiniaturize:)), None),
@ -205,14 +205,14 @@ impl MenuItem {
"Toggle Sidebar",
Some("s"),
Some(sel!(toggleSidebar:)),
Some(&[EventModifierFlag::Command, EventModifierFlag::Option])
Some(&[EventModifierFlag::Command, EventModifierFlag::Option]),
),
Self::Separator => {
let cls = class!(NSMenuItem);
let separator: id = msg_send![cls, separatorItem];
Id::from_ptr(separator)
}
},
}
}

View file

@ -75,7 +75,9 @@ impl Menu {
/// applications, as expected.
pub fn standard() -> Vec<Menu> {
vec![
Menu::new("", vec![
Menu::new(
"",
vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
@ -83,9 +85,12 @@ impl Menu {
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
]),
],
),
Menu::new("File", vec![MenuItem::CloseWindow]),
Menu::new("Edit", vec![
Menu::new(
"Edit",
vec![
MenuItem::Undo,
MenuItem::Redo,
MenuItem::Separator,
@ -94,14 +99,18 @@ impl Menu {
MenuItem::Paste,
MenuItem::Separator,
MenuItem::SelectAll,
]),
],
),
Menu::new("View", vec![MenuItem::EnterFullScreen]),
Menu::new("Window", vec![
Menu::new(
"Window",
vec![
MenuItem::Minimize,
MenuItem::Zoom,
MenuItem::Separator,
MenuItem::new("Bring All to Front"),
]),
],
),
]
}
}

View file

@ -17,7 +17,7 @@ pub enum PrintResponse {
/// For when the result of printing cannot be returned immediately (e.g, if printing causes a sheet to appear).
/// If your method returns PrintResponse::ReplyLater it must always invoke `App::reply_to_open_or_print()` when the
/// entire print operation has been completed, successfully or not.
ReplyLater
ReplyLater,
}
impl From<PrintResponse> for NSUInteger {
@ -26,7 +26,7 @@ impl From<PrintResponse> for NSUInteger {
PrintResponse::Cancelled => 0,
PrintResponse::Success => 1,
PrintResponse::Failure => 3,
PrintResponse::ReplyLater => 2
PrintResponse::ReplyLater => 2,
}
}
}

View file

@ -10,14 +10,14 @@ use crate::foundation::id;
/// application/user.
#[derive(Clone, Debug)]
pub struct PrintSettings {
pub inner: ShareId<Object>
pub inner: ShareId<Object>,
}
impl PrintSettings {
/// Internal method, constructs a wrapper around the backing `NSDictionary` print settings.
pub(crate) fn with_inner(inner: id) -> Self {
PrintSettings {
inner: unsafe { ShareId::from_ptr(inner) }
inner: unsafe { ShareId::from_ptr(inner) },
}
}
}

View file

@ -73,19 +73,19 @@ pub(crate) fn register_toolbar_class<T: ToolbarDelegate>(instance: &T) -> *const
// Add callback methods
decl.add_method(
sel!(toolbarAllowedItemIdentifiers:),
allowed_item_identifiers::<T> as extern "C" fn(&Object, _, _) -> id
allowed_item_identifiers::<T> as extern "C" fn(&Object, _, _) -> id,
);
decl.add_method(
sel!(toolbarDefaultItemIdentifiers:),
default_item_identifiers::<T> as extern "C" fn(&Object, _, _) -> id
default_item_identifiers::<T> as extern "C" fn(&Object, _, _) -> id,
);
decl.add_method(
sel!(toolbarSelectableItemIdentifiers:),
selectable_item_identifiers::<T> as extern "C" fn(&Object, _, _) -> id
selectable_item_identifiers::<T> as extern "C" fn(&Object, _, _) -> id,
);
decl.add_method(
sel!(toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:),
item_for_identifier::<T> as extern "C" fn(&Object, _, _, _, _) -> id
item_for_identifier::<T> as extern "C" fn(&Object, _, _, _, _) -> id,
);
})
}

View file

@ -15,7 +15,7 @@ pub enum ToolbarDisplayMode {
IconOnly,
/// Show label only.
LabelOnly
LabelOnly,
}
impl From<ToolbarDisplayMode> for NSUInteger {
@ -24,7 +24,7 @@ impl From<ToolbarDisplayMode> for NSUInteger {
ToolbarDisplayMode::Default => 0,
ToolbarDisplayMode::IconAndLabel => 1,
ToolbarDisplayMode::IconOnly => 2,
ToolbarDisplayMode::LabelOnly => 3
ToolbarDisplayMode::LabelOnly => 3,
}
}
}
@ -77,7 +77,7 @@ pub enum ItemIdentifier {
/// Note that this API was introduced in Big Sur (11.0), and you may need to check against this
/// at runtime to ensure behavior is appropriate on older OS versions (if you support them).
///
SidebarTracker
SidebarTracker,
}
extern "C" {
@ -106,7 +106,7 @@ impl ItemIdentifier {
// This ensures that the framework compiles and runs on 10.15.7 and lower; it will
// not actually work on anything except 11.0+. Use a runtime check to be safe.
Self::SidebarTracker => NSString::no_copy("NSToolbarSidebarTrackingSeparatorItemIdentifier").into()
Self::SidebarTracker => NSString::no_copy("NSToolbarSidebarTrackingSeparatorItemIdentifier").into(),
}
}
}
@ -122,7 +122,7 @@ pub enum ToolbarSizeMode {
Regular,
/// The small size mode.
Small
Small,
}
impl From<ToolbarSizeMode> for NSUInteger {
@ -130,7 +130,7 @@ impl From<ToolbarSizeMode> for NSUInteger {
match mode {
ToolbarSizeMode::Default => 0,
ToolbarSizeMode::Regular => 1,
ToolbarSizeMode::Small => 2
ToolbarSizeMode::Small => 2,
}
}
}

View file

@ -22,7 +22,7 @@ pub struct ToolbarItem {
pub objc: Id<Object>,
pub button: Option<Button>,
pub image: Option<Image>,
handler: Option<TargetActionHandler>
handler: Option<TargetActionHandler>,
}
impl ToolbarItem {
@ -43,7 +43,7 @@ impl ToolbarItem {
objc,
button: None,
image: None,
handler: None
handler: None,
}
}
@ -53,7 +53,7 @@ impl ToolbarItem {
objc: unsafe { Id::from_retained_ptr(item) },
button: None,
image: None,
handler: None
handler: None,
}
}

View file

@ -38,12 +38,12 @@ pub struct Toolbar<T = ()> {
pub objc_delegate: ShareId<Object>,
/// The user supplied delegate.
pub delegate: Option<Box<T>>
pub delegate: Option<Box<T>>,
}
impl<T> Toolbar<T>
where
T: ToolbarDelegate + 'static
T: ToolbarDelegate + 'static,
{
/// Creates a new `NSToolbar` instance, configures it appropriately, sets up the delegate
/// chain, and retains it all.
@ -69,14 +69,14 @@ where
objc: objc.clone(),
objc_delegate: objc_delegate.clone(),
identifier: identifier.clone(),
delegate: None
delegate: None,
});
Toolbar {
identifier,
objc,
objc_delegate,
delegate: Some(delegate)
delegate: Some(delegate),
}
}
}
@ -135,7 +135,7 @@ impl<T> fmt::Debug for Toolbar<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let delegate = match &self.delegate {
Some(d) => format!("Some({:p})", d),
None => "None".to_string()
None => "None".to_string(),
};
f.debug_struct("Toolbar")

View file

@ -20,7 +20,7 @@ extern "C" fn should_close<T: WindowDelegate>(this: &Object, _: Sel, _: id) -> B
match window.should_close() {
true => YES,
false => NO
false => NO,
}
}
@ -62,7 +62,7 @@ extern "C" fn will_resize<T: WindowDelegate>(this: &Object, _: Sel, _: id, size:
CGSize {
width: s.0 as CGFloat,
height: s.1 as CGFloat
height: s.1 as CGFloat,
}
}
@ -122,7 +122,7 @@ extern "C" fn content_size_for_full_screen<T: WindowDelegate>(this: &Object, _:
CGSize {
width: width as CGFloat,
height: height as CGFloat
height: height as CGFloat,
}
}
@ -234,71 +234,71 @@ pub(crate) fn register_window_class_with_delegate<T: WindowDelegate>(instance: &
// NSWindowDelegate methods
decl.add_method(
sel!(windowShouldClose:),
should_close::<T> as extern "C" fn(&Object, _, _) -> BOOL
should_close::<T> as extern "C" fn(&Object, _, _) -> BOOL,
);
decl.add_method(sel!(windowWillClose:), will_close::<T> as extern "C" fn(&Object, _, _));
// Sizing
decl.add_method(
sel!(windowWillResize:toSize:),
will_resize::<T> as extern "C" fn(&Object, _, _, CGSize) -> CGSize
will_resize::<T> as extern "C" fn(&Object, _, _, CGSize) -> CGSize,
);
decl.add_method(sel!(windowDidResize:), did_resize::<T> as extern "C" fn(&Object, _, _));
decl.add_method(
sel!(windowWillStartLiveResize:),
will_start_live_resize::<T> as extern "C" fn(&Object, _, _)
will_start_live_resize::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowDidEndLiveResize:),
did_end_live_resize::<T> as extern "C" fn(&Object, _, _)
did_end_live_resize::<T> as extern "C" fn(&Object, _, _),
);
// Minimizing
decl.add_method(
sel!(windowWillMiniaturize:),
will_miniaturize::<T> as extern "C" fn(&Object, _, _)
will_miniaturize::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowDidMiniaturize:),
did_miniaturize::<T> as extern "C" fn(&Object, _, _)
did_miniaturize::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowDidDeminiaturize:),
did_deminiaturize::<T> as extern "C" fn(&Object, _, _)
did_deminiaturize::<T> as extern "C" fn(&Object, _, _),
);
// Full Screen
decl.add_method(
sel!(window:willUseFullScreenContentSize:),
content_size_for_full_screen::<T> as extern "C" fn(&Object, _, _, CGSize) -> CGSize
content_size_for_full_screen::<T> as extern "C" fn(&Object, _, _, CGSize) -> CGSize,
);
decl.add_method(
sel!(window:willUseFullScreenPresentationOptions:),
options_for_full_screen::<T> as extern "C" fn(&Object, _, _, NSUInteger) -> NSUInteger
options_for_full_screen::<T> as extern "C" fn(&Object, _, _, NSUInteger) -> NSUInteger,
);
decl.add_method(
sel!(windowWillEnterFullScreen:),
will_enter_full_screen::<T> as extern "C" fn(&Object, _, _)
will_enter_full_screen::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowDidEnterFullScreen:),
did_enter_full_screen::<T> as extern "C" fn(&Object, _, _)
did_enter_full_screen::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowWillExitFullScreen:),
will_exit_full_screen::<T> as extern "C" fn(&Object, _, _)
will_exit_full_screen::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowDidExitFullScreen:),
did_exit_full_screen::<T> as extern "C" fn(&Object, _, _)
did_exit_full_screen::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowDidFailToEnterFullScreen:),
did_fail_to_enter_full_screen::<T> as extern "C" fn(&Object, _, _)
did_fail_to_enter_full_screen::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowDidFailToExitFullScreen:),
did_fail_to_exit_full_screen::<T> as extern "C" fn(&Object, _, _)
did_fail_to_exit_full_screen::<T> as extern "C" fn(&Object, _, _),
);
// Key status
@ -308,11 +308,11 @@ pub(crate) fn register_window_class_with_delegate<T: WindowDelegate>(instance: &
// Main status
decl.add_method(
sel!(windowDidBecomeMain:),
did_become_main::<T> as extern "C" fn(&Object, _, _)
did_become_main::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowDidResignMain:),
did_resign_main::<T> as extern "C" fn(&Object, _, _)
did_resign_main::<T> as extern "C" fn(&Object, _, _),
);
// Moving Windows
@ -320,21 +320,21 @@ pub(crate) fn register_window_class_with_delegate<T: WindowDelegate>(instance: &
decl.add_method(sel!(windowDidMove:), did_move::<T> as extern "C" fn(&Object, _, _));
decl.add_method(
sel!(windowDidChangeScreen:),
did_change_screen::<T> as extern "C" fn(&Object, _, _)
did_change_screen::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowDidChangeScreenProfile:),
did_change_screen_profile::<T> as extern "C" fn(&Object, _, _)
did_change_screen_profile::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(
sel!(windowDidChangeBackingProperties:),
did_change_backing_properties::<T> as extern "C" fn(&Object, _, _)
did_change_backing_properties::<T> as extern "C" fn(&Object, _, _),
);
// Random
decl.add_method(
sel!(windowDidChangeOcclusionState:),
did_change_occlusion_state::<T> as extern "C" fn(&Object, _, _)
did_change_occlusion_state::<T> as extern "C" fn(&Object, _, _),
);
decl.add_method(sel!(windowDidExpose:), did_expose::<T> as extern "C" fn(&Object, _, _));
decl.add_method(sel!(windowDidUpdate:), did_update::<T> as extern "C" fn(&Object, _, _));

View file

@ -32,7 +32,7 @@ pub struct WindowConfig {
/// for other variants.
///
/// This setting is notably important for Preferences windows.
pub toolbar_style: WindowToolbarStyle
pub toolbar_style: WindowToolbarStyle,
}
impl Default for WindowConfig {
@ -41,7 +41,7 @@ impl Default for WindowConfig {
style: 0,
initial_dimensions: Rect::new(100., 100., 1024., 768.),
defer: true,
toolbar_style: WindowToolbarStyle::Automatic
toolbar_style: WindowToolbarStyle::Automatic,
};
config.set_styles(&[
@ -50,7 +50,7 @@ impl Default for WindowConfig {
WindowStyle::UnifiedTitleAndToolbar,
WindowStyle::Closable,
WindowStyle::Titled,
WindowStyle::FullSizeContentView
WindowStyle::FullSizeContentView,
]);
config

View file

@ -48,12 +48,12 @@ pub struct WindowController<T> {
pub objc: Id<Object>,
/// The underlying `Window` that this controller wraps.
pub window: Window<T>
pub window: Window<T>,
}
impl<T> WindowController<T>
where
T: WindowDelegate + 'static
T: WindowDelegate + 'static,
{
/// Allocates and configures an `NSWindowController` in the Objective-C/Cocoa runtime that maps over
/// to your supplied delegate.

View file

@ -39,7 +39,7 @@ pub enum WindowStyle {
NonActivatingPanel,
/// A HUD window.
HUDWindow
HUDWindow,
}
impl From<WindowStyle> for NSUInteger {
@ -56,7 +56,7 @@ impl From<WindowStyle> for NSUInteger {
WindowStyle::Utility => 1 << 4,
WindowStyle::DocModalWindow => 1 << 6,
WindowStyle::NonActivatingPanel => 1 << 7,
WindowStyle::HUDWindow => 1 << 13
WindowStyle::HUDWindow => 1 << 13,
}
}
}
@ -75,7 +75,7 @@ impl From<&WindowStyle> for NSUInteger {
WindowStyle::Utility => 1 << 4,
WindowStyle::DocModalWindow => 1 << 6,
WindowStyle::NonActivatingPanel => 1 << 7,
WindowStyle::HUDWindow => 1 << 13
WindowStyle::HUDWindow => 1 << 13,
}
}
}
@ -87,14 +87,14 @@ pub enum TitleVisibility {
Visible,
/// Title is hidden.
Hidden
Hidden,
}
impl From<TitleVisibility> for NSInteger {
fn from(visibility: TitleVisibility) -> Self {
match visibility {
TitleVisibility::Visible => 0,
TitleVisibility::Hidden => 1
TitleVisibility::Hidden => 1,
}
}
}
@ -120,7 +120,7 @@ pub enum WindowToolbarStyle {
/// The Big Sur (11.0+) style, but more compact. Toolbar flushes up against the title and
/// spacing is reduced.
UnifiedCompact
UnifiedCompact,
}
impl From<WindowToolbarStyle> for NSUInteger {
@ -130,7 +130,7 @@ impl From<WindowToolbarStyle> for NSUInteger {
WindowToolbarStyle::Expanded => 1,
WindowToolbarStyle::Preferences => 2,
WindowToolbarStyle::Unified => 3,
WindowToolbarStyle::UnifiedCompact => 4
WindowToolbarStyle::UnifiedCompact => 4,
}
}
}

View file

@ -49,7 +49,7 @@ pub struct Window<T = ()> {
pub objc: ShareId<Object>,
/// A delegate for this window.
pub delegate: Option<Box<T>>
pub delegate: Option<Box<T>>,
}
impl Default for Window {
@ -109,14 +109,14 @@ impl Window {
Window {
objc: objc,
delegate: None
delegate: None,
}
}
}
impl<T> Window<T>
where
T: WindowDelegate + 'static
T: WindowDelegate + 'static,
{
/// Constructs a new Window with a `config` and `delegate`. Using a `WindowDelegate` enables
/// you to respond to window lifecycle events - visibility, movement, and so on. It also
@ -176,13 +176,13 @@ where
{
(&mut delegate).did_load(Window {
delegate: None,
objc: objc.clone()
objc: objc.clone(),
});
}
Window {
objc: objc,
delegate: Some(delegate)
delegate: Some(delegate),
}
}
}
@ -462,7 +462,7 @@ impl<T> Window<T> {
pub fn begin_sheet<F, W>(&self, window: &Window<W>, completion: F)
where
F: Fn() + Send + Sync + 'static,
W: WindowDelegate + 'static
W: WindowDelegate + 'static,
{
let block = ConcreteBlock::new(move |_response: NSInteger| {
completion();
@ -477,7 +477,7 @@ impl<T> Window<T> {
/// Closes a sheet.
pub fn end_sheet<W>(&self, window: &Window<W>)
where
W: WindowDelegate + 'static
W: WindowDelegate + 'static,
{
unsafe {
let _: () = msg_send![&*self.objc, endSheet:&*window.objc];

View file

@ -46,7 +46,7 @@ pub enum BezelStyle {
/// Any style that's not known by this framework (e.g, if Apple
/// introduces something new).
Unknown(NSUInteger)
Unknown(NSUInteger),
}
#[cfg(feature = "appkit")]
@ -66,7 +66,7 @@ impl From<BezelStyle> for NSUInteger {
BezelStyle::SmallSquare => 10,
BezelStyle::TexturedRounded => 11,
BezelStyle::TexturedSquare => 8,
BezelStyle::Unknown(i) => i
BezelStyle::Unknown(i) => i,
}
}
}
@ -88,7 +88,7 @@ impl From<NSUInteger> for BezelStyle {
10 => Self::SmallSquare,
11 => Self::TexturedRounded,
8 => Self::TexturedSquare,
i => Self::Unknown(i)
i => Self::Unknown(i),
}
}
}

View file

@ -122,7 +122,7 @@ pub struct Button {
/// A pointer to the Objective-C runtime center Y layout constraint.
#[cfg(feature = "autolayout")]
pub center_y: LayoutAnchorY
pub center_y: LayoutAnchorY,
}
impl Button {
@ -179,7 +179,7 @@ impl Button {
#[cfg(feature = "autolayout")]
center_y: LayoutAnchorY::center(view),
objc: ObjcProperty::retain(view)
objc: ObjcProperty::retain(view),
}
}
@ -226,14 +226,14 @@ impl Button {
/// button will fire.
pub fn set_key_equivalent<'a, K>(&self, key: K)
where
K: Into<Key<'a>>
K: Into<Key<'a>>,
{
let key: Key<'a> = key.into();
self.objc.with_mut(|obj| {
let keychar = match key {
Key::Char(s) => NSString::new(s),
Key::Delete => NSString::new("\u{08}")
Key::Delete => NSString::new("\u{08}"),
};
unsafe {

View file

@ -9,14 +9,14 @@ use crate::foundation::id;
/// to, say, handle accepting an invite for a share.
#[derive(Clone, Debug)]
pub struct CKShareMetaData {
pub inner: ShareId<Object>
pub inner: ShareId<Object>,
}
impl CKShareMetaData {
/// Internal method for wrapping a system-provided `CKShareMetaData` object.
pub(crate) fn with_inner(object: id) -> Self {
CKShareMetaData {
inner: unsafe { ShareId::from_ptr(object) }
inner: unsafe { ShareId::from_ptr(object) },
}
}
}

View file

@ -58,7 +58,7 @@ fn get_effective_color(this: &Object) -> id {
NSAppearanceNameAqua,
NSAppearanceNameAccessibilityHighContrastAqua,
NSAppearanceNameDarkAqua,
NSAppearanceNameAccessibilityHighContrastDarkAqua
NSAppearanceNameAccessibilityHighContrastDarkAqua,
]);
let style: id = msg_send![appearance, bestMatchFromAppearancesWithNames:&*names];
@ -270,22 +270,22 @@ pub(crate) fn register_class() -> *const Class {
decl.add_method(sel!(colorSpace), color_space as extern "C" fn(&Object, _) -> id);
decl.add_method(
sel!(colorUsingColorSpace:),
color_using_color_space as extern "C" fn(&Object, _, id) -> id
color_using_color_space as extern "C" fn(&Object, _, id) -> id,
);
decl.add_method(sel!(colorSpaceName), color_space_name as extern "C" fn(&Object, _) -> id);
decl.add_method(
sel!(colorUsingColorSpaceName:),
color_using_color_space_name as extern "C" fn(&Object, _, id) -> id
color_using_color_space_name as extern "C" fn(&Object, _, id) -> id,
);
decl.add_method(
sel!(numberOfComponents),
number_of_components as extern "C" fn(&Object, _) -> NSInteger
number_of_components as extern "C" fn(&Object, _) -> NSInteger,
);
decl.add_method(sel!(getComponents:), get_components as extern "C" fn(&Object, _, CGFloat));
decl.add_method(
sel!(getRed:green:blue:alpha:),
get_rgba as extern "C" fn(&Object, _, CGFloat, CGFloat, CGFloat, CGFloat)
get_rgba as extern "C" fn(&Object, _, CGFloat, CGFloat, CGFloat, CGFloat),
);
decl.add_method(sel!(redComponent), red_component as extern "C" fn(&Object, _) -> CGFloat);
decl.add_method(sel!(greenComponent), green_component as extern "C" fn(&Object, _) -> CGFloat);
@ -294,36 +294,36 @@ pub(crate) fn register_class() -> *const Class {
decl.add_method(sel!(hueComponent), hue_component as extern "C" fn(&Object, _) -> CGFloat);
decl.add_method(
sel!(saturationComponent),
saturation_component as extern "C" fn(&Object, _) -> CGFloat
saturation_component as extern "C" fn(&Object, _) -> CGFloat,
);
decl.add_method(
sel!(brightnessComponent),
brightness_component as extern "C" fn(&Object, _) -> CGFloat
brightness_component as extern "C" fn(&Object, _) -> CGFloat,
);
decl.add_method(
sel!(getHue:saturation:brightness:alpha:),
get_hsba as extern "C" fn(&Object, _, CGFloat, CGFloat, CGFloat, CGFloat)
get_hsba as extern "C" fn(&Object, _, CGFloat, CGFloat, CGFloat, CGFloat),
);
decl.add_method(sel!(whiteComponent), white_component as extern "C" fn(&Object, _) -> CGFloat);
decl.add_method(
sel!(getWhite:alpha:),
get_white as extern "C" fn(&Object, _, CGFloat, CGFloat)
get_white as extern "C" fn(&Object, _, CGFloat, CGFloat),
);
decl.add_method(sel!(cyanComponent), cyan_component as extern "C" fn(&Object, _) -> CGFloat);
decl.add_method(
sel!(magentaComponent),
magenta_component as extern "C" fn(&Object, _) -> CGFloat
magenta_component as extern "C" fn(&Object, _) -> CGFloat,
);
decl.add_method(
sel!(yellowComponent),
yellow_component as extern "C" fn(&Object, _) -> CGFloat
yellow_component as extern "C" fn(&Object, _) -> CGFloat,
);
decl.add_method(sel!(blackComponent), black_component as extern "C" fn(&Object, _) -> CGFloat);
decl.add_method(
sel!(getCyan:magenta:yellow:black:alpha:),
get_cmyk as extern "C" fn(&Object, _, CGFloat, CGFloat, CGFloat, CGFloat, CGFloat)
get_cmyk as extern "C" fn(&Object, _, CGFloat, CGFloat, CGFloat, CGFloat, CGFloat),
);
decl.add_method(sel!(alphaComponent), alpha_component as extern "C" fn(&Object, _) -> CGFloat);
@ -335,24 +335,24 @@ pub(crate) fn register_class() -> *const Class {
decl.add_method(
sel!(highlightWithLevel:),
highlight_with_level as extern "C" fn(&Object, _, CGFloat) -> id
highlight_with_level as extern "C" fn(&Object, _, CGFloat) -> id,
);
decl.add_method(
sel!(shadowWithLevel:),
shadow_with_level as extern "C" fn(&Object, _, CGFloat) -> id
shadow_with_level as extern "C" fn(&Object, _, CGFloat) -> id,
);
decl.add_method(
sel!(colorWithAlphaComponent:),
color_with_alpha_component as extern "C" fn(&Object, _, CGFloat) -> id
color_with_alpha_component as extern "C" fn(&Object, _, CGFloat) -> id,
);
decl.add_method(
sel!(blendedColorWithFraction:ofColor:),
blended_color as extern "C" fn(&Object, _, CGFloat, id) -> id
blended_color as extern "C" fn(&Object, _, CGFloat, id) -> id,
);
decl.add_method(
sel!(colorWithSystemEffect:),
color_with_system_effect as extern "C" fn(&Object, _, NSInteger) -> id
color_with_system_effect as extern "C" fn(&Object, _, NSInteger) -> id,
);
decl.add_ivar::<id>(AQUA_LIGHT_COLOR_NORMAL_CONTRAST);

View file

@ -31,7 +31,7 @@ mod appkit_dynamic_color;
#[cfg(feature = "appkit")]
use appkit_dynamic_color::{
AQUA_DARK_COLOR_HIGH_CONTRAST, AQUA_DARK_COLOR_NORMAL_CONTRAST, AQUA_LIGHT_COLOR_HIGH_CONTRAST,
AQUA_LIGHT_COLOR_NORMAL_CONTRAST
AQUA_LIGHT_COLOR_NORMAL_CONTRAST,
};
/// Represents a rendering style - dark mode or light mode.
@ -45,7 +45,7 @@ pub enum Theme {
Light,
/// Dark mode.
Dark
Dark,
}
/// Represents the contrast level for a rendering context.
@ -55,7 +55,7 @@ pub enum Contrast {
Normal,
/// The high contrast level for the system.
High
High,
}
/// A `Style` is passed to you when doing dynamic color calculations. You can opt to
@ -67,7 +67,7 @@ pub struct Style {
pub theme: Theme,
/// Represents the current contrast level for where this color may render.
pub contrast: Contrast
pub contrast: Contrast,
}
/// Represents a Color. You can create custom colors using the various
@ -235,7 +235,7 @@ pub enum Color {
/// The background color that should appear under a page per the system theme.
#[cfg(feature = "appkit")]
MacOSUnderPageBackgroundColor
MacOSUnderPageBackgroundColor,
}
impl Color {
@ -337,7 +337,7 @@ impl Color {
#[cfg(feature = "appkit")]
pub fn dynamic<F>(handler: F) -> Self
where
F: Fn(Style) -> Color + 'static
F: Fn(Style) -> Color + 'static,
{
// It's *possible* that we shouldn't cache these up-front and let them be truly dynamically
// allocated, but this is fine for now (and more predictable, even if perhaps wrong). I'm
@ -350,7 +350,7 @@ impl Color {
(&mut *color).set_ivar(AQUA_LIGHT_COLOR_NORMAL_CONTRAST, {
let color: id = handler(Style {
theme: Theme::Light,
contrast: Contrast::Normal
contrast: Contrast::Normal,
})
.into();
@ -360,7 +360,7 @@ impl Color {
(&mut *color).set_ivar(AQUA_LIGHT_COLOR_HIGH_CONTRAST, {
let color: id = handler(Style {
theme: Theme::Light,
contrast: Contrast::High
contrast: Contrast::High,
})
.into();
@ -370,7 +370,7 @@ impl Color {
(&mut *color).set_ivar(AQUA_DARK_COLOR_NORMAL_CONTRAST, {
let color: id = handler(Style {
theme: Theme::Dark,
contrast: Contrast::Normal
contrast: Contrast::Normal,
})
.into();
@ -380,7 +380,7 @@ impl Color {
(&mut *color).set_ivar(AQUA_DARK_COLOR_HIGH_CONTRAST, {
let color: id = handler(Style {
theme: Theme::Light,
contrast: Contrast::Normal
contrast: Contrast::Normal,
})
.into();
@ -517,6 +517,6 @@ unsafe fn to_objc(obj: &Color) -> id {
Color::MacOSWindowBackgroundColor => system_color_with_fallback!(color, windowBackgroundColor, clearColor),
#[cfg(feature = "appkit")]
Color::MacOSUnderPageBackgroundColor => system_color_with_fallback!(color, underPageBackgroundColor, clearColor)
Color::MacOSUnderPageBackgroundColor => system_color_with_fallback!(color, underPageBackgroundColor, clearColor),
}
}

View file

@ -19,7 +19,7 @@ pub enum ControlSize {
/// A large control. Only available on macOS 11.0+.
/// If you pass this to the `set_control_size` method on the `Control` trait, it will
/// transparently map to `Regular` on 10.15 and below.
Large
Large,
}
/// A trait that view wrappers must conform to. Enables managing the subview tree.
@ -44,8 +44,8 @@ pub trait Control: ObjcAccess {
ControlSize::Large => match crate::utils::os::is_minimum_version(11) {
true => 3,
false => 0
}
false => 0,
},
};
self.with_backing_obj_mut(|obj| unsafe {

View file

@ -213,7 +213,7 @@ impl UserDefaults {
println!("Unexpected code type found: {}", _x);
None
}
},
};
}

View file

@ -23,7 +23,7 @@ pub enum Value {
/// Represents Data (bytes). You can use this to store arbitrary things that aren't supported
/// above. You're responsible for moving things back and forth to the necessary types.
Data(Vec<u8>)
Data(Vec<u8>),
}
impl Value {
@ -36,7 +36,7 @@ impl Value {
pub fn is_boolean(&self) -> bool {
match self {
Value::Bool(_) => true,
_ => false
_ => false,
}
}
@ -44,7 +44,7 @@ impl Value {
pub fn as_bool(&self) -> Option<bool> {
match self {
Value::Bool(v) => Some(*v),
_ => None
_ => None,
}
}
@ -52,7 +52,7 @@ impl Value {
pub fn is_string(&self) -> bool {
match self {
Value::String(_) => true,
_ => false
_ => false,
}
}
@ -60,7 +60,7 @@ impl Value {
pub fn as_str(&self) -> Option<&str> {
match self {
Value::String(s) => Some(s),
_ => None
_ => None,
}
}
@ -68,7 +68,7 @@ impl Value {
pub fn is_integer(&self) -> bool {
match self {
Value::Integer(_) => true,
_ => false
_ => false,
}
}
@ -76,7 +76,7 @@ impl Value {
pub fn as_i32(&self) -> Option<i32> {
match self {
Value::Integer(i) => Some(*i as i32),
_ => None
_ => None,
}
}
@ -84,7 +84,7 @@ impl Value {
pub fn as_i64(&self) -> Option<i64> {
match self {
Value::Integer(i) => Some(*i as i64),
_ => None
_ => None,
}
}
@ -92,7 +92,7 @@ impl Value {
pub fn is_float(&self) -> bool {
match self {
Value::Float(_) => true,
_ => false
_ => false,
}
}
@ -100,7 +100,7 @@ impl Value {
pub fn as_f32(&self) -> Option<f32> {
match self {
Value::Float(f) => Some(*f as f32),
_ => None
_ => None,
}
}
@ -108,7 +108,7 @@ impl Value {
pub fn as_f64(&self) -> Option<f64> {
match self {
Value::Float(f) => Some(*f as f64),
_ => None
_ => None,
}
}
@ -116,7 +116,7 @@ impl Value {
pub fn is_data(&self) -> bool {
match self {
Value::Data(_) => true,
_ => false
_ => false,
}
}
@ -125,7 +125,7 @@ impl Value {
pub fn as_data(&self) -> Option<&[u8]> {
match self {
Value::Data(data) => Some(data),
_ => None
_ => None,
}
}
}
@ -140,14 +140,14 @@ impl From<Value> for id {
Value::String(s) => NSString::new(&s).into(),
Value::Float(f) => NSNumber::float(f).into(),
Value::Integer(i) => NSNumber::integer(i).into(),
Value::Data(data) => NSData::new(data).into()
Value::Data(data) => NSData::new(data).into(),
}
}
}
impl<K> From<HashMap<K, Value>> for NSMutableDictionary
where
K: AsRef<str>
K: AsRef<str>,
{
/// Translates a `HashMap` of `Value`s into an `NSDictionary`.
fn from(map: HashMap<K, Value>) -> Self {

View file

@ -31,7 +31,7 @@ pub enum DragOperation {
Move,
/// The data can be deleted.
Delete // All of the above.
Delete, // All of the above.
// @TODO: NSUIntegerMax, a tricky beast
// Every
}
@ -45,7 +45,7 @@ impl From<DragOperation> for NSUInteger {
DragOperation::Generic => 4,
DragOperation::Private => 8,
DragOperation::Move => 16,
DragOperation::Delete => 32
DragOperation::Delete => 32,
}
}
}
@ -54,7 +54,7 @@ impl From<DragOperation> for NSUInteger {
/// this only provides getters - merely a Rust-y way to grab what you need.
#[derive(Clone, Debug)]
pub struct DragInfo {
pub info: ShareId<Object>
pub info: ShareId<Object>,
}
impl DragInfo {

View file

@ -23,7 +23,7 @@ pub struct Error {
pub domain: String,
/// Maps over to `[NSError localizedDescription]`.
pub description: String
pub description: String,
}
impl Error {
@ -42,7 +42,7 @@ impl Error {
Error {
code,
domain: domain.to_string(),
description: description.to_string()
description: description.to_string(),
}
}

View file

@ -19,7 +19,7 @@ pub enum EventModifierFlag {
Command,
/// Device independent flags mask.
DeviceIndependentFlagsMask
DeviceIndependentFlagsMask,
}
impl From<EventModifierFlag> for NSUInteger {
@ -29,7 +29,7 @@ impl From<EventModifierFlag> for NSUInteger {
EventModifierFlag::Control => 1 << 18,
EventModifierFlag::Option => 1 << 19,
EventModifierFlag::Command => 1 << 20,
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000,
}
}
}
@ -41,7 +41,7 @@ impl From<&EventModifierFlag> for NSUInteger {
EventModifierFlag::Control => 1 << 18,
EventModifierFlag::Option => 1 << 19,
EventModifierFlag::Command => 1 << 20,
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000
EventModifierFlag::DeviceIndependentFlagsMask => 0xffff0000,
}
}
}
@ -50,5 +50,5 @@ impl From<&EventModifierFlag> for NSUInteger {
#[derive(Clone, Copy, Debug)]
pub enum EventType {
/// A keydown event.
KeyDown
KeyDown,
}

View file

@ -27,7 +27,7 @@ pub enum ModalResponse {
SecondButtonReturned,
/// The third button in the dialog was clicked.
ThirdButtonReturned
ThirdButtonReturned,
}
impl From<NSInteger> for ModalResponse {
@ -47,7 +47,7 @@ impl From<NSInteger> for ModalResponse {
// gracefully handle.
e => {
panic!("Unknown NSModalResponse sent back! {}", e);
}
},
}
}
}
@ -68,7 +68,7 @@ pub enum SearchPathDomainMask {
Domain,
/// Search all domains. Not typically used these days.
AllDomains
AllDomains,
}
impl From<SearchPathDomainMask> for NSUInteger {
@ -78,7 +78,7 @@ impl From<SearchPathDomainMask> for NSUInteger {
SearchPathDomainMask::Local => 2,
SearchPathDomainMask::Network => 4,
SearchPathDomainMask::Domain => 8,
SearchPathDomainMask::AllDomains => 0x0ffff
SearchPathDomainMask::AllDomains => 0x0ffff,
}
}
}
@ -172,7 +172,7 @@ pub enum SearchPathDirectory {
AllLibraries,
/// The Trash directory.
Trash
Trash,
}
impl From<SearchPathDirectory> for NSUInteger {
@ -204,7 +204,7 @@ impl From<SearchPathDirectory> for NSUInteger {
SearchPathDirectory::ItemReplacement => 99,
SearchPathDirectory::AllApplications => 100,
SearchPathDirectory::AllLibraries => 101,
SearchPathDirectory::Trash => 102
SearchPathDirectory::Trash => 102,
}
}
}

View file

@ -19,7 +19,7 @@ pub struct FileSavePanel {
pub delegate: ShareId<Object>,
/// Whether the user can choose files. Defaults to `true`.
pub can_create_directories: bool
pub can_create_directories: bool,
}
impl Default for FileSavePanel {
@ -41,7 +41,7 @@ impl FileSavePanel {
delegate: unsafe { ShareId::from_ptr(msg_send![class!(NSObject), new]) },
can_create_directories: true
can_create_directories: true,
}
}

View file

@ -38,7 +38,7 @@ pub struct FileSelectPanel {
/// When the value of this property is true, the user may select multiple items from the
/// browser. Defaults to `false`.
pub allows_multiple_selection: bool
pub allows_multiple_selection: bool,
}
impl Default for FileSelectPanel {
@ -63,7 +63,7 @@ impl FileSelectPanel {
can_choose_files: true,
can_choose_directories: false,
resolves_aliases: true,
allows_multiple_selection: true
allows_multiple_selection: true,
}
}
@ -135,7 +135,7 @@ impl FileSelectPanel {
/// script) or can't easily pass one to use as a sheet.
pub fn show<F>(&self, handler: F)
where
F: Fn(Vec<NSURL>) + 'static
F: Fn(Vec<NSURL>) + 'static,
{
let panel = self.panel.clone();
let completion = ConcreteBlock::new(move |result: NSInteger| {
@ -143,7 +143,7 @@ impl FileSelectPanel {
handler(match response {
ModalResponse::Ok => get_urls(&panel),
_ => Vec::new()
_ => Vec::new(),
});
});
@ -171,7 +171,7 @@ impl FileSelectPanel {
/// retain/ownership rules here.
pub fn begin_sheet<T, F>(&self, window: &Window<T>, handler: F)
where
F: Fn(Vec<NSURL>) + 'static
F: Fn(Vec<NSURL>) + 'static,
{
let panel = self.panel.clone();
let completion = ConcreteBlock::new(move |result: NSInteger| {
@ -179,7 +179,7 @@ impl FileSelectPanel {
handler(match response {
ModalResponse::Ok => get_urls(&panel),
_ => Vec::new()
_ => Vec::new(),
});
});

View file

@ -30,7 +30,7 @@ impl AutoReleasePool {
/// with an autorelease pool - otherwise your memory footprint will continue to grow.
pub fn run<F>(handler: F)
where
F: Fn() + 'static
F: Fn() + 'static,
{
let _pool = AutoReleasePool::new();
handler();

View file

@ -122,7 +122,7 @@ impl ClassMap {
#[inline(always)]
pub fn load_or_register_class<F>(superclass_name: &'static str, subclass_name: &'static str, config: F) -> *const Class
where
F: Fn(&mut ClassDecl) + 'static
F: Fn(&mut ClassDecl) + 'static,
{
if let Some(subclass) = CLASSES.load_subclass(subclass_name, superclass_name) {
return subclass;
@ -145,7 +145,7 @@ where
"Subclass of type {}_{} could not be allocated.",
subclass_name, superclass_name
);
}
},
}
}

View file

@ -58,7 +58,7 @@ pub fn to_bool(result: BOOL) -> bool {
#[cfg(not(target_arch = "aarch64"))]
_ => {
std::unreachable!();
}
},
}
}

View file

@ -19,7 +19,7 @@ const UTF8_ENCODING: usize = 4;
pub struct NSString<'a> {
/// A reference to the backing `NSString`.
pub objc: Id<Object>,
phantom: PhantomData<&'a ()>
phantom: PhantomData<&'a ()>,
}
impl<'a> NSString<'a> {
@ -34,7 +34,7 @@ impl<'a> NSString<'a> {
])
},
phantom: PhantomData
phantom: PhantomData,
}
}
@ -50,7 +50,7 @@ impl<'a> NSString<'a> {
])
},
phantom: PhantomData
phantom: PhantomData,
}
}
@ -59,7 +59,7 @@ impl<'a> NSString<'a> {
pub fn retain(object: id) -> Self {
NSString {
objc: unsafe { Id::from_ptr(object) },
phantom: PhantomData
phantom: PhantomData,
}
}
@ -67,7 +67,7 @@ impl<'a> NSString<'a> {
pub fn from_retained(object: id) -> Self {
NSString {
objc: unsafe { Id::from_retained_ptr(object) },
phantom: PhantomData
phantom: PhantomData,
}
}

View file

@ -16,7 +16,7 @@ pub enum NSURLBookmarkCreationOption {
/// When combined with the NSURLBookmarkCreationOptions::SecurityScoped option, specifies that you
/// want to create a security-scoped bookmark that, when resolved, provides a security-scoped URL allowing
/// read-only access to a file-system resource.
SecurityScopedReadOnly
SecurityScopedReadOnly,
}
impl From<NSURLBookmarkCreationOption> for NSUInteger {
@ -25,7 +25,7 @@ impl From<NSURLBookmarkCreationOption> for NSUInteger {
NSURLBookmarkCreationOption::Minimal => 1u64 << 9,
NSURLBookmarkCreationOption::SuitableForBookmarkFile => 1u64 << 10,
NSURLBookmarkCreationOption::SecurityScoped => 1 << 11,
NSURLBookmarkCreationOption::SecurityScopedReadOnly => 1 << 12
NSURLBookmarkCreationOption::SecurityScopedReadOnly => 1 << 12,
}
}
}
@ -36,7 +36,7 @@ impl From<&NSURLBookmarkCreationOption> for NSUInteger {
NSURLBookmarkCreationOption::Minimal => 1u64 << 9,
NSURLBookmarkCreationOption::SuitableForBookmarkFile => 1u64 << 10,
NSURLBookmarkCreationOption::SecurityScoped => 1 << 11,
NSURLBookmarkCreationOption::SecurityScopedReadOnly => 1 << 12
NSURLBookmarkCreationOption::SecurityScopedReadOnly => 1 << 12,
}
}
}
@ -52,7 +52,7 @@ pub enum NSURLBookmarkResolutionOption {
/// Specifies that the security scope, applied to the bookmark when it was created, should
/// be used during resolution of the bookmark data.
SecurityScoped
SecurityScoped,
}
impl From<NSURLBookmarkResolutionOption> for NSUInteger {
@ -60,7 +60,7 @@ impl From<NSURLBookmarkResolutionOption> for NSUInteger {
match flag {
NSURLBookmarkResolutionOption::WithoutUI => 1u64 << 8,
NSURLBookmarkResolutionOption::WithoutMounting => 1u64 << 9,
NSURLBookmarkResolutionOption::SecurityScoped => 1 << 10
NSURLBookmarkResolutionOption::SecurityScoped => 1 << 10,
}
}
}

View file

@ -32,7 +32,7 @@ pub use resource_keys::{NSURLFileResource, NSURLResourceKey, NSUbiquitousItemDow
pub struct NSURL<'a> {
/// A reference to the backing `NSURL`.
pub objc: ShareId<Object>,
phantom: PhantomData<&'a ()>
phantom: PhantomData<&'a ()>,
}
impl<'a> NSURL<'a> {
@ -41,7 +41,7 @@ impl<'a> NSURL<'a> {
pub fn retain(object: id) -> Self {
NSURL {
objc: unsafe { ShareId::from_ptr(object) },
phantom: PhantomData
phantom: PhantomData,
}
}
@ -49,7 +49,7 @@ impl<'a> NSURL<'a> {
pub fn from_retained(object: id) -> Self {
NSURL {
objc: unsafe { ShareId::from_retained_ptr(object) },
phantom: PhantomData
phantom: PhantomData,
}
}
@ -60,7 +60,7 @@ impl<'a> NSURL<'a> {
Self {
objc: unsafe { ShareId::from_ptr(msg_send![class!(NSURL), URLWithString:&*url]) },
phantom: PhantomData
phantom: PhantomData,
}
}
@ -91,7 +91,7 @@ impl<'a> NSURL<'a> {
&self,
options: &[NSURLBookmarkCreationOption],
resource_value_keys: &[NSURLResourceKey],
relative_to_url: Option<NSURL>
relative_to_url: Option<NSURL>,
) -> Result<NSData, Box<dyn Error>> {
let mut opts: NSUInteger = 0;
for mask in options {
@ -118,7 +118,7 @@ impl<'a> NSURL<'a> {
relativeToURL:nil
error:nil
]
}
},
});
// Check for errors...
@ -132,7 +132,7 @@ impl<'a> NSURL<'a> {
data: NSData,
options: &[NSURLBookmarkResolutionOption],
relative_to_url: Option<NSURL>,
data_is_stale: bool
data_is_stale: bool,
) -> Result<Self, Box<dyn Error>> {
Err("LOL".into())
}

View file

@ -25,7 +25,7 @@ pub enum NSURLFileResource {
Socket,
/// The resources type is unknown.
Unknown
Unknown,
}
/// Values that describe the iCloud storage state of a file.
@ -38,7 +38,7 @@ pub enum NSUbiquitousItemDownloadingStatus {
Downloaded,
/// This item has not been downloaded yet. Initiate a download.
NotDownloaded
NotDownloaded,
}
#[derive(Debug)]
@ -166,5 +166,5 @@ pub enum NSURLResourceKey {
MayHaveExtendedAttributes,
MayShareFileContent,
UbiquitousItemIsExcludedFromSync,
VolumeSupportsFileProtection
VolumeSupportsFileProtection,
}

View file

@ -16,7 +16,7 @@ pub struct Rect {
pub width: f64,
/// Height, in points.
pub height: f64
pub height: f64,
}
impl Rect {
@ -26,7 +26,7 @@ impl Rect {
top: top,
left: left,
width: width,
height: height
height: height,
}
}
@ -36,7 +36,7 @@ impl Rect {
top: 0.0,
left: 0.0,
width: 0.0,
height: 0.0
height: 0.0,
}
}
}
@ -53,7 +53,7 @@ impl From<CGRect> for Rect {
top: rect.origin.y as f64,
left: rect.origin.x as f64,
width: rect.size.width as f64,
height: rect.size.height as f64
height: rect.size.height as f64,
}
}
}

View file

@ -30,7 +30,7 @@ pub enum MacSystemIcon {
Remove,
/// Returns a Folder icon.
Folder
Folder,
}
extern "C" {
@ -53,7 +53,7 @@ impl MacSystemIcon {
MacSystemIcon::PreferencesUserAccounts => NSImageNameUserAccounts,
MacSystemIcon::Add => NSImageNameAddTemplate,
MacSystemIcon::Remove => NSImageNameRemoveTemplate,
MacSystemIcon::Folder => NSImageNameFolder
MacSystemIcon::Folder => NSImageNameFolder,
}
}
}
@ -66,7 +66,7 @@ impl MacSystemIcon {
MacSystemIcon::PreferencesUserAccounts => SFSymbol::AtSymbol.to_str(),
MacSystemIcon::Add => SFSymbol::Plus.to_str(),
MacSystemIcon::Remove => SFSymbol::Minus.to_str(),
MacSystemIcon::Folder => SFSymbol::FolderFilled.to_str()
MacSystemIcon::Folder => SFSymbol::FolderFilled.to_str(),
}
}
}
@ -85,7 +85,7 @@ pub enum SFSymbol {
SquareAndArrowUpOnSquareFill,
SquareAndArrowDownOnSquare,
SquareAndArrowDownOnSquareFill,
SquareDashed
SquareDashed,
}
impl SFSymbol {
@ -103,7 +103,7 @@ impl SFSymbol {
Self::SquareAndArrowUpOnSquareFill => "square.and.arrow.up.on.square.fill",
Self::SquareAndArrowDownOnSquare => "square.and.arrow.down.on.square",
Self::SquareAndArrowDownOnSquareFill => "square.and.arrow.down.on.square.fill",
Self::SquareDashed => "square.dashed"
Self::SquareDashed => "square.dashed",
}
}
}

View file

@ -8,7 +8,7 @@ use block::ConcreteBlock;
use core_graphics::context::{CGContext, CGContextRef};
use core_graphics::{
base::CGFloat,
geometry::{CGPoint, CGRect, CGSize}
geometry::{CGPoint, CGRect, CGSize},
};
use super::icons::*;
@ -28,7 +28,7 @@ pub enum ResizeBehavior {
Stretch,
/// Center and then let whatever else flow around it.
Center
Center,
}
fn max_cgfloat(x: CGFloat, y: CGFloat) -> CGFloat {
@ -38,7 +38,7 @@ fn max_cgfloat(x: CGFloat, y: CGFloat) -> CGFloat {
match x > y {
true => x,
false => y
false => y,
}
}
@ -49,7 +49,7 @@ fn min_cgfloat(x: CGFloat, y: CGFloat) -> CGFloat {
match x < y {
true => x,
false => y
false => y,
}
}
@ -90,7 +90,7 @@ impl ResizeBehavior {
ResizeBehavior::Center => {
scales.width = 1.;
scales.height = 1.;
}
},
}
let mut result = source;
@ -113,7 +113,7 @@ pub struct DrawConfig {
pub target: (CGFloat, CGFloat),
/// The type of resizing to use during drawing and scaling.
pub resize: ResizeBehavior
pub resize: ResizeBehavior,
}
/// Wraps `NSImage` under AppKit, and `UIImage` on under UIKit (iOS and tvOS). Can be used to display images, icons,
@ -195,7 +195,7 @@ impl Image {
false => {
let icon = icon.to_id();
msg_send![Self::class(), imageNamed: icon]
}
},
})
})
}
@ -232,7 +232,7 @@ impl Image {
#[cfg(all(feature = "uikit", not(feature = "appkit")))]
panic!("SFSymbols are only supported on macOS 11.0 and up.");
}
},
})
})
}
@ -244,7 +244,7 @@ impl Image {
#[cfg(feature = "appkit")]
pub fn draw<F>(config: DrawConfig, handler: F) -> Self
where
F: Fn(CGRect, &CGContextRef) -> bool + 'static
F: Fn(CGRect, &CGContextRef) -> bool + 'static,
{
let source_frame = CGRect::new(&CGPoint::new(0., 0.), &CGSize::new(config.source.0, config.source.1));
@ -261,7 +261,7 @@ impl Image {
context.translate(resized_frame.origin.x, resized_frame.origin.y);
context.scale(
resized_frame.size.width / config.source.0,
resized_frame.size.height / config.source.1
resized_frame.size.height / config.source.1,
);
let result = handler(resized_frame, &context);
@ -270,7 +270,7 @@ impl Image {
match result {
true => YES,
false => NO
false => NO,
}
});
let block = block.copy();

View file

@ -90,7 +90,7 @@ pub struct ImageView {
/// A pointer to the Objective-C runtime center Y layout constraint.
#[cfg(feature = "autolayout")]
pub center_y: LayoutAnchorY
pub center_y: LayoutAnchorY,
}
impl Default for ImageView {
@ -135,7 +135,7 @@ impl ImageView {
#[cfg(feature = "autolayout")]
center_y: LayoutAnchorY::center(view),
objc: ObjcProperty::retain(view)
objc: ObjcProperty::retain(view),
}
}

View file

@ -35,7 +35,7 @@ extern "C" fn text_should_begin_editing<T: TextFieldDelegate>(this: &mut Object,
match view.text_should_begin_editing(s.to_str()) {
true => YES,
false => NO
false => NO,
}
}
@ -44,7 +44,7 @@ extern "C" fn text_should_end_editing<T: TextFieldDelegate>(this: &mut Object, _
let s = NSString::retain(unsafe { msg_send![this, stringValue] });
match view.text_should_end_editing(s.to_str()) {
true => YES,
false => NO
false => NO,
}
}
@ -74,20 +74,20 @@ pub(crate) fn register_view_class_with_delegate<T: TextFieldDelegate>(instance:
decl.add_method(
sel!(textDidEndEditing:),
text_did_end_editing::<T> as extern "C" fn(&mut Object, _, _)
text_did_end_editing::<T> as extern "C" fn(&mut Object, _, _),
);
decl.add_method(
sel!(textDidBeginEditing:),
text_did_begin_editing::<T> as extern "C" fn(&mut Object, _, _)
text_did_begin_editing::<T> as extern "C" fn(&mut Object, _, _),
);
decl.add_method(sel!(textDidChange:), text_did_change::<T> as extern "C" fn(&mut Object, _, _));
decl.add_method(
sel!(textShouldBeginEditing:),
text_should_begin_editing::<T> as extern "C" fn(&mut Object, Sel, id) -> BOOL
text_should_begin_editing::<T> as extern "C" fn(&mut Object, Sel, id) -> BOOL,
);
decl.add_method(
sel!(textShouldEndEditing:),
text_should_end_editing::<T> as extern "C" fn(&mut Object, Sel, id) -> BOOL
text_should_end_editing::<T> as extern "C" fn(&mut Object, Sel, id) -> BOOL,
);
})
}

View file

@ -138,7 +138,7 @@ pub struct TextField<T = ()> {
/// A pointer to the Objective-C runtime center Y layout constraint.
#[cfg(feature = "autolayout")]
pub center_y: LayoutAnchorY
pub center_y: LayoutAnchorY,
}
impl Default for TextField {
@ -185,14 +185,14 @@ impl TextField {
center_x: LayoutAnchorX::center(view),
#[cfg(feature = "autolayout")]
center_y: LayoutAnchorY::center(view)
center_y: LayoutAnchorY::center(view),
}
}
}
impl<T> TextField<T>
where
T: TextFieldDelegate + 'static
T: TextFieldDelegate + 'static,
{
/// Initializes a new TextField with a given `TextFieldDelegate`. This enables you to respond to events
/// and customize the view as a module, similar to class-based systems.
@ -238,7 +238,7 @@ where
center_x: LayoutAnchorX::center(label),
#[cfg(feature = "autolayout")]
center_y: LayoutAnchorY::center(label)
center_y: LayoutAnchorY::center(label),
};
(&mut delegate).did_load(label.clone_as_handle());
@ -285,7 +285,7 @@ impl<T> TextField<T> {
center_x: self.center_x.clone(),
#[cfg(feature = "autolayout")]
center_y: self.center_y.clone()
center_y: self.center_y.clone(),
}
}

View file

@ -49,7 +49,7 @@ impl fmt::Debug for Action {
#[derive(Debug)]
pub struct TargetActionHandler {
action: Box<Action>,
invoker: ShareId<Object>
invoker: ShareId<Object>,
}
impl TargetActionHandler {
@ -71,7 +71,7 @@ impl TargetActionHandler {
TargetActionHandler {
invoker: invoker,
action: unsafe { Box::from_raw(ptr) }
action: unsafe { Box::from_raw(ptr) },
}
}
}

View file

@ -8,7 +8,7 @@ pub enum Key<'a> {
Delete,
/// Whatever character you want.
Char(&'a str)
Char(&'a str),
}
impl<'a> From<&'a str> for Key<'a> {

View file

@ -35,21 +35,21 @@ use crate::utils::properties::ObjcProperty;
#[derive(Clone, Debug)]
pub struct Layer {
/// The underlying layer pointer.
pub objc: ObjcProperty
pub objc: ObjcProperty,
}
impl Layer {
/// Creates a new `CALayer` and retains it.
pub fn new() -> Self {
Layer {
objc: ObjcProperty::retain(unsafe { msg_send![class!(CALayer), new] })
objc: ObjcProperty::retain(unsafe { msg_send![class!(CALayer), new] }),
}
}
/// Wraps an existing (already retained) `CALayer`.
pub fn wrap(layer: id) -> Self {
Layer {
objc: ObjcProperty::from_retained(layer)
objc: ObjcProperty::from_retained(layer),
}
}

View file

@ -12,7 +12,7 @@ pub enum LayoutConstraintOrientation {
/// Represents an unknown value. This should never be constructed, but acts as a guard against
/// a change in representation on the framework side. If a new value was ever introduced, it's
/// caught here, and applications can handle it themselves if need be.
Unknown(NSInteger)
Unknown(NSInteger),
}
impl From<NSInteger> for LayoutConstraintOrientation {
@ -20,7 +20,7 @@ impl From<NSInteger> for LayoutConstraintOrientation {
match i {
0 => Self::Horizontal,
1 => Self::Vertical,
i => Self::Unknown(i)
i => Self::Unknown(i),
}
}
}
@ -40,7 +40,7 @@ pub enum LayoutRelation {
/// Represents an unknown value. This should never be constructed, but acts as a guard against
/// a change in representation on the framework side. If a new value was ever introduced, it's
/// caught here, and applications can handle it themselves if need be.
Unknown(NSInteger)
Unknown(NSInteger),
}
impl From<NSInteger> for LayoutRelation {
@ -49,7 +49,7 @@ impl From<NSInteger> for LayoutRelation {
-1 => Self::LessThanOrEqual,
0 => Self::Equal,
1 => Self::GreaterThanOrEqual,
i => Self::Unknown(i)
i => Self::Unknown(i),
}
}
}
@ -108,7 +108,7 @@ pub enum LayoutAttribute {
/// Represents an unknown value. This should never be constructed, but acts as a guard against
/// a change in representation on the framework side. If a new value was ever introduced, it's
/// caught here, and applications can handle it themselves if need be.
Unknown(NSInteger)
Unknown(NSInteger),
}
impl From<NSInteger> for LayoutAttribute {
@ -127,7 +127,7 @@ impl From<NSInteger> for LayoutAttribute {
11 => Self::LastBaseline,
12 => Self::FirstBaseline,
0 => Self::NotAnAttribute,
i => Self::Unknown(i)
i => Self::Unknown(i),
}
}
}
@ -182,7 +182,7 @@ pub enum LayoutFormat {
/// Represents an unknown value. This should never be constructed, but acts as a guard against
/// a change in representation on the framework side. If a new value was ever introduced, it's
/// caught here, and applications can handle it themselves if need be.
Unknown(NSUInteger)
Unknown(NSUInteger),
}
impl From<NSUInteger> for LayoutFormat {
@ -200,7 +200,7 @@ impl From<NSUInteger> for LayoutFormat {
0 => Self::DirectionLeadingToTrailing,
65536 => Self::DirectionLeftToRight,
131072 => Self::DirectionRightToLeft,
i => Self::Unknown(i)
i => Self::Unknown(i),
}
}
}
@ -215,5 +215,5 @@ pub enum LayoutPriority {
High,
/// Low priority.
Low
Low,
}

View file

@ -34,7 +34,7 @@ pub struct LayoutConstraint {
/// An animator proxy that can be used inside animation contexts.
/// This is currently only supported on macOS with the `appkit` feature.
#[cfg(all(feature = "appkit", target_os = "macos"))]
pub animator: LayoutConstraintAnimatorProxy
pub animator: LayoutConstraintAnimatorProxy,
}
impl LayoutConstraint {
@ -47,7 +47,7 @@ impl LayoutConstraint {
constraint: unsafe { ShareId::from_ptr(object) },
offset: 0.0,
multiplier: 0.0,
priority: 0.0
priority: 0.0,
}
}
@ -66,7 +66,7 @@ impl LayoutConstraint {
constraint: self.constraint,
offset: offset,
multiplier: self.multiplier,
priority: self.priority
priority: self.priority,
}
}

View file

@ -25,7 +25,7 @@ pub enum LayoutAnchorDimension {
Width(ShareId<Object>),
/// Represents a Height anchor.
Height(ShareId<Object>)
Height(ShareId<Object>),
}
impl Default for LayoutAnchorDimension {
@ -87,7 +87,7 @@ impl LayoutAnchorDimension {
/// wrong.
fn constraint_with<F>(&self, anchor_to: &LayoutAnchorDimension, handler: F) -> LayoutConstraint
where
F: Fn(&ShareId<Object>, &ShareId<Object>) -> id
F: Fn(&ShareId<Object>, &ShareId<Object>) -> id,
{
match (self, anchor_to) {
(Self::Width(from), Self::Width(to))
@ -105,7 +105,7 @@ impl LayoutAnchorDimension {
(_, Self::Uninitialized) => {
panic!("Attempted to create constraints with an uninitialized \"to\" dimension anchor.");
}
},
}
}

View file

@ -28,7 +28,7 @@ pub enum LayoutAnchorX {
Right(ShareId<Object>),
/// Represents a center anchor on the X axis.
Center(ShareId<Object>)
Center(ShareId<Object>),
}
impl Default for LayoutAnchorX {
@ -69,7 +69,7 @@ impl LayoutAnchorX {
/// wrong.
fn constraint_with<F>(&self, anchor_to: &LayoutAnchorX, handler: F) -> LayoutConstraint
where
F: Fn(&ShareId<Object>, &ShareId<Object>) -> id
F: Fn(&ShareId<Object>, &ShareId<Object>) -> id,
{
match (self, anchor_to) {
// The anchors that can connect to each other. These blocks could be condensed, but are
@ -153,7 +153,7 @@ impl LayoutAnchorX {
(_, Self::Uninitialized) => {
panic!("Attempted to create constraints with an uninitialized \"to\" X anchor.");
}
},
}
}

View file

@ -38,7 +38,7 @@ pub struct SafeAreaLayoutGuide {
pub center_x: LayoutAnchorX,
/// A pointer to the Objective-C runtime center Y layout constraint.
pub center_y: LayoutAnchorY
pub center_y: LayoutAnchorY,
}
impl SafeAreaLayoutGuide {
@ -48,7 +48,7 @@ impl SafeAreaLayoutGuide {
// For versions prior to Big Sur, we'll just use the default view anchors in place.
let guide: id = match os::is_minimum_version(11) {
true => unsafe { msg_send![view, layoutMarginsGuide] },
false => view
false => view,
};
Self {
@ -61,7 +61,7 @@ impl SafeAreaLayoutGuide {
width: LayoutAnchorDimension::width(guide),
height: LayoutAnchorDimension::height(guide),
center_x: LayoutAnchorX::center(guide),
center_y: LayoutAnchorY::center(guide)
center_y: LayoutAnchorY::center(guide),
}
}
}

View file

@ -19,7 +19,7 @@ pub enum LayoutAnchorY {
Bottom(ShareId<Object>),
/// Represents a center anchor for the Y axis.
Center(ShareId<Object>)
Center(ShareId<Object>),
}
impl Default for LayoutAnchorY {
@ -49,7 +49,7 @@ impl LayoutAnchorY {
/// wrong.
fn constraint_with<F>(&self, anchor_to: &LayoutAnchorY, handler: F) -> LayoutConstraint
where
F: Fn(&ShareId<Object>, &ShareId<Object>) -> id
F: Fn(&ShareId<Object>, &ShareId<Object>) -> id,
{
match (self, anchor_to) {
(Self::Top(from), Self::Top(to))
@ -72,7 +72,7 @@ impl LayoutAnchorY {
(_, Self::Uninitialized) => {
panic!("Attempted to create constraints with an uninitialized \"to\" y anchor.");
}
},
}
}

View file

@ -17,7 +17,7 @@ pub enum RowActionStyle {
Regular,
/// Use this to denote that an action is destructive.
Destructive
Destructive,
}
impl Default for RowActionStyle {
@ -30,7 +30,7 @@ impl From<RowActionStyle> for NSUInteger {
fn from(style: RowActionStyle) -> Self {
match style {
RowActionStyle::Regular => 0,
RowActionStyle::Destructive => 1
RowActionStyle::Destructive => 1,
}
}
}
@ -52,7 +52,7 @@ impl RowAction {
/// our definitions.
pub fn new<F>(title: &str, style: RowActionStyle, handler: F) -> Self
where
F: Fn(RowAction, usize) + 'static
F: Fn(RowAction, usize) + 'static,
{
let title = NSString::new(title);
let block = ConcreteBlock::new(move |action: id, row: NSUInteger| {

View file

@ -31,7 +31,7 @@ extern "C" fn view_for_column<T: ListViewDelegate>(
_: Sel,
_table_view: id,
_table_column: id,
item: NSInteger
item: NSInteger,
) -> id {
/*use core_graphics::geometry::CGRect;
unsafe {
@ -61,7 +61,7 @@ extern "C" fn will_display_cell<T: ListViewDelegate>(
_table_view: id,
_cell: id,
_column: id,
item: NSInteger
item: NSInteger,
) {
let view = load::<T>(this, LISTVIEW_DELEGATE_PTR);
view.will_display_item(item as usize);
@ -109,7 +109,7 @@ extern "C" fn row_actions_for_row<T: ListViewDelegate>(
_: Sel,
_table_view: id,
row: NSInteger,
edge: NSInteger
edge: NSInteger,
) -> id {
let edge: RowEdge = edge.into();
let view = load::<T>(this, LISTVIEW_DELEGATE_PTR);
@ -133,7 +133,7 @@ extern "C" fn enforce_normalcy(_: &Object, _: Sel) -> BOOL {
extern "C" fn dragging_entered<T: ListViewDelegate>(this: &mut Object, _: Sel, info: id) -> NSUInteger {
let view = load::<T>(this, LISTVIEW_DELEGATE_PTR);
view.dragging_entered(DragInfo {
info: unsafe { Id::from_ptr(info) }
info: unsafe { Id::from_ptr(info) },
})
.into()
}
@ -143,10 +143,10 @@ extern "C" fn prepare_for_drag_operation<T: ListViewDelegate>(this: &mut Object,
let view = load::<T>(this, LISTVIEW_DELEGATE_PTR);
match view.prepare_for_drag_operation(DragInfo {
info: unsafe { Id::from_ptr(info) }
info: unsafe { Id::from_ptr(info) },
}) {
true => YES,
false => NO
false => NO,
}
}
@ -155,10 +155,10 @@ extern "C" fn perform_drag_operation<T: ListViewDelegate>(this: &mut Object, _:
let view = load::<T>(this, LISTVIEW_DELEGATE_PTR);
match view.perform_drag_operation(DragInfo {
info: unsafe { Id::from_ptr(info) }
info: unsafe { Id::from_ptr(info) },
}) {
true => YES,
false => NO
false => NO,
}
}
@ -167,7 +167,7 @@ extern "C" fn conclude_drag_operation<T: ListViewDelegate>(this: &mut Object, _:
let view = load::<T>(this, LISTVIEW_DELEGATE_PTR);
view.conclude_drag_operation(DragInfo {
info: unsafe { Id::from_ptr(info) }
info: unsafe { Id::from_ptr(info) },
});
}
@ -176,7 +176,7 @@ extern "C" fn dragging_exited<T: ListViewDelegate>(this: &mut Object, _: Sel, in
let view = load::<T>(this, LISTVIEW_DELEGATE_PTR);
view.dragging_exited(DragInfo {
info: unsafe { Id::from_ptr(info) }
info: unsafe { Id::from_ptr(info) },
});
}
@ -210,23 +210,23 @@ pub(crate) fn register_listview_class_with_delegate<T: ListViewDelegate>(instanc
// Tableview-specific
decl.add_method(
sel!(numberOfRowsInTableView:),
number_of_items::<T> as extern "C" fn(&Object, _, id) -> NSInteger
number_of_items::<T> as extern "C" fn(&Object, _, id) -> NSInteger,
);
decl.add_method(
sel!(tableView:willDisplayCell:forTableColumn:row:),
will_display_cell::<T> as extern "C" fn(&Object, _, id, id, id, NSInteger)
will_display_cell::<T> as extern "C" fn(&Object, _, id, id, id, NSInteger),
);
decl.add_method(
sel!(tableView:viewForTableColumn:row:),
view_for_column::<T> as extern "C" fn(&Object, _, id, id, NSInteger) -> id
view_for_column::<T> as extern "C" fn(&Object, _, id, id, NSInteger) -> id,
);
decl.add_method(
sel!(tableViewSelectionDidChange:),
selection_did_change::<T> as extern "C" fn(&Object, _, id)
selection_did_change::<T> as extern "C" fn(&Object, _, id),
);
decl.add_method(
sel!(tableView:rowActionsForRow:edge:),
row_actions_for_row::<T> as extern "C" fn(&Object, _, id, NSInteger, NSInteger) -> id
row_actions_for_row::<T> as extern "C" fn(&Object, _, id, NSInteger, NSInteger) -> id,
);
// A slot for some menu handling; we just let it be done here for now rather than do the
@ -234,29 +234,29 @@ pub(crate) fn register_listview_class_with_delegate<T: ListViewDelegate>(instanc
// menu.
decl.add_method(
sel!(menuNeedsUpdate:),
menu_needs_update::<T> as extern "C" fn(&Object, _, id)
menu_needs_update::<T> as extern "C" fn(&Object, _, id),
);
// Drag and drop operations (e.g, accepting files)
decl.add_method(
sel!(draggingEntered:),
dragging_entered::<T> as extern "C" fn(&mut Object, _, _) -> NSUInteger
dragging_entered::<T> as extern "C" fn(&mut Object, _, _) -> NSUInteger,
);
decl.add_method(
sel!(prepareForDragOperation:),
prepare_for_drag_operation::<T> as extern "C" fn(&mut Object, _, _) -> BOOL
prepare_for_drag_operation::<T> as extern "C" fn(&mut Object, _, _) -> BOOL,
);
decl.add_method(
sel!(performDragOperation:),
perform_drag_operation::<T> as extern "C" fn(&mut Object, _, _) -> BOOL
perform_drag_operation::<T> as extern "C" fn(&mut Object, _, _) -> BOOL,
);
decl.add_method(
sel!(concludeDragOperation:),
conclude_drag_operation::<T> as extern "C" fn(&mut Object, _, _)
conclude_drag_operation::<T> as extern "C" fn(&mut Object, _, _),
);
decl.add_method(
sel!(draggingExited:),
dragging_exited::<T> as extern "C" fn(&mut Object, _, _)
dragging_exited::<T> as extern "C" fn(&mut Object, _, _),
);
})
}

View file

@ -25,7 +25,7 @@ pub enum RowAnimation {
SlideLeft,
/// Animates in or out by sliding right.
SlideRight
SlideRight,
}
impl Into<NSUInteger> for RowAnimation {
@ -37,7 +37,7 @@ impl Into<NSUInteger> for RowAnimation {
RowAnimation::SlideUp => 0x10,
RowAnimation::SlideDown => 0x20,
RowAnimation::SlideLeft => 0x30,
RowAnimation::SlideRight => 0x40
RowAnimation::SlideRight => 0x40,
}
}
}
@ -51,7 +51,7 @@ pub enum RowEdge {
Leading,
/// The trailing edge.
Trailing
Trailing,
}
impl Into<RowEdge> for NSInteger {
@ -65,7 +65,7 @@ impl Into<RowEdge> for NSInteger {
// feel like there's a better way to do this, though...
_ => {
unreachable!();
}
},
}
}
}

View file

@ -194,7 +194,7 @@ pub struct ListView<T = ()> {
/// A pointer to the Objective-C runtime center Y layout constraint.
#[cfg(feature = "autolayout")]
pub center_y: LayoutAnchorY
pub center_y: LayoutAnchorY,
}
impl Default for ListView {
@ -270,14 +270,14 @@ impl ListView {
objc: ObjcProperty::retain(view),
scrollview
scrollview,
}
}
}
impl<T> ListView<T>
where
T: ListViewDelegate + 'static
T: ListViewDelegate + 'static,
{
/// Initializes a new View with a given `ViewDelegate`. This enables you to respond to events
/// and customize the view as a module, similar to class-based systems.
@ -349,7 +349,7 @@ where
#[cfg(feature = "autolayout")]
center_y: LayoutAnchorY::center(anchor_view),
scrollview
scrollview,
};
(&mut delegate).did_load(view.clone_as_handle());
@ -401,7 +401,7 @@ impl<T> ListView<T> {
#[cfg(feature = "autolayout")]
center_y: self.center_y.clone(),
scrollview: self.scrollview.clone_as_handle()
scrollview: self.scrollview.clone_as_handle(),
}
}
@ -410,7 +410,7 @@ impl<T> ListView<T> {
pub fn register<F, R>(&self, identifier: &'static str, vendor: F)
where
F: Fn() -> R + 'static,
R: ViewDelegate + 'static
R: ViewDelegate + 'static,
{
self.cell_factory.insert(identifier, vendor);
}

View file

@ -28,7 +28,7 @@ extern "C" fn enforce_normalcy(_: &Object, _: Sel) -> BOOL {
extern "C" fn dragging_entered<T: ViewDelegate>(this: &mut Object, _: Sel, info: id) -> NSUInteger {
let view = load::<T>(this, LISTVIEW_ROW_DELEGATE_PTR);
view.dragging_entered(DragInfo {
info: unsafe { Id::from_ptr(info) }
info: unsafe { Id::from_ptr(info) },
})
.into()
}
@ -38,10 +38,10 @@ extern "C" fn prepare_for_drag_operation<T: ViewDelegate>(this: &mut Object, _:
let view = load::<T>(this, LISTVIEW_ROW_DELEGATE_PTR);
match view.prepare_for_drag_operation(DragInfo {
info: unsafe { Id::from_ptr(info) }
info: unsafe { Id::from_ptr(info) },
}) {
true => YES,
false => NO
false => NO,
}
}
@ -50,10 +50,10 @@ extern "C" fn perform_drag_operation<T: ViewDelegate>(this: &mut Object, _: Sel,
let view = load::<T>(this, LISTVIEW_ROW_DELEGATE_PTR);
match view.perform_drag_operation(DragInfo {
info: unsafe { Id::from_ptr(info) }
info: unsafe { Id::from_ptr(info) },
}) {
true => YES,
false => NO
false => NO,
}
}
@ -62,7 +62,7 @@ extern "C" fn conclude_drag_operation<T: ViewDelegate>(this: &mut Object, _: Sel
let view = load::<T>(this, LISTVIEW_ROW_DELEGATE_PTR);
view.conclude_drag_operation(DragInfo {
info: unsafe { Id::from_ptr(info) }
info: unsafe { Id::from_ptr(info) },
});
}
@ -71,7 +71,7 @@ extern "C" fn dragging_exited<T: ViewDelegate>(this: &mut Object, _: Sel, info:
let view = load::<T>(this, LISTVIEW_ROW_DELEGATE_PTR);
view.dragging_exited(DragInfo {
info: unsafe { Id::from_ptr(info) }
info: unsafe { Id::from_ptr(info) },
});
}
@ -143,23 +143,23 @@ pub(crate) fn register_listview_row_class_with_delegate<T: ViewDelegate>() -> *c
// Drag and drop operations (e.g, accepting files)
decl.add_method(
sel!(draggingEntered:),
dragging_entered::<T> as extern "C" fn(&mut Object, _, _) -> NSUInteger
dragging_entered::<T> as extern "C" fn(&mut Object, _, _) -> NSUInteger,
);
decl.add_method(
sel!(prepareForDragOperation:),
prepare_for_drag_operation::<T> as extern "C" fn(&mut Object, _, _) -> BOOL
prepare_for_drag_operation::<T> as extern "C" fn(&mut Object, _, _) -> BOOL,
);
decl.add_method(
sel!(performDragOperation:),
perform_drag_operation::<T> as extern "C" fn(&mut Object, _, _) -> BOOL
perform_drag_operation::<T> as extern "C" fn(&mut Object, _, _) -> BOOL,
);
decl.add_method(
sel!(concludeDragOperation:),
conclude_drag_operation::<T> as extern "C" fn(&mut Object, _, _)
conclude_drag_operation::<T> as extern "C" fn(&mut Object, _, _),
);
decl.add_method(
sel!(draggingExited:),
dragging_exited::<T> as extern "C" fn(&mut Object, _, _)
dragging_exited::<T> as extern "C" fn(&mut Object, _, _),
);
// Cleanup

View file

@ -146,7 +146,7 @@ pub struct ListViewRow<T = ()> {
/// A pointer to the Objective-C runtime center Y layout constraint.
#[cfg(feature = "autolayout")]
pub center_y: LayoutAnchorY
pub center_y: LayoutAnchorY,
}
impl Default for ListViewRow {
@ -196,14 +196,14 @@ impl ListViewRow {
center_x: LayoutAnchorX::center(view),
#[cfg(feature = "autolayout")]
center_y: LayoutAnchorY::center(view)
center_y: LayoutAnchorY::center(view),
}
}
}
impl<T> ListViewRow<T>
where
T: ViewDelegate + 'static
T: ViewDelegate + 'static,
{
/// When we're able to retrieve a reusable view cell from the backing table view, we can check
/// for the pointer and attempt to reconstruct the ListViewRow<T> that corresponds to this.
@ -260,7 +260,7 @@ where
center_x: LayoutAnchorX::center(view),
#[cfg(feature = "autolayout")]
center_y: LayoutAnchorY::center(view)
center_y: LayoutAnchorY::center(view),
};
view
@ -316,7 +316,7 @@ where
center_x: LayoutAnchorX::center(view),
#[cfg(feature = "autolayout")]
center_y: LayoutAnchorY::center(view)
center_y: LayoutAnchorY::center(view),
};
(&mut delegate).did_load(view.clone_as_handle());
@ -368,7 +368,7 @@ where
center_x: self.center_x.clone(),
#[cfg(feature = "autolayout")]
center_y: self.center_y.clone()
center_y: self.center_y.clone(),
}
}
}
@ -417,7 +417,7 @@ impl<T> ListViewRow<T> {
center_x: self.center_x.clone(),
#[cfg(feature = "autolayout")]
center_y: self.center_y.clone()
center_y: self.center_y.clone(),
}
}

View file

@ -1310,13 +1310,13 @@ pub enum NotificationName {
SKStorefrontCountryCodeDidChange,
///
WKAccessibilityReduceMotionStatusDidChange
WKAccessibilityReduceMotionStatusDidChange,
}
impl From<NotificationName> for NSString<'_> {
fn from(name: NotificationName) -> Self {
match name {
_ => NSString::no_copy("")
_ => NSString::no_copy(""),
}
}
}

View file

@ -102,7 +102,7 @@ impl Pasteboard {
return Err(Box::new(Error {
code: 666,
domain: "com.cacao-rs.pasteboard".to_string(),
description: "Pasteboard server returned no data.".to_string()
description: "Pasteboard server returned no data.".to_string(),
}));
}

View file

@ -16,7 +16,7 @@ pub enum PasteboardName {
General,
/// The ruler pasteboard.
Ruler
Ruler,
}
impl From<PasteboardName> for NSString<'_> {
@ -26,7 +26,7 @@ impl From<PasteboardName> for NSString<'_> {
PasteboardName::Find => "Apple CFPasteboard find",
PasteboardName::Font => "Apple CFPasteboard font",
PasteboardName::General => "Apple CFPasteboard general",
PasteboardName::Ruler => "Apple CFPasteboard ruler"
PasteboardName::Ruler => "Apple CFPasteboard ruler",
})
}
}
@ -77,7 +77,7 @@ pub enum PasteboardType {
TabularText,
/// Tag Image File Format (TIFF) data.
TIFF
TIFF,
}
impl From<PasteboardType> for NSString<'_> {
@ -97,7 +97,7 @@ impl From<PasteboardType> for NSString<'_> {
PasteboardType::Sound => "com.apple.cocoa.pasteboard.sound",
PasteboardType::String => "public.utf8-plain-text",
PasteboardType::TabularText => "public.utf8-tab-separated-values-text",
PasteboardType::TIFF => "public.tiff"
PasteboardType::TIFF => "public.tiff",
})
}
}

View file

@ -7,14 +7,14 @@ pub enum ProgressIndicatorStyle {
Bar,
/// A spinning circle.
Spinner
Spinner,
}
impl From<ProgressIndicatorStyle> for NSUInteger {
fn from(style: ProgressIndicatorStyle) -> Self {
match style {
ProgressIndicatorStyle::Bar => 0,
ProgressIndicatorStyle::Spinner => 1
ProgressIndicatorStyle::Spinner => 1,
}
}
}

Some files were not shown because too many files have changed in this diff Show more