#[repr(C)]pub struct NSImage { /* private fields */ }
NSImage
only.Expand description
Implementations§
Source§impl NSImage
impl NSImage
pub unsafe fn imageNamed(name: &NSImageName) -> Option<Retained<NSImage>>
Sourcepub unsafe fn imageWithSystemSymbolName_accessibilityDescription(
name: &NSString,
description: Option<&NSString>,
) -> Option<Retained<Self>>
pub unsafe fn imageWithSystemSymbolName_accessibilityDescription( name: &NSString, description: Option<&NSString>, ) -> Option<Retained<Self>>
Creates a system symbol image with the specified name and value
Parameter name
: A name from the system’s SF Symbols catalog
Parameter description
: The image’s accessibility description. This description is used automatically by interface elements that display images. Like all accessibility descriptions, use a short localized string that does not include the name of the interface element. For instance, “delete” rather than “delete button”.
Sourcepub unsafe fn imageWithSystemSymbolName_variableValue_accessibilityDescription(
name: &NSString,
value: c_double,
description: Option<&NSString>,
) -> Option<Retained<Self>>
pub unsafe fn imageWithSystemSymbolName_variableValue_accessibilityDescription( name: &NSString, value: c_double, description: Option<&NSString>, ) -> Option<Retained<Self>>
Creates a system symbol image with the specified name and value. The
value
argument is only accommodated if the symbol supports variable rendering.
Parameter name
: A name from the system’s SF Symbols catalog
Parameter value
: The value represented by the symbol. The value should be between 0 and 1 inclusive ([0,1]).
Parameter description
: The image’s accessibility description. This description is used automatically by interface elements that display images. Like all accessibility descriptions, use a short localized string that does not include the name of the interface element. For instance, “delete” rather than “delete button”.
Note: Values less than 0 or greater than 1 will be clamped to 0 and 1, respectively.
Sourcepub unsafe fn imageWithSymbolName_variableValue(
name: &NSString,
value: c_double,
) -> Option<Retained<Self>>
pub unsafe fn imageWithSymbolName_variableValue( name: &NSString, value: c_double, ) -> Option<Retained<Self>>
Creates a symbol image with the specified name and value. The
value
argument is only accommodated if the symbol supports variable rendering.
Parameter name
: A name of a symbol image file in the main bundle’s catalog
Parameter value
: The value represented by the symbol. The value should be between 0 and 1 inclusive ([0,1]).
Note: Values less than 0 or greater than 1 will be clamped to 0 and 1, respectively.
Sourcepub unsafe fn imageWithSymbolName_bundle_variableValue(
name: &NSString,
bundle: Option<&NSBundle>,
value: c_double,
) -> Option<Retained<Self>>
pub unsafe fn imageWithSymbolName_bundle_variableValue( name: &NSString, bundle: Option<&NSBundle>, value: c_double, ) -> Option<Retained<Self>>
Creates a symbol image with the specified name and value. The
value
argument is only accommodated if the symbol supports variable rendering.
Parameter name
: A name of a symbol image file in the main bundle’s catalog
Parameter bundle
: The bundle containing the image file or asset catalog. Specify nil
to search the app’s main bundle.
Parameter value
: The value represented by the symbol. The value should be between 0 and 1 inclusive ([0,1]).
Note: Values less than 0 or greater than 1 will be clamped to 0 and 1, respectively.
pub unsafe fn initWithSize( this: Allocated<Self>, size: NSSize, ) -> Retained<Self>
pub unsafe fn initWithCoder( this: Allocated<Self>, coder: &NSCoder, ) -> Retained<Self>
pub fn initWithData( this: Allocated<Self>, data: &NSData, ) -> Option<Retained<Self>>
pub unsafe fn initWithContentsOfFile( this: Allocated<Self>, file_name: &NSString, ) -> Option<Retained<Self>>
pub unsafe fn initWithContentsOfURL( this: Allocated<Self>, url: &NSURL, ) -> Option<Retained<Self>>
pub fn initByReferencingFile( this: Allocated<Self>, file_name: &NSString, ) -> Option<Retained<Self>>
pub unsafe fn initByReferencingURL( this: Allocated<Self>, url: &NSURL, ) -> Retained<Self>
pub unsafe fn initWithPasteboard( this: Allocated<Self>, pasteboard: &NSPasteboard, ) -> Option<Retained<Self>>
NSPasteboard
only.pub unsafe fn initWithDataIgnoringOrientation( this: Allocated<Self>, data: &NSData, ) -> Option<Retained<Self>>
pub unsafe fn imageWithSize_flipped_drawingHandler( size: NSSize, drawing_handler_should_be_called_with_flipped_context: bool, drawing_handler: &DynBlock<dyn Fn(NSRect) -> Bool>, ) -> Retained<Self>
block2
only.pub unsafe fn size(&self) -> NSSize
pub unsafe fn setName(&self, string: Option<&NSImageName>) -> bool
pub unsafe fn name(&self) -> Option<Retained<NSImageName>>
pub unsafe fn backgroundColor(&self) -> Retained<NSColor>
NSColor
only.Sourcepub unsafe fn setBackgroundColor(&self, background_color: &NSColor)
Available on crate feature NSColor
only.
pub unsafe fn setBackgroundColor(&self, background_color: &NSColor)
NSColor
only.Setter for backgroundColor
.
pub unsafe fn usesEPSOnResolutionMismatch(&self) -> bool
Sourcepub unsafe fn setUsesEPSOnResolutionMismatch(
&self,
uses_eps_on_resolution_mismatch: bool,
)
pub unsafe fn setUsesEPSOnResolutionMismatch( &self, uses_eps_on_resolution_mismatch: bool, )
Setter for usesEPSOnResolutionMismatch
.
pub unsafe fn prefersColorMatch(&self) -> bool
Sourcepub unsafe fn setPrefersColorMatch(&self, prefers_color_match: bool)
pub unsafe fn setPrefersColorMatch(&self, prefers_color_match: bool)
Setter for prefersColorMatch
.
pub unsafe fn matchesOnMultipleResolution(&self) -> bool
Sourcepub unsafe fn setMatchesOnMultipleResolution(
&self,
matches_on_multiple_resolution: bool,
)
pub unsafe fn setMatchesOnMultipleResolution( &self, matches_on_multiple_resolution: bool, )
Setter for matchesOnMultipleResolution
.
pub unsafe fn matchesOnlyOnBestFittingAxis(&self) -> bool
Sourcepub unsafe fn setMatchesOnlyOnBestFittingAxis(
&self,
matches_only_on_best_fitting_axis: bool,
)
pub unsafe fn setMatchesOnlyOnBestFittingAxis( &self, matches_only_on_best_fitting_axis: bool, )
Setter for matchesOnlyOnBestFittingAxis
.
pub unsafe fn drawAtPoint_fromRect_operation_fraction( &self, point: NSPoint, from_rect: NSRect, op: NSCompositingOperation, delta: CGFloat, )
NSGraphics
and objc2-core-foundation
only.pub unsafe fn drawInRect_fromRect_operation_fraction( &self, rect: NSRect, from_rect: NSRect, op: NSCompositingOperation, delta: CGFloat, )
NSGraphics
and objc2-core-foundation
only.pub unsafe fn drawInRect_fromRect_operation_fraction_respectFlipped_hints( &self, dst_space_portion_rect: NSRect, src_space_portion_rect: NSRect, op: NSCompositingOperation, requested_alpha: CGFloat, respect_context_is_flipped: bool, hints: Option<&NSDictionary<NSImageHintKey, AnyObject>>, )
NSGraphics
and NSImageRep
and objc2-core-foundation
only.pub unsafe fn drawRepresentation_inRect( &self, image_rep: &NSImageRep, rect: NSRect, ) -> bool
NSImageRep
only.pub unsafe fn drawInRect(&self, rect: NSRect)
pub unsafe fn recache(&self)
pub unsafe fn TIFFRepresentation(&self) -> Option<Retained<NSData>>
pub unsafe fn TIFFRepresentationUsingCompression_factor( &self, comp: NSTIFFCompression, factor: c_float, ) -> Option<Retained<NSData>>
NSBitmapImageRep
only.pub unsafe fn representations(&self) -> Retained<NSArray<NSImageRep>>
NSImageRep
only.pub unsafe fn addRepresentations(&self, image_reps: &NSArray<NSImageRep>)
NSImageRep
only.pub unsafe fn addRepresentation(&self, image_rep: &NSImageRep)
NSImageRep
only.pub unsafe fn removeRepresentation(&self, image_rep: &NSImageRep)
NSImageRep
only.pub unsafe fn isValid(&self) -> bool
pub unsafe fn delegate( &self, ) -> Option<Retained<ProtocolObject<dyn NSImageDelegate>>>
Sourcepub unsafe fn setDelegate(
&self,
delegate: Option<&ProtocolObject<dyn NSImageDelegate>>,
)
pub unsafe fn setDelegate( &self, delegate: Option<&ProtocolObject<dyn NSImageDelegate>>, )
This is a weak property.
Setter for delegate
.
pub unsafe fn imageTypes() -> Retained<NSArray<NSString>>
pub unsafe fn imageUnfilteredTypes() -> Retained<NSArray<NSString>>
pub unsafe fn canInitWithPasteboard(pasteboard: &NSPasteboard) -> bool
NSPasteboard
only.pub unsafe fn cacheMode(&self) -> NSImageCacheMode
Sourcepub unsafe fn setCacheMode(&self, cache_mode: NSImageCacheMode)
pub unsafe fn setCacheMode(&self, cache_mode: NSImageCacheMode)
Setter for cacheMode
.
pub unsafe fn alignmentRect(&self) -> NSRect
Sourcepub unsafe fn setAlignmentRect(&self, alignment_rect: NSRect)
pub unsafe fn setAlignmentRect(&self, alignment_rect: NSRect)
Setter for alignmentRect
.
pub unsafe fn isTemplate(&self) -> bool
Sourcepub unsafe fn setTemplate(&self, template: bool)
pub unsafe fn setTemplate(&self, template: bool)
Setter for isTemplate
.
pub unsafe fn accessibilityDescription(&self) -> Option<Retained<NSString>>
Sourcepub unsafe fn setAccessibilityDescription(
&self,
accessibility_description: Option<&NSString>,
)
pub unsafe fn setAccessibilityDescription( &self, accessibility_description: Option<&NSString>, )
Setter for accessibilityDescription
.
pub unsafe fn initWithCGImage_size( this: Allocated<Self>, cg_image: &CGImage, size: NSSize, ) -> Retained<Self>
objc2-core-graphics
and Apple only.pub unsafe fn CGImageForProposedRect_context_hints( &self, proposed_dest_rect: *mut NSRect, reference_context: Option<&NSGraphicsContext>, hints: Option<&NSDictionary<NSImageHintKey, AnyObject>>, ) -> Option<Retained<CGImage>>
NSGraphicsContext
and crate feature NSImageRep
and crate feature objc2-core-graphics
and Apple only.pub unsafe fn bestRepresentationForRect_context_hints( &self, rect: NSRect, reference_context: Option<&NSGraphicsContext>, hints: Option<&NSDictionary<NSImageHintKey, AnyObject>>, ) -> Option<Retained<NSImageRep>>
NSGraphicsContext
and NSImageRep
only.pub unsafe fn hitTestRect_withImageDestinationRect_context_hints_flipped( &self, test_rect_dest_space: NSRect, image_rect_dest_space: NSRect, context: Option<&NSGraphicsContext>, hints: Option<&NSDictionary<NSImageHintKey, AnyObject>>, flipped: bool, ) -> bool
NSGraphicsContext
and NSImageRep
only.pub unsafe fn recommendedLayerContentsScale( &self, preferred_contents_scale: CGFloat, ) -> CGFloat
objc2-core-foundation
only.pub unsafe fn layerContentsForContentsScale( &self, layer_contents_scale: CGFloat, ) -> Retained<AnyObject>
objc2-core-foundation
only.pub unsafe fn capInsets(&self) -> NSEdgeInsets
Sourcepub unsafe fn setCapInsets(&self, cap_insets: NSEdgeInsets)
pub unsafe fn setCapInsets(&self, cap_insets: NSEdgeInsets)
Setter for capInsets
.
pub unsafe fn resizingMode(&self) -> NSImageResizingMode
Sourcepub unsafe fn setResizingMode(&self, resizing_mode: NSImageResizingMode)
pub unsafe fn setResizingMode(&self, resizing_mode: NSImageResizingMode)
Setter for resizingMode
.
pub unsafe fn imageWithSymbolConfiguration( &self, configuration: &NSImageSymbolConfiguration, ) -> Option<Retained<NSImage>>
pub unsafe fn symbolConfiguration(&self) -> Retained<NSImageSymbolConfiguration>
Sourcepub unsafe fn imageWithLocale(
&self,
locale: Option<&NSLocale>,
) -> Retained<NSImage>
pub unsafe fn imageWithLocale( &self, locale: Option<&NSLocale>, ) -> Retained<NSImage>
Creates and returns a new image with the specified locale. If the receiver contains locale-sensitive representations, the returned image will prefer to draw using representations appropriate for the specified locale. If locale is nil
, the returned image uses the default behavior of choosing representations appropriate for the system’s currently-configured locale.
Source§impl NSImage
Deprecated.
impl NSImage
Deprecated.
pub unsafe fn imageUnfilteredFileTypes() -> Retained<NSArray<NSString>>
pub unsafe fn imageUnfilteredPasteboardTypes() -> Retained<NSArray<NSPasteboardType>>
NSPasteboard
only.pub unsafe fn imageFileTypes() -> Retained<NSArray<NSString>>
pub unsafe fn imagePasteboardTypes() -> Retained<NSArray<NSPasteboardType>>
NSPasteboard
only.pub unsafe fn bestRepresentationForDevice( &self, device_description: Option<&NSDictionary>, ) -> Option<Retained<NSImageRep>>
NSImageRep
only.pub unsafe fn lockFocus(&self)
pub unsafe fn lockFocusFlipped(&self, flipped: bool)
pub unsafe fn unlockFocus(&self)
pub unsafe fn setFlipped(&self, flag: bool)
pub unsafe fn isFlipped(&self) -> bool
pub unsafe fn setScalesWhenResized(&self, flag: bool)
pub unsafe fn scalesWhenResized(&self) -> bool
pub unsafe fn setDataRetained(&self, flag: bool)
pub unsafe fn isDataRetained(&self) -> bool
pub unsafe fn setCachedSeparately(&self, flag: bool)
pub unsafe fn isCachedSeparately(&self) -> bool
pub unsafe fn setCacheDepthMatchesImageDepth(&self, flag: bool)
pub unsafe fn cacheDepthMatchesImageDepth(&self) -> bool
pub unsafe fn dissolveToPoint_fraction(&self, point: NSPoint, fraction: CGFloat)
objc2-core-foundation
only.pub unsafe fn dissolveToPoint_fromRect_fraction( &self, point: NSPoint, rect: NSRect, fraction: CGFloat, )
objc2-core-foundation
only.pub unsafe fn compositeToPoint_operation( &self, point: NSPoint, operation: NSCompositingOperation, )
NSGraphics
only.pub unsafe fn compositeToPoint_fromRect_operation( &self, point: NSPoint, rect: NSRect, operation: NSCompositingOperation, )
NSGraphics
only.pub unsafe fn compositeToPoint_operation_fraction( &self, point: NSPoint, operation: NSCompositingOperation, fraction: CGFloat, )
NSGraphics
and objc2-core-foundation
only.pub unsafe fn compositeToPoint_fromRect_operation_fraction( &self, point: NSPoint, rect: NSRect, operation: NSCompositingOperation, fraction: CGFloat, )
NSGraphics
and objc2-core-foundation
only.pub unsafe fn lockFocusOnRepresentation( &self, image_representation: Option<&NSImageRep>, )
NSImageRep
only.pub unsafe fn cancelIncrementalLoad(&self)
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 ClassType for NSImage
impl ClassType for NSImage
Source§const NAME: &'static str = "NSImage"
const NAME: &'static str = "NSImage"
Source§type ThreadKind = <<NSImage as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSImage as ClassType>::Super as ClassType>::ThreadKind
Source§impl CopyingHelper for NSImage
impl CopyingHelper for NSImage
Source§impl NSCopying for NSImage
impl NSCopying for NSImage
Source§impl NSItemProviderReading for NSImage
impl NSItemProviderReading for NSImage
Source§impl NSItemProviderWriting for NSImage
impl NSItemProviderWriting for NSImage
unsafe fn writableTypeIdentifiersForItemProvider_class() -> Retained<NSArray<NSString>>
unsafe fn writableTypeIdentifiersForItemProvider( &self, ) -> Retained<NSArray<NSString>>
unsafe fn itemProviderVisibilityForRepresentationWithTypeIdentifier_class( type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
unsafe fn itemProviderVisibilityForRepresentationWithTypeIdentifier( &self, type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
Source§impl NSObjectProtocol for NSImage
impl NSObjectProtocol for NSImage
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
Source§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
Source§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
Source§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
Source§fn debugDescription(&self) -> Retained<NSObject>
fn debugDescription(&self) -> Retained<NSObject>
Source§impl NSPasteboardReading for NSImage
impl NSPasteboardReading for NSImage
Source§unsafe fn readableTypesForPasteboard(
pasteboard: &NSPasteboard,
) -> Retained<NSArray<NSPasteboardType>>
unsafe fn readableTypesForPasteboard( pasteboard: &NSPasteboard, ) -> Retained<NSArray<NSPasteboardType>>
NSPasteboard
only.Source§unsafe fn readingOptionsForType_pasteboard(
type: &NSPasteboardType,
pasteboard: &NSPasteboard,
) -> NSPasteboardReadingOptions
unsafe fn readingOptionsForType_pasteboard( type: &NSPasteboardType, pasteboard: &NSPasteboard, ) -> NSPasteboardReadingOptions
NSPasteboard
only.Source§unsafe fn initWithPasteboardPropertyList_ofType(
this: Allocated<Self>,
property_list: &AnyObject,
type: &NSPasteboardType,
) -> Option<Retained<Self>>
unsafe fn initWithPasteboardPropertyList_ofType( this: Allocated<Self>, property_list: &AnyObject, type: &NSPasteboardType, ) -> Option<Retained<Self>>
NSPasteboard
only.Source§impl NSPasteboardWriting for NSImage
impl NSPasteboardWriting for NSImage
Source§unsafe fn writableTypesForPasteboard(
&self,
pasteboard: &NSPasteboard,
) -> Retained<NSArray<NSPasteboardType>>
unsafe fn writableTypesForPasteboard( &self, pasteboard: &NSPasteboard, ) -> Retained<NSArray<NSPasteboardType>>
NSPasteboard
only.Source§unsafe fn writingOptionsForType_pasteboard(
&self,
type: &NSPasteboardType,
pasteboard: &NSPasteboard,
) -> NSPasteboardWritingOptions
unsafe fn writingOptionsForType_pasteboard( &self, type: &NSPasteboardType, pasteboard: &NSPasteboard, ) -> NSPasteboardWritingOptions
NSPasteboard
only.Source§unsafe fn pasteboardPropertyListForType(
&self,
type: &NSPasteboardType,
) -> Option<Retained<AnyObject>>
unsafe fn pasteboardPropertyListForType( &self, type: &NSPasteboardType, ) -> Option<Retained<AnyObject>>
NSPasteboard
only.