Applies rustfmt.toml rules

This commit is contained in:
Alexander Czernay 2023-04-17 21:35:49 +02:00
parent 718c831bc4
commit ff85e24055
6 changed files with 41 additions and 48 deletions

View file

@ -15,35 +15,29 @@ use cacao::text::{Font, Label};
use cacao::view::{Popover, PopoverConfig, View, ViewController, ViewDelegate}; use cacao::view::{Popover, PopoverConfig, View, ViewController, ViewDelegate};
struct BasicApp { struct BasicApp {
window: WindowController<MyWindow>, window: WindowController<MyWindow>
} }
impl AppDelegate for BasicApp { impl AppDelegate for BasicApp {
fn did_finish_launching(&self) { fn did_finish_launching(&self) {
App::set_menu(vec![ App::set_menu(vec![
Menu::new( Menu::new("", vec![
"", MenuItem::Services,
vec![ MenuItem::Separator,
MenuItem::Services, MenuItem::Hide,
MenuItem::Separator, MenuItem::HideOthers,
MenuItem::Hide, MenuItem::ShowAll,
MenuItem::HideOthers, MenuItem::Separator,
MenuItem::ShowAll, MenuItem::Quit,
MenuItem::Separator, ]),
MenuItem::Quit,
],
),
Menu::new("File", vec![MenuItem::CloseWindow]), Menu::new("File", vec![MenuItem::CloseWindow]),
Menu::new("View", vec![MenuItem::EnterFullScreen]), Menu::new("View", vec![MenuItem::EnterFullScreen]),
Menu::new( Menu::new("Window", vec![
"Window", MenuItem::Minimize,
vec![ MenuItem::Zoom,
MenuItem::Minimize, MenuItem::Separator,
MenuItem::Zoom, MenuItem::new("Bring All to Front"),
MenuItem::Separator, ]),
MenuItem::new("Bring All to Front"),
],
),
]); ]);
App::activate(); App::activate();
@ -58,7 +52,7 @@ impl AppDelegate for BasicApp {
#[derive(Default)] #[derive(Default)]
struct MyWindow { struct MyWindow {
controller: Option<ViewController<PopoverExampleContentView>>, controller: Option<ViewController<PopoverExampleContentView>>
} }
impl WindowDelegate for MyWindow { impl WindowDelegate for MyWindow {
@ -87,25 +81,22 @@ impl MyWindow {
} }
fn main() { fn main() {
App::new( App::new("com.test.window-delegate", BasicApp {
"com.test.window-delegate", window: WindowController::with(WindowConfig::default(), MyWindow::default())
BasicApp { })
window: WindowController::with(WindowConfig::default(), MyWindow::default()),
},
)
.run(); .run();
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Msg { pub enum Msg {
Click, Click
} }
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct PopoverExampleContentView { struct PopoverExampleContentView {
view: Option<View>, view: Option<View>,
button: Option<Button>, button: Option<Button>,
popover: Option<Popover<PopoverExampleContentViewController>>, popover: Option<Popover<PopoverExampleContentViewController>>
} }
impl PopoverExampleContentView { impl PopoverExampleContentView {
@ -113,7 +104,7 @@ impl PopoverExampleContentView {
Self { Self {
view: None, view: None,
button: None, button: None,
popover: None, popover: None
} }
} }
@ -123,7 +114,7 @@ impl PopoverExampleContentView {
let Some(ref popover) = self.popover else { return }; let Some(ref popover) = self.popover else { return };
let Some(ref button) = self.button else { return }; let Some(ref button) = self.button else { return };
popover.show_popover(Rect::zero(), button, Edge::MaxY); popover.show_popover(Rect::zero(), button, Edge::MaxY);
}, }
} }
} }
} }
@ -147,7 +138,7 @@ impl ViewDelegate for PopoverExampleContentView {
LayoutConstraint::activate(&[ LayoutConstraint::activate(&[
button.center_x.constraint_equal_to(&view.center_x), button.center_x.constraint_equal_to(&view.center_x),
button.center_y.constraint_equal_to(&view.center_y), button.center_y.constraint_equal_to(&view.center_y)
]); ]);
self.view = Some(view); self.view = Some(view);
@ -173,7 +164,7 @@ impl Dispatcher for BasicApp {
#[derive(Debug)] #[derive(Debug)]
struct PopoverExampleContentViewController { struct PopoverExampleContentViewController {
pub label: Label, pub label: Label
} }
impl PopoverExampleContentViewController { impl PopoverExampleContentViewController {

View file

@ -110,14 +110,14 @@ impl Window {
Window { Window {
objc: objc, objc: objc,
delegate: None, delegate: None
} }
} }
pub(crate) unsafe fn existing(window: *mut Object) -> Window { pub(crate) unsafe fn existing(window: *mut Object) -> Window {
Window { Window {
objc: ShareId::from_ptr(window), objc: ShareId::from_ptr(window),
delegate: None, delegate: None
} }
} }
} }

View file

@ -305,6 +305,7 @@ impl ObjcAccess for Button {
} }
impl Layout for Button {} impl Layout for Button {}
impl Control for Button {} impl Control for Button {}
impl ObjcAccess for &Button { impl ObjcAccess for &Button {
@ -318,6 +319,7 @@ impl ObjcAccess for &Button {
} }
impl Layout for &Button {} impl Layout for &Button {}
impl Control for &Button {} impl Control for &Button {}
impl Drop for Button { impl Drop for Button {

View file

@ -47,7 +47,7 @@ pub enum Edge {
MinX = 0, MinX = 0,
MinY = 1, MinY = 1,
MaxX = 2, MaxX = 2,
MaxY = 3, MaxY = 3
} }
impl From<Rect> for CGRect { impl From<Rect> for CGRect {
fn from(rect: Rect) -> CGRect { fn from(rect: Rect) -> CGRect {

View file

@ -20,14 +20,14 @@ pub enum PopoverBehaviour {
/// The system will close the popover when the user interacts with a user interface element outside the popover. /// The system will close the popover when the user interacts with a user interface element outside the popover.
Transient = 1, Transient = 1,
/// The system will close the popover when the user interacts with user interface elements in the window containing the popover's positioning view. /// The system will close the popover when the user interacts with user interface elements in the window containing the popover's positioning view.
Semitransient = 2, Semitransient = 2
} }
#[derive(Debug)] #[derive(Debug)]
pub struct PopoverConfig { pub struct PopoverConfig {
pub content_size: CGSize, pub content_size: CGSize,
pub animates: bool, pub animates: bool,
pub behaviour: PopoverBehaviour, pub behaviour: PopoverBehaviour
} }
impl Default for PopoverConfig { impl Default for PopoverConfig {
@ -35,10 +35,10 @@ impl Default for PopoverConfig {
Self { Self {
content_size: CGSize { content_size: CGSize {
width: 320.0, width: 320.0,
height: 320.0, height: 320.0
}, },
animates: true, animates: true,
behaviour: PopoverBehaviour::Transient, behaviour: PopoverBehaviour::Transient
} }
} }
} }
@ -49,12 +49,12 @@ pub struct Popover<Content> {
pub objc: ShareId<Object>, pub objc: ShareId<Object>,
/// The wrapped ViewController. /// The wrapped ViewController.
pub view_controller: ViewController<Content>, pub view_controller: ViewController<Content>
} }
impl<Content> Popover<Content> impl<Content> Popover<Content>
where where
Content: ViewDelegate + 'static, Content: ViewDelegate + 'static
{ {
pub fn new(content: Content, config: PopoverConfig) -> Self { pub fn new(content: Content, config: PopoverConfig) -> Self {
let view_controller = ViewController::new(content); let view_controller = ViewController::new(content);

View file

@ -9,7 +9,7 @@ use crate::view::{ViewDelegate, VIEW_DELEGATE_PTR};
/// Called when the view controller receives a `viewWillAppear:` message. /// Called when the view controller receives a `viewWillAppear:` message.
extern "C" fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) { extern "C" fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewWillAppear:animated]; let _: () = msg_send![super(this, class!(UIViewController)), viewWillAppear: animated];
} }
let controller = load::<T>(this, VIEW_DELEGATE_PTR); let controller = load::<T>(this, VIEW_DELEGATE_PTR);
@ -19,7 +19,7 @@ extern "C" fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated:
/// Called when the view controller receives a `viewDidAppear:` message. /// Called when the view controller receives a `viewDidAppear:` message.
extern "C" fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) { extern "C" fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewDidAppear:animated]; let _: () = msg_send![super(this, class!(UIViewController)), viewDidAppear: animated];
} }
let controller = load::<T>(this, VIEW_DELEGATE_PTR); let controller = load::<T>(this, VIEW_DELEGATE_PTR);
@ -29,7 +29,7 @@ extern "C" fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: B
/// Called when the view controller receives a `viewWillDisappear:` message. /// Called when the view controller receives a `viewWillDisappear:` message.
extern "C" fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) { extern "C" fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewWillDisappear:animated]; let _: () = msg_send![super(this, class!(UIViewController)), viewWillDisappear: animated];
} }
let controller = load::<T>(this, VIEW_DELEGATE_PTR); let controller = load::<T>(this, VIEW_DELEGATE_PTR);
@ -39,7 +39,7 @@ extern "C" fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animate
/// Called when the view controller receives a `viewDidDisappear:` message. /// Called when the view controller receives a `viewDidDisappear:` message.
extern "C" fn did_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) { extern "C" fn did_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
unsafe { unsafe {
let _: () = msg_send![super(this, class!(UIViewController)), viewDidDisappear:animated]; let _: () = msg_send![super(this, class!(UIViewController)), viewDidDisappear: animated];
} }
let controller = load::<T>(this, VIEW_DELEGATE_PTR); let controller = load::<T>(this, VIEW_DELEGATE_PTR);