diff --git a/Cargo.toml b/Cargo.toml index cc306ad..a9cb2c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,6 +99,6 @@ required-features = ["appkit"] [[example]] name = "window_controller" required-features = ["appkit"] -[[exmaple]] +[[example]] name = "safe_area" required-features = ["appkit"] \ No newline at end of file diff --git a/examples/safe_area.rs b/examples/safe_area.rs index 08165a9..f0bf85c 100644 --- a/examples/safe_area.rs +++ b/examples/safe_area.rs @@ -50,7 +50,7 @@ impl ViewDelegate for ContentView { self.content.top.constraint_equal_to(&view.safe_layout_guide.top), self.content.leading.constraint_equal_to(&view.safe_layout_guide.leading), self.content.trailing.constraint_equal_to(&view.safe_layout_guide.trailing), - self.content.bottom.constraint_equal_to(&view.safe_layout_guide.bottom), + self.content.bottom.constraint_equal_to(&view.safe_layout_guide.bottom) ]) } } @@ -59,5 +59,6 @@ fn main() { App::new("com.test.window", BasicApp { window: Window::default(), content_view: View::with(ContentView::default()) - }).run(); + }) + .run(); } diff --git a/src/appkit/window/mod.rs b/src/appkit/window/mod.rs index 213abf2..e246061 100644 --- a/src/appkit/window/mod.rs +++ b/src/appkit/window/mod.rs @@ -205,12 +205,14 @@ impl Window { } } - /// Sets the subtitle (smaller text bellow the title on unified and expanded title bars) on the + /// Sets the subtitle (smaller text bellow the title on unified and expanded title bars) on the /// underlying window. When this property is an empty string, the system removes the subtitle /// from the window layout. Allocates and passes an `NSString` over to the Objective C runtime. /// Does nothing when less than version 11. pub fn set_subtittle(&self, subtitle: &str) { - if !os::is_minimum_version(11) { return; } + if !os::is_minimum_version(11) { + return; + } unsafe { let subtitle = NSString::new(subtitle); diff --git a/src/button/enums.rs b/src/button/enums.rs index cf5fe8a..01f163d 100644 --- a/src/button/enums.rs +++ b/src/button/enums.rs @@ -92,3 +92,54 @@ impl From for BezelStyle { } } } + +#[cfg(feature = "appkit")] +#[derive(Debug)] +pub enum ImagePosition { + NoImage, + ImageOnly, + ImageLeft, + ImageRight, + ImageBelow, + ImageAbove, + ImageOverlaps, + ImageLeading, + ImageTrailing, + Other(NSUInteger) +} + +impl From for NSUInteger { + fn from(value: ImagePosition) -> Self { + match value { + ImagePosition::NoImage => 0, + ImagePosition::ImageOnly => 1, + ImagePosition::ImageLeft => 2, + ImagePosition::ImageRight => 3, + ImagePosition::ImageBelow => 4, + ImagePosition::ImageAbove => 5, + ImagePosition::ImageOverlaps => 6, + ImagePosition::ImageLeading => 7, + ImagePosition::ImageTrailing => 8, + ImagePosition::Other(o) => o + } + } +} + +impl From for ImagePosition { + fn from(value: NSUInteger) -> Self { + use ImagePosition::*; + + match value { + 0 => NoImage, + 1 => ImageOnly, + 2 => ImageLeft, + 3 => ImageRight, + 4 => ImageBelow, + 5 => ImageAbove, + 6 => ImageOverlaps, + 7 => ImageLeading, + 8 => ImageTrailing, + o => Other(o) + } + } +} diff --git a/src/button/mod.rs b/src/button/mod.rs index 84b9654..6602bb8 100644 --- a/src/button/mod.rs +++ b/src/button/mod.rs @@ -175,6 +175,15 @@ impl Button { } } + /// Changes the text of the button + #[cfg(feature = "appkit")] + pub fn set_text(&self, text: &str) { + let title = NSString::new(text); + self.objc.with_mut(|obj| unsafe { + let _: () = msg_send![obj, setTitle:&*title]; + }); + } + /// Sets an image on the underlying button. pub fn set_image(&mut self, image: Image) { self.objc.with_mut(|obj| unsafe { @@ -184,6 +193,13 @@ impl Button { self.image = Some(image); } + pub fn set_image_position(&self, image_position: ImagePosition) { + let position: NSUInteger = image_position.into(); + self.objc.with_mut(|obj| unsafe { + let _: () = msg_send![obj, setImagePosition: position]; + }); + } + /// Sets the bezel style for this button. Only supported on appkit. #[cfg(feature = "appkit")] pub fn set_bezel_style(&self, bezel_style: BezelStyle) {