pub struct NSTabViewItem { /* private fields */ }NSTabViewItem only.Expand description
Implementations§
Source§impl NSTabViewItem
impl NSTabViewItem
Sourcepub fn tabViewItemWithViewController(
view_controller: &NSViewController,
) -> Retained<Self>
Available on crate features NSResponder and NSViewController only.
pub fn tabViewItemWithViewController( view_controller: &NSViewController, ) -> Retained<Self>
NSResponder and NSViewController only.Creates an autoreleased TabViewItem that wraps the provided ViewController. The viewController is set as the tab view item’s
-viewControllerproperty, which sets several of the tab view item’s other properties.
Parameter viewController: The view controller to wrap, used to set the viewController property
Sourcepub unsafe fn initWithIdentifier(
this: Allocated<Self>,
identifier: Option<&AnyObject>,
) -> Retained<Self>
pub unsafe fn initWithIdentifier( this: Allocated<Self>, identifier: Option<&AnyObject>, ) -> Retained<Self>
§Safety
identifier should be of the correct type.
pub fn identifier(&self) -> Option<Retained<AnyObject>>
Sourcepub unsafe fn setIdentifier(&self, identifier: Option<&AnyObject>)
pub unsafe fn setIdentifier(&self, identifier: Option<&AnyObject>)
pub fn color(&self) -> Retained<NSColor>
NSColor only.pub fn label(&self) -> Retained<NSString>
Sourcepub fn image(&self) -> Option<Retained<NSImage>>
Available on crate feature NSImage only.
pub fn image(&self) -> Option<Retained<NSImage>>
NSImage only.Get and set the image for this tab view item. The image may only be used in certain tab view styles and options. The default value is nil.
Sourcepub fn setImage(&self, image: Option<&NSImage>)
Available on crate feature NSImage only.
pub fn setImage(&self, image: Option<&NSImage>)
NSImage only.Setter for image.
pub fn view(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>
NSResponder and NSView only.Sourcepub fn setView(&self, view: Option<&NSView>)
Available on crate features NSResponder and NSView only.
pub fn setView(&self, view: Option<&NSView>)
NSResponder and NSView only.Setter for view.
Sourcepub fn viewController(
&self,
mtm: MainThreadMarker,
) -> Option<Retained<NSViewController>>
Available on crate features NSResponder and NSViewController only.
pub fn viewController( &self, mtm: MainThreadMarker, ) -> Option<Retained<NSViewController>>
NSResponder and NSViewController only.The view controller wrapped by the tab view item. This property must be set if the tab view item will be added to an NSTabViewController, but can also be used if the tab view item is added to an NSTabView.
If this is set, the tab view item will forward
-viewcalls onto the viewController. Setting a viewController will also set the following properties on the tab view item:
-identifierfrom the address of the viewController,
-labelfrom the viewController’s title, and
-imagebased on the classname as the view controller.
An image named “ViewControllerClassName-TabViewItem” will be searched for first, followed by “ViewControllerClassName”. It will search first using +[NSImage imageNamed:], then in
viewController.nibBundle,and lastly in the bundle containing the view controller’s class.
As defined by: -[NSImage imageNamed:imageName], -[viewController.nibBundle imageForResource:imageName], -[[NSBundle bundleForClass:[viewController class]] imageForResource:imageName]. One pass with imageName as [NSStringFromClass([viewController class]) stringByAppendingString:
“
-TabViewItem“], followed by imageName as NSStringFromClass([viewController class]).
Sourcepub fn setViewController(&self, view_controller: Option<&NSViewController>)
Available on crate features NSResponder and NSViewController only.
pub fn setViewController(&self, view_controller: Option<&NSViewController>)
NSResponder and NSViewController only.Setter for viewController.
pub fn tabState(&self) -> NSTabState
pub fn tabView(&self, mtm: MainThreadMarker) -> Option<Retained<NSTabView>>
NSResponder and NSTabView and NSView only.pub fn initialFirstResponder( &self, mtm: MainThreadMarker, ) -> Option<Retained<NSView>>
NSResponder and NSView only.Sourcepub fn setInitialFirstResponder(&self, initial_first_responder: Option<&NSView>)
Available on crate features NSResponder and NSView only.
pub fn setInitialFirstResponder(&self, initial_first_responder: Option<&NSView>)
NSResponder and NSView only.Setter for initialFirstResponder.
This is a weak property.
pub fn toolTip(&self) -> Option<Retained<NSString>>
Sourcepub fn setToolTip(&self, tool_tip: Option<&NSString>)
pub fn setToolTip(&self, tool_tip: Option<&NSString>)
pub fn drawLabel_inRect(&self, should_truncate_label: bool, label_rect: NSRect)
pub fn sizeOfLabel(&self, compute_min: bool) -> NSSize
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
Available on crate feature NSAccessibilityConstants only.
pub fn class(&self) -> &'static AnyClass
NSAccessibilityConstants only.Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.Available on crate feature NSAccessibilityConstants only.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load instead.NSAccessibilityConstants only.Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Available on crate feature NSAccessibilityConstants only.
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
NSAccessibilityConstants only.Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AnyObject> for NSTabViewItem
impl AsRef<AnyObject> for NSTabViewItem
Source§impl AsRef<NSObject> for NSTabViewItem
impl AsRef<NSObject> for NSTabViewItem
Source§impl AsRef<NSTabViewItem> for NSTabViewItem
impl AsRef<NSTabViewItem> for NSTabViewItem
Source§impl Borrow<AnyObject> for NSTabViewItem
impl Borrow<AnyObject> for NSTabViewItem
Source§impl Borrow<NSObject> for NSTabViewItem
impl Borrow<NSObject> for NSTabViewItem
Source§impl ClassType for NSTabViewItem
impl ClassType for NSTabViewItem
Source§const NAME: &'static str = "NSTabViewItem"
const NAME: &'static str = "NSTabViewItem"
Source§type ThreadKind = <<NSTabViewItem as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSTabViewItem as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for NSTabViewItem
impl Debug for NSTabViewItem
Source§impl DefaultRetained for NSTabViewItem
impl DefaultRetained for NSTabViewItem
Source§impl Deref for NSTabViewItem
impl Deref for NSTabViewItem
Source§impl Hash for NSTabViewItem
impl Hash for NSTabViewItem
Source§impl Message for NSTabViewItem
impl Message for NSTabViewItem
Source§impl NSCoding for NSTabViewItem
impl NSCoding for NSTabViewItem
Source§impl NSObjectProtocol for NSTabViewItem
impl NSObjectProtocol for NSTabViewItem
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_ref