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};
struct BasicApp {
window: WindowController<MyWindow>,
window: WindowController<MyWindow>
}
impl AppDelegate for BasicApp {
fn did_finish_launching(&self) {
App::set_menu(vec![
Menu::new(
"",
vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
MenuItem::HideOthers,
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
],
),
Menu::new("", vec![
MenuItem::Services,
MenuItem::Separator,
MenuItem::Hide,
MenuItem::HideOthers,
MenuItem::ShowAll,
MenuItem::Separator,
MenuItem::Quit,
]),
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"),
],
),
Menu::new("Window", vec![
MenuItem::Minimize,
MenuItem::Zoom,
MenuItem::Separator,
MenuItem::new("Bring All to Front"),
]),
]);
App::activate();
@ -58,7 +52,7 @@ impl AppDelegate for BasicApp {
#[derive(Default)]
struct MyWindow {
controller: Option<ViewController<PopoverExampleContentView>>,
controller: Option<ViewController<PopoverExampleContentView>>
}
impl WindowDelegate for MyWindow {
@ -87,25 +81,22 @@ impl 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();
}
#[derive(Clone, Debug)]
pub enum Msg {
Click,
Click
}
#[derive(Debug, Default)]
struct PopoverExampleContentView {
view: Option<View>,
button: Option<Button>,
popover: Option<Popover<PopoverExampleContentViewController>>,
popover: Option<Popover<PopoverExampleContentViewController>>
}
impl PopoverExampleContentView {
@ -113,7 +104,7 @@ impl PopoverExampleContentView {
Self {
view: None,
button: None,
popover: None,
popover: None
}
}
@ -123,7 +114,7 @@ impl PopoverExampleContentView {
let Some(ref popover) = self.popover else { return };
let Some(ref button) = self.button else { return };
popover.show_popover(Rect::zero(), button, Edge::MaxY);
},
}
}
}
}
@ -147,7 +138,7 @@ impl ViewDelegate for PopoverExampleContentView {
LayoutConstraint::activate(&[
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);
@ -173,7 +164,7 @@ impl Dispatcher for BasicApp {
#[derive(Debug)]
struct PopoverExampleContentViewController {
pub label: Label,
pub label: Label
}
impl PopoverExampleContentViewController {

View file

@ -110,14 +110,14 @@ impl Window {
Window {
objc: objc,
delegate: None,
delegate: None
}
}
pub(crate) unsafe fn existing(window: *mut Object) -> Window {
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 Control for Button {}
impl ObjcAccess for &Button {
@ -318,6 +319,7 @@ impl ObjcAccess for &Button {
}
impl Layout for &Button {}
impl Control for &Button {}
impl Drop for Button {

View file

@ -47,7 +47,7 @@ pub enum Edge {
MinX = 0,
MinY = 1,
MaxX = 2,
MaxY = 3,
MaxY = 3
}
impl From<Rect> for 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.
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.
Semitransient = 2,
Semitransient = 2
}
#[derive(Debug)]
pub struct PopoverConfig {
pub content_size: CGSize,
pub animates: bool,
pub behaviour: PopoverBehaviour,
pub behaviour: PopoverBehaviour
}
impl Default for PopoverConfig {
@ -35,10 +35,10 @@ impl Default for PopoverConfig {
Self {
content_size: CGSize {
width: 320.0,
height: 320.0,
height: 320.0
},
animates: true,
behaviour: PopoverBehaviour::Transient,
behaviour: PopoverBehaviour::Transient
}
}
}
@ -49,12 +49,12 @@ pub struct Popover<Content> {
pub objc: ShareId<Object>,
/// The wrapped ViewController.
pub view_controller: ViewController<Content>,
pub view_controller: ViewController<Content>
}
impl<Content> Popover<Content>
where
Content: ViewDelegate + 'static,
Content: ViewDelegate + 'static
{
pub fn new(content: Content, config: PopoverConfig) -> Self {
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.
extern "C" fn will_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
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);
@ -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.
extern "C" fn did_appear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
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);
@ -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.
extern "C" fn will_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
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);
@ -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.
extern "C" fn did_disappear<T: ViewDelegate>(this: &mut Object, _: Sel, animated: BOOL) {
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);