diff --git a/examples/animation.rs b/examples/animation.rs index 0b813ee..8d9de6c 100644 --- a/examples/animation.rs +++ b/examples/animation.rs @@ -9,10 +9,10 @@ use cacao::color::Color; use cacao::layout::{Layout, LayoutConstraint, LayoutConstraintAnimatorProxy}; use cacao::view::{View, ViewAnimatorProxy}; -use cacao::appkit::{App, AppDelegate, AnimationContext}; -use cacao::appkit::{Event, EventMask, EventMonitor}; use cacao::appkit::menu::Menu; use cacao::appkit::window::{Window, WindowConfig, WindowDelegate}; +use cacao::appkit::{AnimationContext, App, AppDelegate}; +use cacao::appkit::{Event, EventMask, EventMonitor}; struct BasicApp { window: Window @@ -54,33 +54,26 @@ 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. -fn apply_styles( - view: &View, - parent: &View, - background_color: Color, - animation_table_index: usize -) -> [LayoutConstraint; 4] { +fn apply_styles(view: &View, parent: &View, background_color: Color, animation_table_index: usize) -> [LayoutConstraint; 4] { view.set_background_color(background_color); view.layer.set_corner_radius(16.); parent.add_subview(view); @@ -117,20 +110,24 @@ impl WindowDelegate for AppWindow { let red_frame = apply_styles(&self.red, &self.content, Color::SystemRed, 1); let green_frame = apply_styles(&self.green, &self.content, Color::SystemGreen, 2); - let alpha_animators = [&self.blue, &self.red, &self.green].iter().map(|view| { - view.animator.clone() - }).collect::>(); + let alpha_animators = [&self.blue, &self.red, &self.green] + .iter() + .map(|view| view.animator.clone()) + .collect::>(); - let constraint_animators = [blue_frame, red_frame, green_frame].iter().map(|frame| { - LayoutConstraint::activate(frame); + let constraint_animators = [blue_frame, red_frame, green_frame] + .iter() + .map(|frame| { + LayoutConstraint::activate(frame); - vec![ - frame[0].animator.clone(), - frame[1].animator.clone(), - frame[2].animator.clone(), - frame[3].animator.clone(), - ] - }).collect::>>(); + vec![ + frame[0].animator.clone(), + frame[1].animator.clone(), + frame[2].animator.clone(), + frame[3].animator.clone(), + ] + }) + .collect::>>(); // Monitor key change events for w/a/s/d, and then animate each view to their correct // frame and alpha value. @@ -175,5 +172,6 @@ impl WindowDelegate for AppWindow { fn main() { App::new("com.test.window", BasicApp { window: Window::with(WindowConfig::default(), AppWindow::default()) - }).run(); + }) + .run(); } diff --git a/examples/autolayout.rs b/examples/autolayout.rs index f64b284..6bcdecd 100644 --- a/examples/autolayout.rs +++ b/examples/autolayout.rs @@ -5,9 +5,9 @@ use cacao::color::{Color, Theme}; use cacao::layout::{Layout, LayoutConstraint}; use cacao::view::View; -use cacao::appkit::{App, AppDelegate}; use cacao::appkit::menu::{Menu, MenuItem}; use cacao::appkit::window::{Window, WindowConfig, WindowDelegate}; +use cacao::appkit::{App, AppDelegate}; struct BasicApp { window: Window @@ -23,23 +23,16 @@ impl AppDelegate for BasicApp { MenuItem::HideOthers, MenuItem::ShowAll, MenuItem::Separator, - MenuItem::Quit + MenuItem::Quit, ]), - - Menu::new("File", vec![ - MenuItem::CloseWindow - ]), - - Menu::new("View", vec![ - MenuItem::EnterFullScreen - ]), - + Menu::new("File", vec![MenuItem::CloseWindow]), + Menu::new("View", vec![MenuItem::EnterFullScreen]), Menu::new("Window", vec![ MenuItem::Minimize, MenuItem::Zoom, MenuItem::Separator, - MenuItem::new("Bring All to Front") - ]) + MenuItem::new("Bring All to Front"), + ]), ]); App::activate(); @@ -89,16 +82,14 @@ impl WindowDelegate for AppWindow { self.blue.leading.constraint_equal_to(&self.content.leading).offset(16.), self.blue.bottom.constraint_equal_to(&self.content.bottom).offset(-16.), self.blue.width.constraint_equal_to_constant(100.), - self.red.top.constraint_equal_to(&self.content.top).offset(46.), self.red.leading.constraint_equal_to(&self.blue.trailing).offset(16.), self.red.bottom.constraint_equal_to(&self.content.bottom).offset(-16.), - self.green.top.constraint_equal_to(&self.content.top).offset(46.), 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.) ]); } } @@ -106,5 +97,6 @@ impl WindowDelegate for AppWindow { fn main() { App::new("com.test.window", BasicApp { window: Window::with(WindowConfig::default(), AppWindow::default()) - }).run(); + }) + .run(); } diff --git a/examples/browser/main.rs b/examples/browser/main.rs index a386520..e6433fc 100644 --- a/examples/browser/main.rs +++ b/examples/browser/main.rs @@ -4,10 +4,10 @@ use cacao::notification_center::Dispatcher; use cacao::webview::{WebView, WebViewConfig, WebViewDelegate}; -use cacao::appkit::{App, AppDelegate}; use cacao::appkit::menu::{Menu, MenuItem}; use cacao::appkit::toolbar::Toolbar; use cacao::appkit::window::{Window, WindowConfig, WindowDelegate, WindowToolbarStyle}; +use cacao::appkit::{App, AppDelegate}; mod toolbar; use toolbar::BrowserToolbar; @@ -39,13 +39,9 @@ impl AppDelegate for BasicApp { MenuItem::HideOthers, MenuItem::ShowAll, MenuItem::Separator, - MenuItem::Quit + MenuItem::Quit, ]), - - Menu::new("File", vec![ - MenuItem::CloseWindow - ]), - + Menu::new("File", vec![MenuItem::CloseWindow]), Menu::new("Edit", vec![ MenuItem::Undo, MenuItem::Redo, @@ -54,21 +50,16 @@ impl AppDelegate for BasicApp { MenuItem::Copy, MenuItem::Paste, MenuItem::Separator, - MenuItem::SelectAll + MenuItem::SelectAll, ]), - - Menu::new("View", vec![ - MenuItem::EnterFullScreen - ]), - + Menu::new("View", vec![MenuItem::EnterFullScreen]), Menu::new("Window", vec![ MenuItem::Minimize, MenuItem::Zoom, MenuItem::Separator, - MenuItem::new("Bring All to Front") + MenuItem::new("Bring All to Front"), ]), - - Menu::new("Help", vec![]) + Menu::new("Help", vec![]), ]); App::activate(); @@ -84,9 +75,15 @@ impl Dispatcher for BasicApp { let webview = &window.content; match message { - Action::Back => { webview.go_back(); }, - Action::Forwards => { webview.go_forward(); }, - Action::Load(url) => { window.load_url(&url); } + Action::Back => { + webview.go_back(); + }, + Action::Forwards => { + webview.go_forward(); + }, + Action::Load(url) => { + window.load_url(&url); + } } } } @@ -132,13 +129,17 @@ impl WindowDelegate for AppWindow { fn main() { App::new("com.test.window", BasicApp { - window: Window::with({ - let mut config = WindowConfig::default(); + window: Window::with( + { + let mut config = WindowConfig::default(); - // This flag is necessary for Big Sur to use the correct toolbar style. - config.toolbar_style = WindowToolbarStyle::Expanded; + // This flag is necessary for Big Sur to use the correct toolbar style. + config.toolbar_style = WindowToolbarStyle::Expanded; - config - }, AppWindow::new()) - }).run(); + config + }, + AppWindow::new() + ) + }) + .run(); } diff --git a/examples/browser/toolbar.rs b/examples/browser/toolbar.rs index 919cd17..ecdbb6c 100644 --- a/examples/browser/toolbar.rs +++ b/examples/browser/toolbar.rs @@ -1,10 +1,9 @@ - use cacao::objc::{msg_send, sel, sel_impl}; use cacao::button::Button; use cacao::input::{TextField, TextFieldDelegate}; -use cacao::appkit::toolbar::{Toolbar, ToolbarDisplayMode, ToolbarItem, ItemIdentifier, ToolbarDelegate}; +use cacao::appkit::toolbar::{ItemIdentifier, Toolbar, ToolbarDelegate, ToolbarDisplayMode, ToolbarItem}; use super::Action; @@ -74,7 +73,7 @@ impl BrowserToolbar { ItemIdentifier::Custom(FWDS_BUTTON), ItemIdentifier::Space, ItemIdentifier::Custom(URL_BAR), - ItemIdentifier::Space + ItemIdentifier::Space, ] } } @@ -99,7 +98,9 @@ impl ToolbarDelegate for BrowserToolbar { BACK_BUTTON => &self.back_item, FWDS_BUTTON => &self.forwards_item, URL_BAR => &self.url_bar_item, - _ => { std::unreachable!(); } + _ => { + std::unreachable!(); + } } } } diff --git a/examples/calculator/button_row.rs b/examples/calculator/button_row.rs index b0bc2d6..053c9bb 100644 --- a/examples/calculator/button_row.rs +++ b/examples/calculator/button_row.rs @@ -1,10 +1,10 @@ -use cacao::layout::{LayoutConstraint, Layout}; use cacao::button::Button; use cacao::color::Color; +use cacao::layout::{Layout, LayoutConstraint}; use cacao::view::View; use crate::calculator::Msg; -use crate::content_view::{button, BUTTON_WIDTH, BUTTON_HEIGHT}; +use crate::content_view::{button, BUTTON_HEIGHT, BUTTON_WIDTH}; pub struct ButtonRow { pub view: View, @@ -15,31 +15,36 @@ impl ButtonRow { pub fn new(x: [Msg; 4], color: Color, action_color: Color) -> Self { let view = View::new(); - let buttons: Vec