fix: Add missing button apis
This commit is contained in:
parent
589ff8c789
commit
f2f6a1bcfa
|
@ -99,6 +99,6 @@ required-features = ["appkit"]
|
|||
[[example]]
|
||||
name = "window_controller"
|
||||
required-features = ["appkit"]
|
||||
[[exmaple]]
|
||||
[[example]]
|
||||
name = "safe_area"
|
||||
required-features = ["appkit"]
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -210,7 +210,9 @@ impl<T> Window<T> {
|
|||
/// 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);
|
||||
|
|
|
@ -92,3 +92,54 @@ impl From<NSUInteger> for BezelStyle {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "appkit")]
|
||||
#[derive(Debug)]
|
||||
pub enum ImagePosition {
|
||||
NoImage,
|
||||
ImageOnly,
|
||||
ImageLeft,
|
||||
ImageRight,
|
||||
ImageBelow,
|
||||
ImageAbove,
|
||||
ImageOverlaps,
|
||||
ImageLeading,
|
||||
ImageTrailing,
|
||||
Other(NSUInteger)
|
||||
}
|
||||
|
||||
impl From<ImagePosition> 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<NSUInteger> 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue