pub struct NSColor { /* private fields */ }
NSColor
only.Expand description
Implementations§
impl NSColor
NSAccessibilityColorConformance.
Source§impl NSColor
impl NSColor
pub fn init(this: Allocated<Self>) -> Retained<Self>
Sourcepub unsafe fn initWithCoder(
this: Allocated<Self>,
coder: &NSCoder,
) -> Option<Retained<Self>>
pub unsafe fn initWithCoder( this: Allocated<Self>, coder: &NSCoder, ) -> Option<Retained<Self>>
§Safety
coder
possibly has further requirements.
Sourcepub unsafe fn colorWithColorSpace_components_count(
space: &NSColorSpace,
components: NonNull<CGFloat>,
number_of_components: NSInteger,
) -> Retained<NSColor>
Available on crate features NSColorSpace
and objc2-core-foundation
only.
pub unsafe fn colorWithColorSpace_components_count( space: &NSColorSpace, components: NonNull<CGFloat>, number_of_components: NSInteger, ) -> Retained<NSColor>
NSColorSpace
and objc2-core-foundation
only.§Safety
components
must be a valid pointer.
pub fn colorWithSRGBRed_green_blue_alpha( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithGenericGamma22White_alpha( white: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithDisplayP3Red_green_blue_alpha( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithWhite_alpha(white: CGFloat, alpha: CGFloat) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithRed_green_blue_alpha( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithHue_saturation_brightness_alpha( hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithColorSpace_hue_saturation_brightness_alpha( space: &NSColorSpace, hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
NSColorSpace
and objc2-core-foundation
only.pub fn colorWithCatalogName_colorName( list_name: &NSColorListName, color_name: &NSColorName, ) -> Option<Retained<NSColor>>
NSColorList
only.pub fn colorNamed_bundle( name: &NSColorName, bundle: Option<&NSBundle>, ) -> Option<Retained<NSColor>>
NSColorList
only.pub fn colorNamed(name: &NSColorName) -> Option<Retained<NSColor>>
NSColorList
only.Sourcepub unsafe fn colorWithName_dynamicProvider(
color_name: Option<&NSColorName>,
dynamic_provider: &DynBlock<dyn Fn(NonNull<NSAppearance>) -> NonNull<NSColor>>,
) -> Retained<NSColor>
Available on crate features NSAppearance
and NSColorList
and block2
only.
pub unsafe fn colorWithName_dynamicProvider( color_name: Option<&NSColorName>, dynamic_provider: &DynBlock<dyn Fn(NonNull<NSAppearance>) -> NonNull<NSColor>>, ) -> Retained<NSColor>
NSAppearance
and NSColorList
and block2
only.§Safety
dynamic_provider
block’s return must be a valid pointer.
pub fn colorWithDeviceWhite_alpha( white: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithDeviceRed_green_blue_alpha( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithDeviceHue_saturation_brightness_alpha( hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithDeviceCyan_magenta_yellow_black_alpha( cyan: CGFloat, magenta: CGFloat, yellow: CGFloat, black: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithCalibratedWhite_alpha( white: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithCalibratedRed_green_blue_alpha( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithCalibratedHue_saturation_brightness_alpha( hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.pub fn colorWithPatternImage(image: &NSImage) -> Retained<NSColor>
NSImage
only.pub fn type(&self) -> NSColorType
pub fn colorUsingType(&self, type: NSColorType) -> Option<Retained<NSColor>>
pub fn colorUsingColorSpace( &self, space: &NSColorSpace, ) -> Option<Retained<NSColor>>
NSColorSpace
only.Sourcepub fn colorWithRed_green_blue_alpha_exposure(
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat,
exposure: CGFloat,
) -> Retained<NSColor>
Available on crate feature objc2-core-foundation
only.
pub fn colorWithRed_green_blue_alpha_exposure( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, exposure: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.Generates an HDR color in the extended sRGB colorspace by applying an exposure to the SDR color defined by the red, green, and blue components. The red
, green
, and blue
components have a nominal range of [0..1], exposure
is a value >= 0. To produce an HDR color, we process the given color in a linear color space, multiplying component values by 2^exposure
. The produced color will have a contentHeadroom
equal to the linearized exposure value. Each whole value of exposure produces a color that is twice as bright.
Sourcepub fn colorWithRed_green_blue_alpha_linearExposure(
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat,
linear_exposure: CGFloat,
) -> Retained<NSColor>
Available on crate feature objc2-core-foundation
only.
pub fn colorWithRed_green_blue_alpha_linearExposure( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, linear_exposure: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.Generates an HDR color in the extended sRGB colorspace by applying an exposure to the SDR color defined by the red, green, and blue components. The red
, green
, and blue
components have a nominal range of [0..1], linearExposure
is a value >= 1. To produce an HDR color, we process the given color in a linear color space, multiplying component values by linearExposure
. The produced color will have a contentHeadroom
equal to linearExposure
. Each doubling of linearExposure
produces a color that is twice as bright.
Sourcepub fn colorByApplyingContentHeadroom(
&self,
content_headroom: CGFloat,
) -> Retained<NSColor>
Available on crate feature objc2-core-foundation
only.
pub fn colorByApplyingContentHeadroom( &self, content_headroom: CGFloat, ) -> Retained<NSColor>
objc2-core-foundation
only.Reinterpret the color by applying a new contentHeadroom
without changing the color components. Changing the contentHeadroom
redefines the color relative to a different peak white, changing its behavior under tone mapping and the result of calling standardDynamicRangeColor
. The new color will have a contentHeadroom
>= 1.0. If called on a color with a color space that does not support extended range, or does not have an equivalent extended range counterpart, this will return self
.
Sourcepub fn standardDynamicRangeColor(&self) -> Retained<NSColor>
pub fn standardDynamicRangeColor(&self) -> Retained<NSColor>
In some cases it is useful to recover the color that was base the SDR color that was exposed to generate an HDR color. If a color’s linearExposure
is > 1, then this will return the base SDR color. If the color is not an HDR color, this will return self
.
pub fn blackColor() -> Retained<NSColor>
pub fn darkGrayColor() -> Retained<NSColor>
pub fn lightGrayColor() -> Retained<NSColor>
pub fn whiteColor() -> Retained<NSColor>
pub fn grayColor() -> Retained<NSColor>
pub fn redColor() -> Retained<NSColor>
pub fn greenColor() -> Retained<NSColor>
pub fn blueColor() -> Retained<NSColor>
pub fn cyanColor() -> Retained<NSColor>
pub fn yellowColor() -> Retained<NSColor>
pub fn magentaColor() -> Retained<NSColor>
pub fn orangeColor() -> Retained<NSColor>
pub fn purpleColor() -> Retained<NSColor>
pub fn brownColor() -> Retained<NSColor>
pub fn clearColor() -> Retained<NSColor>
pub fn labelColor() -> Retained<NSColor>
pub fn secondaryLabelColor() -> Retained<NSColor>
pub fn tertiaryLabelColor() -> Retained<NSColor>
pub fn quaternaryLabelColor() -> Retained<NSColor>
pub fn quinaryLabelColor() -> Retained<NSColor>
Sourcepub fn linkColor() -> Retained<NSColor>
pub fn linkColor() -> Retained<NSColor>
Used for large scale images or subtle decorative elements; not for general foreground content.
pub fn placeholderTextColor() -> Retained<NSColor>
pub fn windowFrameTextColor() -> Retained<NSColor>
pub fn selectedMenuItemTextColor() -> Retained<NSColor>
pub fn alternateSelectedControlTextColor() -> Retained<NSColor>
pub fn headerTextColor() -> Retained<NSColor>
pub fn separatorColor() -> Retained<NSColor>
pub fn gridColor() -> Retained<NSColor>
pub fn windowBackgroundColor() -> Retained<NSColor>
pub fn underPageBackgroundColor() -> Retained<NSColor>
pub fn controlBackgroundColor() -> Retained<NSColor>
pub fn selectedContentBackgroundColor() -> Retained<NSColor>
pub fn unemphasizedSelectedContentBackgroundColor() -> Retained<NSColor>
pub fn alternatingContentBackgroundColors() -> Retained<NSArray<NSColor>>
pub fn findHighlightColor() -> Retained<NSColor>
pub fn textColor() -> Retained<NSColor>
pub fn textBackgroundColor() -> Retained<NSColor>
pub fn textInsertionPointColor() -> Retained<NSColor>
pub fn selectedTextColor() -> Retained<NSColor>
pub fn selectedTextBackgroundColor() -> Retained<NSColor>
pub fn unemphasizedSelectedTextBackgroundColor() -> Retained<NSColor>
pub fn unemphasizedSelectedTextColor() -> Retained<NSColor>
pub fn controlColor() -> Retained<NSColor>
pub fn controlTextColor() -> Retained<NSColor>
pub fn selectedControlColor() -> Retained<NSColor>
pub fn selectedControlTextColor() -> Retained<NSColor>
pub fn disabledControlTextColor() -> Retained<NSColor>
pub fn keyboardFocusIndicatorColor() -> Retained<NSColor>
pub fn scrubberTexturedBackgroundColor() -> Retained<NSColor>
pub fn systemRedColor() -> Retained<NSColor>
pub fn systemGreenColor() -> Retained<NSColor>
pub fn systemBlueColor() -> Retained<NSColor>
pub fn systemOrangeColor() -> Retained<NSColor>
pub fn systemYellowColor() -> Retained<NSColor>
pub fn systemBrownColor() -> Retained<NSColor>
pub fn systemPinkColor() -> Retained<NSColor>
pub fn systemPurpleColor() -> Retained<NSColor>
pub fn systemGrayColor() -> Retained<NSColor>
pub fn systemTealColor() -> Retained<NSColor>
pub fn systemIndigoColor() -> Retained<NSColor>
pub fn systemMintColor() -> Retained<NSColor>
pub fn systemCyanColor() -> Retained<NSColor>
Sourcepub fn systemFillColor() -> Retained<NSColor>
pub fn systemFillColor() -> Retained<NSColor>
Fill colors for UI elements. These are meant to be used over the background colors, since their alpha component is less than 1.
systemFillColor is appropriate for filling thin shapes, such as the track of a slider.
Sourcepub fn secondarySystemFillColor() -> Retained<NSColor>
pub fn secondarySystemFillColor() -> Retained<NSColor>
secondarySystemFillColor is appropriate for filling small-size shapes, such as the backing of a progress indicator.
Sourcepub fn tertiarySystemFillColor() -> Retained<NSColor>
pub fn tertiarySystemFillColor() -> Retained<NSColor>
tertiarySystemFillColor is appropriate for filling medium-size shapes, such as the backing of a switch.
Sourcepub fn quaternarySystemFillColor() -> Retained<NSColor>
pub fn quaternarySystemFillColor() -> Retained<NSColor>
quaternarySystemFillColor is appropriate for filling large areas, such as a group box or tab pane.
Sourcepub fn quinarySystemFillColor() -> Retained<NSColor>
pub fn quinarySystemFillColor() -> Retained<NSColor>
quinarySystemFillColor is appropriate for filling large areas that require subtle emphasis, such as content of a form..
Sourcepub fn controlAccentColor() -> Retained<NSColor>
pub fn controlAccentColor() -> Retained<NSColor>
A dynamic color that reflects the user’s current preferred accent color. This color automatically updates when the accent color preference changes. Do not make assumptions about the color space of this color, which may change across releases.
pub fn currentControlTint() -> NSControlTint
NSCell
only.pub fn colorForControlTint(control_tint: NSControlTint) -> Retained<NSColor>
NSCell
only.pub fn highlightColor() -> Retained<NSColor>
pub fn shadowColor() -> Retained<NSColor>
pub fn highlightWithLevel(&self, val: CGFloat) -> Option<Retained<NSColor>>
objc2-core-foundation
only.pub fn shadowWithLevel(&self, val: CGFloat) -> Option<Retained<NSColor>>
objc2-core-foundation
only.Sourcepub fn colorWithSystemEffect(
&self,
system_effect: NSColorSystemEffect,
) -> Retained<NSColor>
pub fn colorWithSystemEffect( &self, system_effect: NSColorSystemEffect, ) -> Retained<NSColor>
Returns a color representing the base color with a system defined effect applied to it. This color is safe to create before draw time, as the resolution of the final color only happens when being -set
, retrieving its CGColor
, resolving with -colorWithType:
, etc. The return color type is .named
.
pub fn set(&self)
pub fn setFill(&self)
pub fn setStroke(&self)
pub fn blendedColorWithFraction_ofColor( &self, fraction: CGFloat, color: &NSColor, ) -> Option<Retained<NSColor>>
objc2-core-foundation
only.pub fn colorWithAlphaComponent(&self, alpha: CGFloat) -> Retained<NSColor>
objc2-core-foundation
only.Sourcepub fn catalogNameComponent(&self) -> Retained<NSColorListName>
Available on crate feature NSColorList
only.
pub fn catalogNameComponent(&self) -> Retained<NSColorListName>
NSColorList
only.- Methods to get various components of colors. Not all of the methods apply to all colors; if called, they raise. **
pub fn colorNameComponent(&self) -> Retained<NSColorName>
NSColorList
only.pub fn localizedCatalogNameComponent(&self) -> Retained<NSString>
pub fn localizedColorNameComponent(&self) -> Retained<NSString>
pub fn redComponent(&self) -> CGFloat
objc2-core-foundation
only.pub fn greenComponent(&self) -> CGFloat
objc2-core-foundation
only.pub fn blueComponent(&self) -> CGFloat
objc2-core-foundation
only.Sourcepub unsafe fn getRed_green_blue_alpha(
&self,
red: *mut CGFloat,
green: *mut CGFloat,
blue: *mut CGFloat,
alpha: *mut CGFloat,
)
Available on crate feature objc2-core-foundation
only.
pub unsafe fn getRed_green_blue_alpha( &self, red: *mut CGFloat, green: *mut CGFloat, blue: *mut CGFloat, alpha: *mut CGFloat, )
objc2-core-foundation
only.§Safety
red
must be a valid pointer or null.green
must be a valid pointer or null.blue
must be a valid pointer or null.alpha
must be a valid pointer or null.
pub fn hueComponent(&self) -> CGFloat
objc2-core-foundation
only.pub fn saturationComponent(&self) -> CGFloat
objc2-core-foundation
only.pub fn brightnessComponent(&self) -> CGFloat
objc2-core-foundation
only.Sourcepub unsafe fn getHue_saturation_brightness_alpha(
&self,
hue: *mut CGFloat,
saturation: *mut CGFloat,
brightness: *mut CGFloat,
alpha: *mut CGFloat,
)
Available on crate feature objc2-core-foundation
only.
pub unsafe fn getHue_saturation_brightness_alpha( &self, hue: *mut CGFloat, saturation: *mut CGFloat, brightness: *mut CGFloat, alpha: *mut CGFloat, )
objc2-core-foundation
only.§Safety
hue
must be a valid pointer or null.saturation
must be a valid pointer or null.brightness
must be a valid pointer or null.alpha
must be a valid pointer or null.
pub fn whiteComponent(&self) -> CGFloat
objc2-core-foundation
only.Sourcepub unsafe fn getWhite_alpha(&self, white: *mut CGFloat, alpha: *mut CGFloat)
Available on crate feature objc2-core-foundation
only.
pub unsafe fn getWhite_alpha(&self, white: *mut CGFloat, alpha: *mut CGFloat)
objc2-core-foundation
only.§Safety
white
must be a valid pointer or null.alpha
must be a valid pointer or null.
pub fn cyanComponent(&self) -> CGFloat
objc2-core-foundation
only.pub fn magentaComponent(&self) -> CGFloat
objc2-core-foundation
only.pub fn yellowComponent(&self) -> CGFloat
objc2-core-foundation
only.pub fn blackComponent(&self) -> CGFloat
objc2-core-foundation
only.Sourcepub unsafe fn getCyan_magenta_yellow_black_alpha(
&self,
cyan: *mut CGFloat,
magenta: *mut CGFloat,
yellow: *mut CGFloat,
black: *mut CGFloat,
alpha: *mut CGFloat,
)
Available on crate feature objc2-core-foundation
only.
pub unsafe fn getCyan_magenta_yellow_black_alpha( &self, cyan: *mut CGFloat, magenta: *mut CGFloat, yellow: *mut CGFloat, black: *mut CGFloat, alpha: *mut CGFloat, )
objc2-core-foundation
only.§Safety
cyan
must be a valid pointer or null.magenta
must be a valid pointer or null.yellow
must be a valid pointer or null.black
must be a valid pointer or null.alpha
must be a valid pointer or null.
pub fn colorSpace(&self) -> Retained<NSColorSpace>
NSColorSpace
only.pub fn numberOfComponents(&self) -> NSInteger
Sourcepub unsafe fn getComponents(&self, components: NonNull<CGFloat>)
Available on crate feature objc2-core-foundation
only.
pub unsafe fn getComponents(&self, components: NonNull<CGFloat>)
objc2-core-foundation
only.§Safety
components
must be a valid pointer.
pub fn patternImage(&self) -> Retained<NSImage>
NSImage
only.pub fn alphaComponent(&self) -> CGFloat
objc2-core-foundation
only.Sourcepub fn linearExposure(&self) -> CGFloat
Available on crate feature objc2-core-foundation
only.
pub fn linearExposure(&self) -> CGFloat
objc2-core-foundation
only.For HDR colors, the linear brightness multiplier that was applied when generating the color. Colors created with an exposure by NSColor create CGColors that are tagged with a contentHeadroom value. While CGColors created without a contentHeadroom tag will return 0 from CGColorGetHeadroom, NSColors generated in a similar fashion return a linearExposure of 1.0.
pub fn colorFromPasteboard( paste_board: &NSPasteboard, ) -> Option<Retained<NSColor>>
NSPasteboard
only.pub fn writeToPasteboard(&self, paste_board: &NSPasteboard)
NSPasteboard
only.pub fn drawSwatchInRect(&self, rect: NSRect)
pub fn ignoresAlpha(mtm: MainThreadMarker) -> bool
showsAlpha
in NSColorPanel
and supportsAlpha
in NSColorWell
to control alpha behavior for individual controls.Sourcepub fn setIgnoresAlpha(ignores_alpha: bool, mtm: MainThreadMarker)
👎Deprecated: Use showsAlpha
in NSColorPanel
and supportsAlpha
in NSColorWell
to control alpha behavior for individual controls.
pub fn setIgnoresAlpha(ignores_alpha: bool, mtm: MainThreadMarker)
showsAlpha
in NSColorPanel
and supportsAlpha
in NSColorWell
to control alpha behavior for individual controls.Setter for ignoresAlpha
.
Source§impl NSColor
NSDeprecated.
impl NSColor
NSDeprecated.
Sourcepub fn controlHighlightColor() -> Retained<NSColor>
👎Deprecated: Use a color that matches the semantics being used, such as separatorColor
pub fn controlHighlightColor() -> Retained<NSColor>
separatorColor
Historically used as the inner border highlight color for beveled buttons. No longer used.
Sourcepub fn controlLightHighlightColor() -> Retained<NSColor>
👎Deprecated: Use a color that matches the semantics being used, such as separatorColor
pub fn controlLightHighlightColor() -> Retained<NSColor>
separatorColor
Historically used as the outer border highlight color for beveled buttons. No longer used.
Sourcepub fn controlShadowColor() -> Retained<NSColor>
👎Deprecated: Use a color that matches the semantics being used, such as separatorColor
pub fn controlShadowColor() -> Retained<NSColor>
separatorColor
Historically used as the inner border shadow color for beveled buttons. No longer used.
Sourcepub fn controlDarkShadowColor() -> Retained<NSColor>
👎Deprecated: Use a color that matches the semantics being used, such as separatorColor
pub fn controlDarkShadowColor() -> Retained<NSColor>
separatorColor
Historically used as the outer border shadow color for beveled buttons. No longer used.
Sourcepub fn scrollBarColor() -> Retained<NSColor>
👎Deprecated: Use NSScroller instead
pub fn scrollBarColor() -> Retained<NSColor>
Historically used as the color of scroll bars. No longer used.
Sourcepub fn knobColor() -> Retained<NSColor>
👎Deprecated: Use NSScroller instead
pub fn knobColor() -> Retained<NSColor>
Historically used as the color of scroll bar knobs. No longer used.
Sourcepub fn selectedKnobColor() -> Retained<NSColor>
👎Deprecated: Use NSScroller instead
pub fn selectedKnobColor() -> Retained<NSColor>
Historically used as the color of scroll bar knobs being dragged. No longer used.
Sourcepub fn windowFrameColor() -> Retained<NSColor>
👎Deprecated: Use NSVisualEffectMaterialTitlebar
pub fn windowFrameColor() -> Retained<NSColor>
Historically used as the color of the window chrome, which is no longer able to be represented by a color. No longer used.
Sourcepub fn selectedMenuItemColor() -> Retained<NSColor>
👎Deprecated: Use NSVisualEffectMaterialSelection
pub fn selectedMenuItemColor() -> Retained<NSColor>
Historically used as the color of selected menu items, which is no longer a color but a tinted blur effect. No longer used.
Sourcepub fn headerColor() -> Retained<NSColor>
👎Deprecated: Use NSVisualEffectMaterialHeaderView
pub fn headerColor() -> Retained<NSColor>
Historically used as the color of table headers, which is no longer a color but a tinted blur effect.
Sourcepub fn secondarySelectedControlColor() -> Retained<NSColor>
👎Deprecated
pub fn secondarySelectedControlColor() -> Retained<NSColor>
The background color of selected content or text that is unemphasized. Older alias for +unemphasizedSelectedContentBackgroundColor and +unemphasizedSelectedTextBackgroundColor
Sourcepub fn alternateSelectedControlColor() -> Retained<NSColor>
👎Deprecated
pub fn alternateSelectedControlColor() -> Retained<NSColor>
The background color of selected and emphasized (focused) content: table views rows, collection views, etc. Older alias for +selectedContentBackgroundColor
Sourcepub fn controlAlternatingRowBackgroundColors() -> Retained<NSArray<NSColor>>
👎Deprecated
pub fn controlAlternatingRowBackgroundColors() -> Retained<NSArray<NSColor>>
The background colors for alternating content items: such as table view rows, collection view items. Older alias for +alternatingContentBackgroundColors
pub fn colorSpaceName(&self) -> Retained<NSColorSpaceName>
NSGraphics
only.Sourcepub unsafe fn colorUsingColorSpaceName_device(
&self,
name: Option<&NSColorSpaceName>,
device_description: Option<&NSDictionary<NSDeviceDescriptionKey, AnyObject>>,
) -> Option<Retained<NSColor>>
👎Deprecated: Use -colorUsingType: or -colorUsingColorSpace: insteadAvailable on crate feature NSGraphics
only.
pub unsafe fn colorUsingColorSpaceName_device( &self, name: Option<&NSColorSpaceName>, device_description: Option<&NSDictionary<NSDeviceDescriptionKey, AnyObject>>, ) -> Option<Retained<NSColor>>
NSGraphics
only.§Safety
device_description
generic should be of the correct type.
pub fn colorUsingColorSpaceName( &self, name: &NSColorSpaceName, ) -> Option<Retained<NSColor>>
NSGraphics
only.impl NSColor
NSQuartzCoreAdditions.
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 NSColor
impl ClassType for NSColor
Source§const NAME: &'static str = "NSColor"
const NAME: &'static str = "NSColor"
Source§type ThreadKind = <<NSColor as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSColor as ClassType>::Super as ClassType>::ThreadKind
Source§impl CopyingHelper for NSColor
impl CopyingHelper for NSColor
Source§impl DefaultRetained for NSColor
impl DefaultRetained for NSColor
Source§impl NSAccessibilityColor for NSColor
Available on crate feature NSAccessibilityColor
only.
impl NSAccessibilityColor for NSColor
NSAccessibilityColor
only.Source§impl NSCopying for NSColor
impl NSCopying for NSColor
Source§impl NSObjectProtocol for NSColor
impl NSObjectProtocol for NSColor
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 NSColor
impl NSPasteboardReading for NSColor
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 NSColor
impl NSPasteboardWriting for NSColor
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.