Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSColor: add AppKit-defined colors #660

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
511 changes: 507 additions & 4 deletions cocoa/src/appkit.rs
Original file line number Diff line number Diff line change
@@ -4587,7 +4587,6 @@ impl NSColorSpace for id {
}

pub trait NSColor: Sized {
unsafe fn clearColor(_: Self) -> id;
unsafe fn colorWithRed_green_blue_alpha_(
_: Self,
r: CGFloat,
@@ -4626,6 +4625,171 @@ pub trait NSColor: Sized {

unsafe fn colorUsingColorSpace_(self, color_space: id) -> id;

// UI Element Colors
// https://developer.apple.com/documentation/appkit/nscolor/ui_element_colors?language=objc

// Label Colors
/// The primary color to use for text labels.
unsafe fn labelColor(_: Self) -> id;
/// The secondary color to use for text labels.
unsafe fn secondaryLabelColor(_: Self) -> id;
/// The tertiary color to use for text labels.
unsafe fn tertiaryLabelColor(_: Self) -> id;
/// The quaternary color to use for text labels and separators.
unsafe fn quaternaryLabelColor(_: Self) -> id;

// Text Colors
/// The color to use for text.
unsafe fn textColor(_: Self) -> id;
/// The color to use for placeholder text in controls or text views.
unsafe fn placeholderTextColor(_: Self) -> id;
/// The color to use for selected text.
unsafe fn selectedTextColor(_: Self) -> id;
/// The color to use for the background area behind text.
unsafe fn textBackgroundColor(_: Self) -> id;
/// The color to use for the background of selected text.
unsafe fn selectedTextBackgroundColor(_: Self) -> id;
/// The color to use for the keyboard focus ring around controls.
unsafe fn keyboardFocusIndicatorColor(_: Self) -> id;
/// The color to use for selected text in an unemphasized context.
unsafe fn unemphasizedSelectedTextColor(_: Self) -> id;
/// The color to use for the text background in an unemphasized context.
unsafe fn unemphasizedSelectedTextBackgroundColor(_: Self) -> id;

// Content Colors
/// The color to use for links.
unsafe fn linkColor(_: Self) -> id;
/// The color to use for separators between different sections of content.
unsafe fn separatorColor(_: Self) -> id;
/// The color to use for the background of selected and emphasized content.
unsafe fn selectedContentBackgroundColor(_: Self) -> id;
/// The color to use for selected and unemphasized content.
unsafe fn unemphasizedSelectedContentBackgroundColor(_: Self) -> id;

// Menu Colors
/// The color to use for the text in menu items.
unsafe fn selectedMenuItemTextColor(_: Self) -> id;

// Table Colors
/// The color to use for the optional gridlines, such as those in a table view.
unsafe fn gridColor(_: Self) -> id;
/// The color to use for text in header cells in table views and outline views.
unsafe fn headerTextColor(_: Self) -> id;
/// The colors to use for alternating content, typically found in table views and collection views.
unsafe fn alternatingContentBackgroundColors(_: Self) -> id;

// Control Colors
/// The user's current accent color preference.
unsafe fn controlAccentColor(_: Self) -> id;
/// The color to use for the flat surfaces of a control.
unsafe fn controlColor(_: Self) -> id;
/// The color to use for the background of large controls, such as scroll views or table views.
unsafe fn controlBackgroundColor(_: Self) -> id;
/// The color to use for text on enabled controls.
unsafe fn controlTextColor(_: Self) -> id;
/// The color to use for text on disabled controls.
unsafe fn disabledControlTextColor(_: Self) -> id;
/// The current system control tint color.
unsafe fn currentControlTint(_: Self) -> id;
/// The color to use for the face of a selected control—that is, a control that has been clicked or is being dragged.
unsafe fn selectedControlColor(_: Self) -> id;
/// The color to use for text in a selected control—that is, a control being clicked or dragged.
unsafe fn selectedControlTextColor(_: Self) -> id;
/// The color to use for text in a selected control.
unsafe fn alternateSelectedControlTextColor(_: Self) -> id;
/// The patterned color to use for the background of a scrubber control.
unsafe fn scrubberTexturedBackgroundColor(_: Self) -> id;

// Window Colors
/// The color to use for the window background.
unsafe fn windowBackgroundColor(_: Self) -> id;
/// The color to use for text in a window's frame.
unsafe fn windowFrameTextColor(_: Self) -> id;
/// The color to use in the area beneath your window's views.
unsafe fn underPageBackgroundColor(_: Self) -> id;

// Highlights and Shadows
/// The highlight color to use for the bubble that shows inline search result values.
unsafe fn findHighlightColor(_: Self) -> id;
/// The color to use as a virtual light source on the screen.
unsafe fn highlightColor(_: Self) -> id;
/// The color to use for virtual shadows cast by raised objects on the screen.
unsafe fn shadowColor(_: Self) -> id;

// Fill Colors
unsafe fn quaternarySystemFillColor(_: Self) -> id;
unsafe fn quinaryLabelColor(_: Self) -> id;
unsafe fn quinarySystemFillColor(_: Self) -> id;
unsafe fn secondarySystemFillColor(_: Self) -> id;
unsafe fn systemFillColor(_: Self) -> id;
unsafe fn tertiarySystemFillColor(_: Self) -> id;
unsafe fn textInsertionPointColor(_: Self) -> id;

// Standard Colors
// https://developer.apple.com/documentation/appkit/nscolor/standard_colors?language=objc

// Adaptable System Colors
/// Returns a color object for blue that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemBlueColor(_: Self) -> id;
/// Returns a color object for brown that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemBrownColor(_: Self) -> id;
/// Returns a color object for cyan that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemCyanColor(_: Self) -> id;
/// Returns a color object for gray that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemGrayColor(_: Self) -> id;
/// Returns a color object for green that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemGreenColor(_: Self) -> id;
/// Returns a color object for indigo that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemIndigoColor(_: Self) -> id;
/// Returns a color object for mint that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemMintColor(_: Self) -> id;
/// Returns a color object for orange that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemOrangeColor(_: Self) -> id;
/// Returns a color object for pink that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemPinkColor(_: Self) -> id;
/// Returns a color object for purple that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemPurpleColor(_: Self) -> id;
/// Returns a color object for red that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemRedColor(_: Self) -> id;
/// Returns a color object for teal that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemTealColor(_: Self) -> id;
/// Returns a color object for yellow that automatically adapts to vibrancy and accessibility settings.
unsafe fn systemYellowColor(_: Self) -> id;

// Transparent Color
/// Returns a color object whose grayscale and alpha values are both 0.0.
unsafe fn clearColor(_: Self) -> id;

// Fixed Colors
/// Returns a color object whose grayscale value is 0.0 and whose alpha value is 1.0.
unsafe fn blackColor(_: Self) -> id;
/// Returns a color object whose RGB value is 0.0, 0.0, 1.0 and whose alpha value is 1.0.
unsafe fn blueColor(_: Self) -> id;
/// Returns a color object whose RGB value is 0.6, 0.4, 0.2 and whose alpha value is 1.0.
unsafe fn brownColor(_: Self) -> id;
/// Returns a color object whose RGB value is 0.0, 1.0, 1.0 and whose alpha value is 1.0.
unsafe fn cyanColor(_: Self) -> id;
/// Returns a color object whose grayscale value is 1/3 and whose alpha value is 1.0.
unsafe fn darkGrayColor(_: Self) -> id;
/// Returns a color object whose grayscale value is 0.5 and whose alpha value is 1.0.
unsafe fn grayColor(_: Self) -> id;
/// Returns a color object whose RGB value is 0.0, 1.0, 0.0 and whose alpha value is 1.0.
unsafe fn greenColor(_: Self) -> id;
/// Returns a color object whose grayscale value is 2/3 and whose alpha value is 1.0.
unsafe fn lightGrayColor(_: Self) -> id;
/// Returns a color object whose RGB value is 1.0, 0.0, 1.0 and whose alpha value is 1.0.
unsafe fn magentaColor(_: Self) -> id;
/// Returns a color object whose RGB value is 1.0, 0.5, 0.0 and whose alpha value is 1.0.
unsafe fn orangeColor(_: Self) -> id;
/// Returns a color object whose RGB value is 0.5, 0.0, 0.5 and whose alpha value is 1.0.
unsafe fn purpleColor(_: Self) -> id;
/// Returns a color object whose RGB value is 1.0, 0.0, 0.0 and whose alpha value is 1.0.
unsafe fn redColor(_: Self) -> id;
/// Returns a color object whose grayscale and alpha values are both 1.0.
unsafe fn whiteColor(_: Self) -> id;
/// Returns a color object whose RGB value is 1.0, 1.0, 0.0 and whose alpha value is 1.0.
unsafe fn yellowColor(_: Self) -> id;

unsafe fn alphaComponent(self) -> CGFloat;
unsafe fn whiteComponent(self) -> CGFloat;
unsafe fn redComponent(self) -> CGFloat;
@@ -4641,9 +4805,6 @@ pub trait NSColor: Sized {
}

impl NSColor for id {
unsafe fn clearColor(_: Self) -> id {
msg_send![class!(NSColor), clearColor]
}
unsafe fn colorWithRed_green_blue_alpha_(
_: Self,
r: CGFloat,
@@ -4694,6 +4855,245 @@ impl NSColor for id {
msg_send![self, colorUsingColorSpace: color_space]
}

unsafe fn labelColor(_: Self) -> id {
msg_send![class!(NSColor), labelColor]
}
unsafe fn secondaryLabelColor(_: Self) -> id {
msg_send![class!(NSColor), secondaryLabelColor]
}
unsafe fn tertiaryLabelColor(_: Self) -> id {
msg_send![class!(NSColor), tertiaryLabelColor]
}
unsafe fn quaternaryLabelColor(_: Self) -> id {
msg_send![class!(NSColor), quaternaryLabelColor]
}

// Text Colors
unsafe fn textColor(_: Self) -> id {
msg_send![class!(NSColor), textColor]
}
unsafe fn placeholderTextColor(_: Self) -> id {
msg_send![class!(NSColor), placeholderTextColor]
}
unsafe fn selectedTextColor(_: Self) -> id {
msg_send![class!(NSColor), selectedTextColor]
}
unsafe fn textBackgroundColor(_: Self) -> id {
msg_send![class!(NSColor), textBackgroundColor]
}
unsafe fn selectedTextBackgroundColor(_: Self) -> id {
msg_send![class!(NSColor), selectedTextBackgroundColor]
}
unsafe fn keyboardFocusIndicatorColor(_: Self) -> id {
msg_send![class!(NSColor), keyboardFocusIndicatorColor]
}
unsafe fn unemphasizedSelectedTextColor(_: Self) -> id {
msg_send![class!(NSColor), unemphasizedSelectedTextColor]
}
unsafe fn unemphasizedSelectedTextBackgroundColor(_: Self) -> id {
msg_send![class!(NSColor), unemphasizedSelectedTextBackgroundColor]
}

// Content Colors
unsafe fn linkColor(_: Self) -> id {
msg_send![class!(NSColor), linkColor]
}
unsafe fn separatorColor(_: Self) -> id {
msg_send![class!(NSColor), separatorColor]
}
unsafe fn selectedContentBackgroundColor(_: Self) -> id {
msg_send![class!(NSColor), selectedContentBackgroundColor]
}
unsafe fn unemphasizedSelectedContentBackgroundColor(_: Self) -> id {
msg_send![class!(NSColor), unemphasizedSelectedContentBackgroundColor]
}

// Menu Colors
unsafe fn selectedMenuItemTextColor(_: Self) -> id {
msg_send![class!(NSColor), selectedMenuItemTextColor]
}

// Table Colors
unsafe fn gridColor(_: Self) -> id {
msg_send![class!(NSColor), gridColor]
}
unsafe fn headerTextColor(_: Self) -> id {
msg_send![class!(NSColor), headerTextColor]
}
unsafe fn alternatingContentBackgroundColors(_: Self) -> id {
msg_send![class!(NSColor), alternatingContentBackgroundColors]
}

// Control Colors
unsafe fn controlAccentColor(_: Self) -> id {
msg_send![class!(NSColor), controlAccentColor]
}
unsafe fn controlColor(_: Self) -> id {
msg_send![class!(NSColor), controlColor]
}
unsafe fn controlBackgroundColor(_: Self) -> id {
msg_send![class!(NSColor), controlBackgroundColor]
}
unsafe fn controlTextColor(_: Self) -> id {
msg_send![class!(NSColor), controlTextColor]
}
unsafe fn disabledControlTextColor(_: Self) -> id {
msg_send![class!(NSColor), disabledControlTextColor]
}
unsafe fn currentControlTint(_: Self) -> id {
msg_send![class!(NSColor), currentControlTint]
}
unsafe fn selectedControlColor(_: Self) -> id {
msg_send![class!(NSColor), selectedControlColor]
}
unsafe fn selectedControlTextColor(_: Self) -> id {
msg_send![class!(NSColor), selectedControlTextColor]
}
unsafe fn alternateSelectedControlTextColor(_: Self) -> id {
msg_send![class!(NSColor), alternateSelectedControlTextColor]
}
unsafe fn scrubberTexturedBackgroundColor(_: Self) -> id {
msg_send![class!(NSColor), scrubberTexturedBackgroundColor]
}

// Window Colors
unsafe fn windowBackgroundColor(_: Self) -> id {
msg_send![class!(NSColor), windowBackgroundColor]
}
unsafe fn windowFrameTextColor(_: Self) -> id {
msg_send![class!(NSColor), windowFrameTextColor]
}
unsafe fn underPageBackgroundColor(_: Self) -> id {
msg_send![class!(NSColor), underPageBackgroundColor]
}

// Highlights and Shadows
unsafe fn findHighlightColor(_: Self) -> id {
msg_send![class!(NSColor), findHighlightColor]
}
unsafe fn highlightColor(_: Self) -> id {
msg_send![class!(NSColor), highlightColor]
}
unsafe fn shadowColor(_: Self) -> id {
msg_send![class!(NSColor), shadowColor]
}

// Fill Colors
unsafe fn quaternarySystemFillColor(_: Self) -> id {
msg_send![class!(NSColor), quaternarySystemFillColor]
}
unsafe fn quinaryLabelColor(_: Self) -> id {
msg_send![class!(NSColor), quinaryLabelColor]
}
unsafe fn quinarySystemFillColor(_: Self) -> id {
msg_send![class!(NSColor), quinarySystemFillColor]
}
unsafe fn secondarySystemFillColor(_: Self) -> id {
msg_send![class!(NSColor), secondarySystemFillColor]
}
unsafe fn systemFillColor(_: Self) -> id {
msg_send![class!(NSColor), systemFillColor]
}
unsafe fn tertiarySystemFillColor(_: Self) -> id {
msg_send![class!(NSColor), tertiarySystemFillColor]
}
unsafe fn textInsertionPointColor(_: Self) -> id {
msg_send![class!(NSColor), textInsertionPointColor]
}

// Standard Colors
// https://developer.apple.com/documentation/appkit/nscolor/standard_colors?language=objc

// Adaptable System Colors
unsafe fn systemBlueColor(_: Self) -> id {
msg_send![class!(NSColor), systemBlueColor]
}
unsafe fn systemBrownColor(_: Self) -> id {
msg_send![class!(NSColor), systemBrownColor]
}
unsafe fn systemCyanColor(_: Self) -> id {
msg_send![class!(NSColor), systemCyanColor]
}
unsafe fn systemGrayColor(_: Self) -> id {
msg_send![class!(NSColor), systemGrayColor]
}
unsafe fn systemGreenColor(_: Self) -> id {
msg_send![class!(NSColor), systemGreenColor]
}
unsafe fn systemIndigoColor(_: Self) -> id {
msg_send![class!(NSColor), systemIndigoColor]
}
unsafe fn systemMintColor(_: Self) -> id {
msg_send![class!(NSColor), systemMintColor]
}
unsafe fn systemOrangeColor(_: Self) -> id {
msg_send![class!(NSColor), systemOrangeColor]
}
unsafe fn systemPinkColor(_: Self) -> id {
msg_send![class!(NSColor), systemPinkColor]
}
unsafe fn systemPurpleColor(_: Self) -> id {
msg_send![class!(NSColor), systemPurpleColor]
}
unsafe fn systemRedColor(_: Self) -> id {
msg_send![class!(NSColor), systemRedColor]
}
unsafe fn systemTealColor(_: Self) -> id {
msg_send![class!(NSColor), systemTealColor]
}
unsafe fn systemYellowColor(_: Self) -> id {
msg_send![class!(NSColor), systemYellowColor]
}

// Transparent Color
unsafe fn clearColor(_: Self) -> id {
msg_send![class!(NSColor), clearColor]
}

// Fixed Colors
unsafe fn blackColor(_: Self) -> id {
msg_send![class!(NSColor), blackColor]
}
unsafe fn blueColor(_: Self) -> id {
msg_send![class!(NSColor), blueColor]
}
unsafe fn brownColor(_: Self) -> id {
msg_send![class!(NSColor), brownColor]
}
unsafe fn cyanColor(_: Self) -> id {
msg_send![class!(NSColor), cyanColor]
}
unsafe fn darkGrayColor(_: Self) -> id {
msg_send![class!(NSColor), darkGrayColor]
}
unsafe fn grayColor(_: Self) -> id {
msg_send![class!(NSColor), grayColor]
}
unsafe fn greenColor(_: Self) -> id {
msg_send![class!(NSColor), greenColor]
}
unsafe fn lightGrayColor(_: Self) -> id {
msg_send![class!(NSColor), lightGrayColor]
}
unsafe fn magentaColor(_: Self) -> id {
msg_send![class!(NSColor), magentaColor]
}
unsafe fn orangeColor(_: Self) -> id {
msg_send![class!(NSColor), orangeColor]
}
unsafe fn purpleColor(_: Self) -> id {
msg_send![class!(NSColor), purpleColor]
}
unsafe fn redColor(_: Self) -> id {
msg_send![class!(NSColor), redColor]
}
unsafe fn whiteColor(_: Self) -> id {
msg_send![class!(NSColor), whiteColor]
}
unsafe fn yellowColor(_: Self) -> id {
msg_send![class!(NSColor), yellowColor]
}

unsafe fn alphaComponent(self) -> CGFloat {
msg_send![self, alphaComponent]
}
@@ -4991,4 +5391,107 @@ mod test {
let _nsApp = NSApp();
}
}

#[test]
pub fn test_nscolor_appkit_colors() {
use crate::base::nil;
unsafe {
// Check all colors are defined

// Label Colors
let _ = NSColor::labelColor(nil);
let _ = NSColor::secondaryLabelColor(nil);
let _ = NSColor::tertiaryLabelColor(nil);
let _ = NSColor::quaternaryLabelColor(nil);

// Text Colors
let _ = NSColor::textColor(nil);
let _ = NSColor::placeholderTextColor(nil);
let _ = NSColor::selectedTextColor(nil);
let _ = NSColor::textBackgroundColor(nil);
let _ = NSColor::selectedTextBackgroundColor(nil);
let _ = NSColor::keyboardFocusIndicatorColor(nil);
let _ = NSColor::unemphasizedSelectedTextColor(nil);
let _ = NSColor::unemphasizedSelectedTextBackgroundColor(nil);

// Content Colors
let _ = NSColor::linkColor(nil);
let _ = NSColor::separatorColor(nil);
let _ = NSColor::selectedContentBackgroundColor(nil);
let _ = NSColor::unemphasizedSelectedContentBackgroundColor(nil);

// Menu Colors
let _ = NSColor::selectedMenuItemTextColor(nil);

// Table Colors
let _ = NSColor::gridColor(nil);
let _ = NSColor::headerTextColor(nil);
let _ = NSColor::alternatingContentBackgroundColors(nil);

// Control Colors
let _ = NSColor::controlAccentColor(nil);
let _ = NSColor::controlColor(nil);
let _ = NSColor::controlBackgroundColor(nil);
let _ = NSColor::controlTextColor(nil);
let _ = NSColor::disabledControlTextColor(nil);
let _ = NSColor::currentControlTint(nil);
let _ = NSColor::selectedControlColor(nil);
let _ = NSColor::selectedControlTextColor(nil);
let _ = NSColor::alternateSelectedControlTextColor(nil);
let _ = NSColor::scrubberTexturedBackgroundColor(nil);

// Window Colors
let _ = NSColor::windowBackgroundColor(nil);
let _ = NSColor::windowFrameTextColor(nil);
let _ = NSColor::underPageBackgroundColor(nil);

// Highlights and Shadows
let _ = NSColor::findHighlightColor(nil);
let _ = NSColor::highlightColor(nil);
let _ = NSColor::shadowColor(nil);

// Fill Colors
let _ = NSColor::quaternarySystemFillColor(nil);
let _ = NSColor::quinaryLabelColor(nil);
let _ = NSColor::quinarySystemFillColor(nil);
let _ = NSColor::secondarySystemFillColor(nil);
let _ = NSColor::systemFillColor(nil);
let _ = NSColor::tertiarySystemFillColor(nil);
let _ = NSColor::textInsertionPointColor(nil);

// Adaptable System Colors
let _ = NSColor::systemBlueColor(nil);
let _ = NSColor::systemBrownColor(nil);
let _ = NSColor::systemCyanColor(nil);
let _ = NSColor::systemGrayColor(nil);
let _ = NSColor::systemGreenColor(nil);
let _ = NSColor::systemIndigoColor(nil);
let _ = NSColor::systemMintColor(nil);
let _ = NSColor::systemOrangeColor(nil);
let _ = NSColor::systemPinkColor(nil);
let _ = NSColor::systemPurpleColor(nil);
let _ = NSColor::systemRedColor(nil);
let _ = NSColor::systemTealColor(nil);
let _ = NSColor::systemYellowColor(nil);

// Transparent Color
let _ = NSColor::clearColor(nil);

// Fixed Colors
let _ = NSColor::blackColor(nil);
let _ = NSColor::blueColor(nil);
let _ = NSColor::brownColor(nil);
let _ = NSColor::cyanColor(nil);
let _ = NSColor::darkGrayColor(nil);
let _ = NSColor::grayColor(nil);
let _ = NSColor::greenColor(nil);
let _ = NSColor::lightGrayColor(nil);
let _ = NSColor::magentaColor(nil);
let _ = NSColor::orangeColor(nil);
let _ = NSColor::purpleColor(nil);
let _ = NSColor::redColor(nil);
let _ = NSColor::whiteColor(nil);
let _ = NSColor::yellowColor(nil);
}
}
}