1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8#[cfg(feature = "objc2-core-graphics")]
9use objc2_core_graphics::*;
10#[cfg(feature = "objc2-core-image")]
11#[cfg(not(target_os = "watchos"))]
12use objc2_core_image::*;
13use objc2_foundation::*;
14
15use crate::*;
16
17#[repr(transparent)]
20#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
21pub struct UIColorProminence(pub NSInteger);
22impl UIColorProminence {
23 #[doc(alias = "UIColorProminencePrimary")]
24 pub const Primary: Self = Self(0);
25 #[doc(alias = "UIColorProminenceSecondary")]
26 pub const Secondary: Self = Self(1);
27 #[doc(alias = "UIColorProminenceTertiary")]
28 pub const Tertiary: Self = Self(2);
29 #[doc(alias = "UIColorProminenceQuaternary")]
30 pub const Quaternary: Self = Self(3);
31}
32
33unsafe impl Encode for UIColorProminence {
34 const ENCODING: Encoding = NSInteger::ENCODING;
35}
36
37unsafe impl RefEncode for UIColorProminence {
38 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
39}
40
41extern_class!(
42 #[unsafe(super(NSObject))]
44 #[derive(Debug, PartialEq, Eq, Hash)]
45 pub struct UIColor;
46);
47
48unsafe impl Send for UIColor {}
49
50unsafe impl Sync for UIColor {}
51
52extern_conformance!(
53 unsafe impl NSCoding for UIColor {}
54);
55
56extern_conformance!(
57 unsafe impl NSCopying for UIColor {}
58);
59
60unsafe impl CopyingHelper for UIColor {
61 type Result = Self;
62}
63
64extern_conformance!(
65 unsafe impl NSObjectProtocol for UIColor {}
66);
67
68extern_conformance!(
69 unsafe impl NSSecureCoding for UIColor {}
70);
71
72impl UIColor {
73 extern_methods!(
74 #[cfg(feature = "objc2-core-foundation")]
75 #[unsafe(method(colorWithWhite:alpha:))]
76 #[unsafe(method_family = none)]
77 pub fn colorWithWhite_alpha(white: CGFloat, alpha: CGFloat) -> Retained<UIColor>;
78
79 #[cfg(feature = "objc2-core-foundation")]
80 #[unsafe(method(colorWithHue:saturation:brightness:alpha:))]
81 #[unsafe(method_family = none)]
82 pub fn colorWithHue_saturation_brightness_alpha(
83 hue: CGFloat,
84 saturation: CGFloat,
85 brightness: CGFloat,
86 alpha: CGFloat,
87 ) -> Retained<UIColor>;
88
89 #[cfg(feature = "objc2-core-foundation")]
90 #[unsafe(method(colorWithRed:green:blue:alpha:))]
91 #[unsafe(method_family = none)]
92 pub fn colorWithRed_green_blue_alpha(
93 red: CGFloat,
94 green: CGFloat,
95 blue: CGFloat,
96 alpha: CGFloat,
97 ) -> Retained<UIColor>;
98
99 #[cfg(feature = "objc2-core-foundation")]
100 #[unsafe(method(colorWithDisplayP3Red:green:blue:alpha:))]
101 #[unsafe(method_family = none)]
102 pub fn colorWithDisplayP3Red_green_blue_alpha(
103 display_p3_red: CGFloat,
104 green: CGFloat,
105 blue: CGFloat,
106 alpha: CGFloat,
107 ) -> Retained<UIColor>;
108
109 #[cfg(feature = "objc2-core-graphics")]
110 #[unsafe(method(colorWithCGColor:))]
111 #[unsafe(method_family = none)]
112 pub fn colorWithCGColor(cg_color: &CGColor) -> Retained<UIColor>;
113
114 #[cfg(feature = "UIImage")]
115 #[unsafe(method(colorWithPatternImage:))]
116 #[unsafe(method_family = none)]
117 pub fn colorWithPatternImage(image: &UIImage) -> Retained<UIColor>;
118
119 #[cfg(feature = "objc2-core-image")]
120 #[cfg(not(target_os = "watchos"))]
121 #[unsafe(method(colorWithCIColor:))]
122 #[unsafe(method_family = none)]
123 pub fn colorWithCIColor(ci_color: &CIColor) -> Retained<UIColor>;
124
125 #[cfg(feature = "objc2-core-foundation")]
126 #[unsafe(method(initWithWhite:alpha:))]
127 #[unsafe(method_family = init)]
128 pub fn initWithWhite_alpha(
129 this: Allocated<Self>,
130 white: CGFloat,
131 alpha: CGFloat,
132 ) -> Retained<UIColor>;
133
134 #[cfg(feature = "objc2-core-foundation")]
135 #[unsafe(method(initWithHue:saturation:brightness:alpha:))]
136 #[unsafe(method_family = init)]
137 pub fn initWithHue_saturation_brightness_alpha(
138 this: Allocated<Self>,
139 hue: CGFloat,
140 saturation: CGFloat,
141 brightness: CGFloat,
142 alpha: CGFloat,
143 ) -> Retained<UIColor>;
144
145 #[cfg(feature = "objc2-core-foundation")]
146 #[unsafe(method(initWithRed:green:blue:alpha:))]
147 #[unsafe(method_family = init)]
148 pub fn initWithRed_green_blue_alpha(
149 this: Allocated<Self>,
150 red: CGFloat,
151 green: CGFloat,
152 blue: CGFloat,
153 alpha: CGFloat,
154 ) -> Retained<UIColor>;
155
156 #[cfg(feature = "objc2-core-foundation")]
157 #[unsafe(method(initWithDisplayP3Red:green:blue:alpha:))]
158 #[unsafe(method_family = init)]
159 pub fn initWithDisplayP3Red_green_blue_alpha(
160 this: Allocated<Self>,
161 display_p3_red: CGFloat,
162 green: CGFloat,
163 blue: CGFloat,
164 alpha: CGFloat,
165 ) -> Retained<UIColor>;
166
167 #[cfg(feature = "objc2-core-graphics")]
168 #[unsafe(method(initWithCGColor:))]
169 #[unsafe(method_family = init)]
170 pub fn initWithCGColor(this: Allocated<Self>, cg_color: &CGColor) -> Retained<UIColor>;
171
172 #[cfg(feature = "UIImage")]
173 #[unsafe(method(initWithPatternImage:))]
174 #[unsafe(method_family = init)]
175 pub fn initWithPatternImage(this: Allocated<Self>, image: &UIImage) -> Retained<UIColor>;
176
177 #[cfg(feature = "objc2-core-image")]
178 #[cfg(not(target_os = "watchos"))]
179 #[unsafe(method(initWithCIColor:))]
180 #[unsafe(method_family = init)]
181 pub fn initWithCIColor(this: Allocated<Self>, ci_color: &CIColor) -> Retained<UIColor>;
182
183 #[cfg(feature = "objc2-core-foundation")]
184 #[unsafe(method(initWithRed:green:blue:alpha:exposure:))]
186 #[unsafe(method_family = init)]
187 pub fn initWithRed_green_blue_alpha_exposure(
188 this: Allocated<Self>,
189 red: CGFloat,
190 green: CGFloat,
191 blue: CGFloat,
192 alpha: CGFloat,
193 exposure: CGFloat,
194 ) -> Retained<UIColor>;
195
196 #[cfg(feature = "objc2-core-foundation")]
197 #[unsafe(method(colorWithRed:green:blue:alpha:exposure:))]
198 #[unsafe(method_family = none)]
199 pub fn colorWithRed_green_blue_alpha_exposure(
200 red: CGFloat,
201 green: CGFloat,
202 blue: CGFloat,
203 alpha: CGFloat,
204 exposure: CGFloat,
205 ) -> Retained<UIColor>;
206
207 #[cfg(feature = "objc2-core-foundation")]
208 #[unsafe(method(initWithRed:green:blue:alpha:linearExposure:))]
210 #[unsafe(method_family = init)]
211 pub fn initWithRed_green_blue_alpha_linearExposure(
212 this: Allocated<Self>,
213 red: CGFloat,
214 green: CGFloat,
215 blue: CGFloat,
216 alpha: CGFloat,
217 linear_exposure: CGFloat,
218 ) -> Retained<UIColor>;
219
220 #[cfg(feature = "objc2-core-foundation")]
221 #[unsafe(method(colorWithRed:green:blue:alpha:linearExposure:))]
222 #[unsafe(method_family = none)]
223 pub fn colorWithRed_green_blue_alpha_linearExposure(
224 red: CGFloat,
225 green: CGFloat,
226 blue: CGFloat,
227 alpha: CGFloat,
228 linear_exposure: CGFloat,
229 ) -> Retained<UIColor>;
230
231 #[cfg(feature = "objc2-core-foundation")]
232 #[unsafe(method(colorByApplyingContentHeadroom:))]
234 #[unsafe(method_family = none)]
235 pub fn colorByApplyingContentHeadroom(
236 &self,
237 content_headroom: CGFloat,
238 ) -> Retained<UIColor>;
239
240 #[unsafe(method(blackColor))]
241 #[unsafe(method_family = none)]
242 pub fn blackColor() -> Retained<UIColor>;
243
244 #[unsafe(method(darkGrayColor))]
245 #[unsafe(method_family = none)]
246 pub fn darkGrayColor() -> Retained<UIColor>;
247
248 #[unsafe(method(lightGrayColor))]
249 #[unsafe(method_family = none)]
250 pub fn lightGrayColor() -> Retained<UIColor>;
251
252 #[unsafe(method(whiteColor))]
253 #[unsafe(method_family = none)]
254 pub fn whiteColor() -> Retained<UIColor>;
255
256 #[unsafe(method(grayColor))]
257 #[unsafe(method_family = none)]
258 pub fn grayColor() -> Retained<UIColor>;
259
260 #[unsafe(method(redColor))]
261 #[unsafe(method_family = none)]
262 pub fn redColor() -> Retained<UIColor>;
263
264 #[unsafe(method(greenColor))]
265 #[unsafe(method_family = none)]
266 pub fn greenColor() -> Retained<UIColor>;
267
268 #[unsafe(method(blueColor))]
269 #[unsafe(method_family = none)]
270 pub fn blueColor() -> Retained<UIColor>;
271
272 #[unsafe(method(cyanColor))]
273 #[unsafe(method_family = none)]
274 pub fn cyanColor() -> Retained<UIColor>;
275
276 #[unsafe(method(yellowColor))]
277 #[unsafe(method_family = none)]
278 pub fn yellowColor() -> Retained<UIColor>;
279
280 #[unsafe(method(magentaColor))]
281 #[unsafe(method_family = none)]
282 pub fn magentaColor() -> Retained<UIColor>;
283
284 #[unsafe(method(orangeColor))]
285 #[unsafe(method_family = none)]
286 pub fn orangeColor() -> Retained<UIColor>;
287
288 #[unsafe(method(purpleColor))]
289 #[unsafe(method_family = none)]
290 pub fn purpleColor() -> Retained<UIColor>;
291
292 #[unsafe(method(brownColor))]
293 #[unsafe(method_family = none)]
294 pub fn brownColor() -> Retained<UIColor>;
295
296 #[unsafe(method(clearColor))]
297 #[unsafe(method_family = none)]
298 pub fn clearColor() -> Retained<UIColor>;
299
300 #[unsafe(method(set))]
301 #[unsafe(method_family = none)]
302 pub fn set(&self);
303
304 #[unsafe(method(setFill))]
305 #[unsafe(method_family = none)]
306 pub fn setFill(&self);
307
308 #[unsafe(method(setStroke))]
309 #[unsafe(method_family = none)]
310 pub fn setStroke(&self);
311
312 #[cfg(feature = "objc2-core-foundation")]
313 #[unsafe(method(getWhite:alpha:))]
318 #[unsafe(method_family = none)]
319 pub unsafe fn getWhite_alpha(&self, white: *mut CGFloat, alpha: *mut CGFloat) -> bool;
320
321 #[cfg(feature = "objc2-core-foundation")]
322 #[unsafe(method(getHue:saturation:brightness:alpha:))]
329 #[unsafe(method_family = none)]
330 pub unsafe fn getHue_saturation_brightness_alpha(
331 &self,
332 hue: *mut CGFloat,
333 saturation: *mut CGFloat,
334 brightness: *mut CGFloat,
335 alpha: *mut CGFloat,
336 ) -> bool;
337
338 #[cfg(feature = "objc2-core-foundation")]
339 #[unsafe(method(getRed:green:blue:alpha:))]
346 #[unsafe(method_family = none)]
347 pub unsafe fn getRed_green_blue_alpha(
348 &self,
349 red: *mut CGFloat,
350 green: *mut CGFloat,
351 blue: *mut CGFloat,
352 alpha: *mut CGFloat,
353 ) -> bool;
354
355 #[cfg(feature = "objc2-core-foundation")]
356 #[unsafe(method(colorWithAlphaComponent:))]
357 #[unsafe(method_family = none)]
358 pub fn colorWithAlphaComponent(&self, alpha: CGFloat) -> Retained<UIColor>;
359
360 #[cfg(feature = "objc2-core-graphics")]
361 #[unsafe(method(CGColor))]
367 #[unsafe(method_family = none)]
368 pub unsafe fn CGColor(&self) -> Retained<CGColor>;
369
370 #[cfg(feature = "objc2-core-image")]
371 #[cfg(not(target_os = "watchos"))]
372 #[unsafe(method(CIColor))]
378 #[unsafe(method_family = none)]
379 pub unsafe fn CIColor(&self) -> Retained<CIColor>;
380
381 #[cfg(feature = "objc2-core-foundation")]
382 #[unsafe(method(linearExposure))]
390 #[unsafe(method_family = none)]
391 pub unsafe fn linearExposure(&self) -> CGFloat;
392
393 #[unsafe(method(standardDynamicRangeColor))]
401 #[unsafe(method_family = none)]
402 pub unsafe fn standardDynamicRangeColor(&self) -> Retained<UIColor>;
403 );
404}
405
406impl UIColor {
408 extern_methods!(
409 #[unsafe(method(init))]
410 #[unsafe(method_family = init)]
411 pub fn init(this: Allocated<Self>) -> Retained<Self>;
412
413 #[unsafe(method(new))]
414 #[unsafe(method_family = new)]
415 pub fn new() -> Retained<Self>;
416 );
417}
418
419impl DefaultRetained for UIColor {
420 #[inline]
421 fn default_retained() -> Retained<Self> {
422 Self::new()
423 }
424}
425
426impl UIColor {
428 extern_methods!();
429}
430
431extern_conformance!(
432 unsafe impl NSItemProviderReading for UIColor {}
433);
434
435extern_conformance!(
436 unsafe impl NSItemProviderWriting for UIColor {}
437);
438
439mod private_CIColorUIKitAdditions {
440 pub trait Sealed {}
441}
442
443#[doc(alias = "UIKitAdditions")]
445pub unsafe trait CIColorUIKitAdditions:
446 ClassType + Sized + private_CIColorUIKitAdditions::Sealed
447{
448 extern_methods!(
449 #[unsafe(method(initWithColor:))]
450 #[unsafe(method_family = init)]
451 fn initWithColor(this: Allocated<Self>, color: &UIColor) -> Retained<Self>;
452 );
453}
454
455#[cfg(feature = "objc2-core-image")]
456#[cfg(not(target_os = "watchos"))]
457impl private_CIColorUIKitAdditions::Sealed for CIColor {}
458#[cfg(feature = "objc2-core-image")]
459#[cfg(not(target_os = "watchos"))]
460unsafe impl CIColorUIKitAdditions for CIColor {}
461
462impl UIColor {
464 extern_methods!(
465 #[unsafe(method(colorNamed:))]
466 #[unsafe(method_family = none)]
467 pub fn colorNamed(name: &NSString) -> Option<Retained<UIColor>>;
468
469 #[cfg(feature = "UITraitCollection")]
470 #[unsafe(method(colorNamed:inBundle:compatibleWithTraitCollection:))]
471 #[unsafe(method_family = none)]
472 pub fn colorNamed_inBundle_compatibleWithTraitCollection(
473 name: &NSString,
474 bundle: Option<&NSBundle>,
475 trait_collection: Option<&UITraitCollection>,
476 ) -> Option<Retained<UIColor>>;
477 );
478}
479
480impl UIColor {
482 extern_methods!(
483 #[cfg(all(feature = "UITraitCollection", feature = "block2"))]
484 #[unsafe(method(colorWithDynamicProvider:))]
488 #[unsafe(method_family = none)]
489 pub unsafe fn colorWithDynamicProvider(
490 dynamic_provider: &block2::DynBlock<
491 dyn Fn(NonNull<UITraitCollection>) -> NonNull<UIColor>,
492 >,
493 ) -> Retained<UIColor>;
494
495 #[cfg(all(feature = "UITraitCollection", feature = "block2"))]
496 #[unsafe(method(initWithDynamicProvider:))]
500 #[unsafe(method_family = init)]
501 pub unsafe fn initWithDynamicProvider(
502 this: Allocated<Self>,
503 dynamic_provider: &block2::DynBlock<
504 dyn Fn(NonNull<UITraitCollection>) -> NonNull<UIColor>,
505 >,
506 ) -> Retained<UIColor>;
507
508 #[cfg(feature = "UITraitCollection")]
509 #[unsafe(method(resolvedColorWithTraitCollection:))]
510 #[unsafe(method_family = none)]
511 pub fn resolvedColorWithTraitCollection(
512 &self,
513 trait_collection: &UITraitCollection,
514 ) -> Retained<UIColor>;
515 );
516}
517
518impl UIColor {
520 extern_methods!(
521 #[unsafe(method(colorWithProminence:))]
522 #[unsafe(method_family = none)]
523 pub fn colorWithProminence(&self, prominence: UIColorProminence) -> Retained<UIColor>;
524
525 #[unsafe(method(prominence))]
531 #[unsafe(method_family = none)]
532 pub unsafe fn prominence(&self) -> UIColorProminence;
533 );
534}