pub struct NSImage { /* private fields */ }NSImage only.Expand description
Implementations§
Source§impl NSImage
impl NSImage
pub fn imageNamed(name: &NSImageName) -> Option<Retained<NSImage>>
Sourcepub fn imageWithSystemSymbolName_accessibilityDescription(
name: &NSString,
description: Option<&NSString>,
) -> Option<Retained<Self>>
pub 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 fn imageWithSystemSymbolName_variableValue_accessibilityDescription(
name: &NSString,
value: c_double,
description: Option<&NSString>,
) -> Option<Retained<Self>>
pub 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
valueargument 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 fn imageWithSymbolName_variableValue(
name: &NSString,
value: c_double,
) -> Option<Retained<Self>>
pub fn imageWithSymbolName_variableValue( name: &NSString, value: c_double, ) -> Option<Retained<Self>>
Creates a symbol image with the specified name and value. The
valueargument 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 fn imageWithSymbolName_bundle_variableValue(
name: &NSString,
bundle: Option<&NSBundle>,
value: c_double,
) -> Option<Retained<Self>>
pub 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
valueargument 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 fn initWithSize(this: Allocated<Self>, size: NSSize) -> Retained<Self>
Sourcepub unsafe fn initWithCoder(
this: Allocated<Self>,
coder: &NSCoder,
) -> Retained<Self>
pub unsafe fn initWithCoder( this: Allocated<Self>, coder: &NSCoder, ) -> Retained<Self>
§Safety
coder possibly has further requirements.
pub fn initWithData( this: Allocated<Self>, data: &NSData, ) -> Option<Retained<Self>>
pub fn initWithContentsOfFile( this: Allocated<Self>, file_name: &NSString, ) -> Option<Retained<Self>>
pub fn initWithContentsOfURL( this: Allocated<Self>, url: &NSURL, ) -> Option<Retained<Self>>
pub fn initByReferencingFile( this: Allocated<Self>, file_name: &NSString, ) -> Option<Retained<Self>>
pub fn initByReferencingURL( this: Allocated<Self>, url: &NSURL, ) -> Retained<Self>
pub fn initWithPasteboard( this: Allocated<Self>, pasteboard: &NSPasteboard, ) -> Option<Retained<Self>>
NSPasteboard only.pub fn initWithDataIgnoringOrientation( this: Allocated<Self>, data: &NSData, ) -> Option<Retained<Self>>
pub 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 fn size(&self) -> NSSize
pub fn setName(&self, string: Option<&NSImageName>) -> bool
pub fn name(&self) -> Option<Retained<NSImageName>>
pub fn backgroundColor(&self) -> Retained<NSColor>
NSColor only.Sourcepub fn setBackgroundColor(&self, background_color: &NSColor)
Available on crate feature NSColor only.
pub fn setBackgroundColor(&self, background_color: &NSColor)
NSColor only.Setter for backgroundColor.
This is copied when set.
pub fn usesEPSOnResolutionMismatch(&self) -> bool
Sourcepub fn setUsesEPSOnResolutionMismatch(
&self,
uses_eps_on_resolution_mismatch: bool,
)
pub fn setUsesEPSOnResolutionMismatch( &self, uses_eps_on_resolution_mismatch: bool, )
Setter for usesEPSOnResolutionMismatch.
pub fn prefersColorMatch(&self) -> bool
Sourcepub fn setPrefersColorMatch(&self, prefers_color_match: bool)
pub fn setPrefersColorMatch(&self, prefers_color_match: bool)
Setter for prefersColorMatch.
pub fn matchesOnMultipleResolution(&self) -> bool
Sourcepub fn setMatchesOnMultipleResolution(
&self,
matches_on_multiple_resolution: bool,
)
pub fn setMatchesOnMultipleResolution( &self, matches_on_multiple_resolution: bool, )
Setter for matchesOnMultipleResolution.
pub fn matchesOnlyOnBestFittingAxis(&self) -> bool
Sourcepub fn setMatchesOnlyOnBestFittingAxis(
&self,
matches_only_on_best_fitting_axis: bool,
)
pub fn setMatchesOnlyOnBestFittingAxis( &self, matches_only_on_best_fitting_axis: bool, )
Setter for matchesOnlyOnBestFittingAxis.
pub fn drawAtPoint_fromRect_operation_fraction( &self, point: NSPoint, from_rect: NSRect, op: NSCompositingOperation, delta: CGFloat, )
NSGraphics and objc2-core-foundation only.pub fn drawInRect_fromRect_operation_fraction( &self, rect: NSRect, from_rect: NSRect, op: NSCompositingOperation, delta: CGFloat, )
NSGraphics and objc2-core-foundation only.Sourcepub 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>>,
)
Available on crate features NSGraphics and NSImageRep 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.§Safety
hints generic should be of the correct type.
pub fn drawRepresentation_inRect( &self, image_rep: &NSImageRep, rect: NSRect, ) -> bool
NSImageRep only.pub fn drawInRect(&self, rect: NSRect)
pub fn recache(&self)
pub fn TIFFRepresentation(&self) -> Option<Retained<NSData>>
pub fn TIFFRepresentationUsingCompression_factor( &self, comp: NSTIFFCompression, factor: c_float, ) -> Option<Retained<NSData>>
NSBitmapImageRep only.pub fn representations(&self) -> Retained<NSArray<NSImageRep>>
NSImageRep only.pub fn addRepresentations(&self, image_reps: &NSArray<NSImageRep>)
NSImageRep only.pub fn addRepresentation(&self, image_rep: &NSImageRep)
NSImageRep only.pub fn removeRepresentation(&self, image_rep: &NSImageRep)
NSImageRep only.pub fn isValid(&self) -> bool
pub fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSImageDelegate>>>
Sourcepub fn setDelegate(
&self,
delegate: Option<&ProtocolObject<dyn NSImageDelegate>>,
)
pub fn setDelegate( &self, delegate: Option<&ProtocolObject<dyn NSImageDelegate>>, )
Setter for delegate.
This is a weak property.
pub fn imageTypes() -> Retained<NSArray<NSString>>
pub fn imageUnfilteredTypes() -> Retained<NSArray<NSString>>
pub fn canInitWithPasteboard(pasteboard: &NSPasteboard) -> bool
NSPasteboard only.pub fn cacheMode(&self) -> NSImageCacheMode
Sourcepub fn setCacheMode(&self, cache_mode: NSImageCacheMode)
pub fn setCacheMode(&self, cache_mode: NSImageCacheMode)
Setter for cacheMode.
pub fn alignmentRect(&self) -> NSRect
Sourcepub fn setAlignmentRect(&self, alignment_rect: NSRect)
pub fn setAlignmentRect(&self, alignment_rect: NSRect)
Setter for alignmentRect.
pub fn isTemplate(&self) -> bool
Sourcepub fn setTemplate(&self, template: bool)
pub fn setTemplate(&self, template: bool)
Setter for isTemplate.
pub fn accessibilityDescription(&self) -> Option<Retained<NSString>>
Sourcepub fn setAccessibilityDescription(
&self,
accessibility_description: Option<&NSString>,
)
pub fn setAccessibilityDescription( &self, accessibility_description: Option<&NSString>, )
Setter for accessibilityDescription.
This is copied when set.
Sourcepub unsafe fn bestRepresentationForRect_context_hints(
&self,
rect: NSRect,
reference_context: Option<&NSGraphicsContext>,
hints: Option<&NSDictionary<NSImageHintKey, AnyObject>>,
) -> Option<Retained<NSImageRep>>
Available on crate features NSGraphicsContext and NSImageRep 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.§Safety
hints generic should be of the correct type.
Sourcepub 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
Available on crate features 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.§Safety
hints generic should be of the correct type.
pub fn recommendedLayerContentsScale( &self, preferred_contents_scale: CGFloat, ) -> CGFloat
objc2-core-foundation only.pub fn layerContentsForContentsScale( &self, layer_contents_scale: CGFloat, ) -> Retained<AnyObject>
objc2-core-foundation only.pub fn capInsets(&self) -> NSEdgeInsets
Sourcepub fn setCapInsets(&self, cap_insets: NSEdgeInsets)
pub fn setCapInsets(&self, cap_insets: NSEdgeInsets)
Setter for capInsets.
pub fn resizingMode(&self) -> NSImageResizingMode
Sourcepub fn setResizingMode(&self, resizing_mode: NSImageResizingMode)
pub fn setResizingMode(&self, resizing_mode: NSImageResizingMode)
Setter for resizingMode.
pub fn imageWithSymbolConfiguration( &self, configuration: &NSImageSymbolConfiguration, ) -> Option<Retained<NSImage>>
pub fn symbolConfiguration(&self) -> Retained<NSImageSymbolConfiguration>
Sourcepub fn imageWithLocale(&self, locale: Option<&NSLocale>) -> Retained<NSImage>
pub 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 fn imageUnfilteredFileTypes() -> Retained<NSArray<NSString>>
pub fn imageUnfilteredPasteboardTypes() -> Retained<NSArray<NSPasteboardType>>
NSPasteboard only.pub fn imageFileTypes() -> Retained<NSArray<NSString>>
pub fn imagePasteboardTypes() -> Retained<NSArray<NSPasteboardType>>
NSPasteboard only.Sourcepub unsafe fn bestRepresentationForDevice(
&self,
device_description: Option<&NSDictionary>,
) -> Option<Retained<NSImageRep>>
👎Deprecated: Use -[NSImage bestRepresentationForRect:context:hints:] instead. Any deviceDescription dictionary is also a valid hints dictionary.Available on crate feature NSImageRep only.
pub unsafe fn bestRepresentationForDevice( &self, device_description: Option<&NSDictionary>, ) -> Option<Retained<NSImageRep>>
NSImageRep only.§Safety
device_descriptiongeneric should be of the correct type.device_descriptionmight not allowNone.
pub fn lockFocus(&self)
pub fn lockFocusFlipped(&self, flipped: bool)
pub fn unlockFocus(&self)
pub fn setFlipped(&self, flag: bool)
pub fn isFlipped(&self) -> bool
pub fn setScalesWhenResized(&self, flag: bool)
pub fn scalesWhenResized(&self) -> bool
pub fn setDataRetained(&self, flag: bool)
pub fn isDataRetained(&self) -> bool
pub fn setCachedSeparately(&self, flag: bool)
pub fn isCachedSeparately(&self) -> bool
pub fn setCacheDepthMatchesImageDepth(&self, flag: bool)
pub fn cacheDepthMatchesImageDepth(&self) -> bool
pub fn dissolveToPoint_fraction(&self, point: NSPoint, fraction: CGFloat)
objc2-core-foundation only.pub fn dissolveToPoint_fromRect_fraction( &self, point: NSPoint, rect: NSRect, fraction: CGFloat, )
objc2-core-foundation only.pub fn compositeToPoint_operation( &self, point: NSPoint, operation: NSCompositingOperation, )
NSGraphics only.pub fn compositeToPoint_fromRect_operation( &self, point: NSPoint, rect: NSRect, operation: NSCompositingOperation, )
NSGraphics only.pub fn compositeToPoint_operation_fraction( &self, point: NSPoint, operation: NSCompositingOperation, fraction: CGFloat, )
NSGraphics and objc2-core-foundation only.pub fn compositeToPoint_fromRect_operation_fraction( &self, point: NSPoint, rect: NSRect, operation: NSCompositingOperation, fraction: CGFloat, )
NSGraphics and objc2-core-foundation only.Sourcepub unsafe fn lockFocusOnRepresentation(
&self,
image_representation: Option<&NSImageRep>,
)
👎Deprecated: Create an image using +[NSImage imageWithSize:flipped:drawingHandler:], and begin your custom drawing with -[NSImageRep drawInRect:] instead.Available on crate feature NSImageRep only.
pub unsafe fn lockFocusOnRepresentation( &self, image_representation: Option<&NSImageRep>, )
NSImageRep only.§Safety
image_representation might not allow None.
pub 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 DefaultRetained for NSImage
impl DefaultRetained 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
fn writableTypeIdentifiersForItemProvider_class() -> Retained<NSArray<NSString>>
fn writableTypeIdentifiersForItemProvider(&self) -> Retained<NSArray<NSString>>
fn itemProviderVisibilityForRepresentationWithTypeIdentifier_class( type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
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_refSource§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§fn readableTypesForPasteboard(
pasteboard: &NSPasteboard,
) -> Retained<NSArray<NSPasteboardType>>
fn readableTypesForPasteboard( pasteboard: &NSPasteboard, ) -> Retained<NSArray<NSPasteboardType>>
NSPasteboard only.Source§fn readingOptionsForType_pasteboard(
type: &NSPasteboardType,
pasteboard: &NSPasteboard,
) -> NSPasteboardReadingOptions
fn readingOptionsForType_pasteboard( type: &NSPasteboardType, pasteboard: &NSPasteboard, ) -> NSPasteboardReadingOptions
NSPasteboard only.Source§impl NSPasteboardWriting for NSImage
impl NSPasteboardWriting for NSImage
Source§fn writableTypesForPasteboard(
&self,
pasteboard: &NSPasteboard,
) -> Retained<NSArray<NSPasteboardType>>
fn writableTypesForPasteboard( &self, pasteboard: &NSPasteboard, ) -> Retained<NSArray<NSPasteboardType>>
NSPasteboard only.Source§fn writingOptionsForType_pasteboard(
&self,
type: &NSPasteboardType,
pasteboard: &NSPasteboard,
) -> NSPasteboardWritingOptions
fn writingOptionsForType_pasteboard( &self, type: &NSPasteboardType, pasteboard: &NSPasteboard, ) -> NSPasteboardWritingOptions
NSPasteboard only.Source§fn pasteboardPropertyListForType(
&self,
type: &NSPasteboardType,
) -> Option<Retained<AnyObject>>
fn pasteboardPropertyListForType( &self, type: &NSPasteboardType, ) -> Option<Retained<AnyObject>>
NSPasteboard only.