pub enum Color {
Show 39 variants
Custom(Arc<RwLock<Id<Object>>>),
SystemBlack,
SystemWhite,
SystemBrown,
SystemBlue,
SystemGreen,
SystemIndigo,
SystemOrange,
SystemPink,
SystemPurple,
SystemRed,
SystemTeal,
SystemYellow,
SystemGray,
SystemGray2,
SystemGray3,
SystemGray4,
SystemGray5,
SystemGray6,
Clear,
Label,
LabelSecondary,
LabelTertiary,
LabelQuaternary,
SystemFill,
SystemFillSecondary,
SystemFillTertiary,
SystemFillQuaternary,
PlaceholderText,
SystemBackground,
SystemBackgroundSecondary,
SystemBackgroundTertiary,
Separator,
OpaqueSeparator,
Link,
DarkText,
LightText,
MacOSWindowBackgroundColor,
MacOSUnderPageBackgroundColor,
}
Expand description
Represents a Color. You can create custom colors using the various
initializers, or opt to use a system-provided color. The system provided
colors will automatically switch to the “correct” colors/shades depending on whether
the user is in light or dark mode; to support this with custom colors, you can create a
dynamic
color with a custom handler that determines a color depending on a variety of system
settings.
This enum is thread-safe, so clone away as needed.
Variants
Custom(Arc<RwLock<Id<Object>>>)
Represents an NSColor
on macOS, and a UIColor
everywhere else. You typically
don’t create this variant yourself; use the initializers found on this enum.
If you need to do custom work not covered by this enum, you can drop to the Objective-C level yourself and wrap your color in this.
SystemBlack
The system-provided black. Harsh - you probably don’t want to use this.
SystemWhite
The system-provided absolute white.
SystemBrown
The system-provided brown.
SystemBlue
The system-provided blue. This value automatically switches to the correct variant depending on light or dark mode.
SystemGreen
The system-provided green. This value automatically switches to the correct variant depending on light or dark mode.
SystemIndigo
The system-provided indigo. This value automatically switches to the correct variant depending on light or dark mode.
SystemOrange
The system-provided orange. This value automatically switches to the correct variant depending on light or dark mode.
SystemPink
The system-provided pink. This value automatically switches to the correct variant depending on light or dark mode.
SystemPurple
The system-provided purple. This value automatically switches to the correct variant depending on light or dark mode.
SystemRed
The system-provided red. This value automatically switches to the correct variant depending on light or dark mode.
SystemTeal
The system-provided teal. This value automatically switches to the correct variant depending on light or dark mode.
SystemYellow
The system-provided yellow. This value automatically switches to the correct variant depending on light or dark mode.
SystemGray
The system-provided base gray color. This value automatically switches to the correct variant depending on light or dark mode.
SystemGray2
The system-provided secondary-level gray color. This value automatically switches to the correct variant depending on light or dark mode.
SystemGray3
The system-provided third-level gray color. This value automatically switches to the correct variant depending on light or dark mode.
SystemGray4
The system-provided fourth-level gray color. This value automatically switches to the correct variant depending on light or dark mode.
SystemGray5
The system-provided fifth-level gray color. This value automatically switches to the correct variant depending on light or dark mode.
SystemGray6
The system-provided sixth-level gray color. This value automatically switches to the correct variant depending on light or dark mode.
Clear
Represents a clear color. This value automatically switches to the correct variant depending on light or dark mode.
Label
The default label color. This value automatically switches to the correct variant depending on light or dark mode.
LabelSecondary
The default color for a second-level label. This value automatically switches to the correct variant depending on light or dark mode.
LabelTertiary
The default color for a third-level label. This value automatically switches to the correct variant depending on light or dark mode.
LabelQuaternary
The default color for a fourth-level label. This value automatically switches to the correct variant depending on light or dark mode.
SystemFill
The default system fill color. This value automatically switches to the correct variant depending on light or dark mode.
SystemFillSecondary
The default system second-level fill color. This value automatically switches to the correct variant depending on light or dark mode.
SystemFillTertiary
The default system third-level fill color. This value automatically switches to the correct variant depending on light or dark mode.
SystemFillQuaternary
The default system fourth-level fill color. This value automatically switches to the correct variant depending on light or dark mode.
PlaceholderText
The default color to use for placeholder text. This value automatically switches to the correct variant depending on light or dark mode.
SystemBackground
The default system background color. This value automatically switches to the correct variant depending on light or dark mode.
SystemBackgroundSecondary
The default system second-level background color. This value automatically switches to the correct variant depending on light or dark mode.
SystemBackgroundTertiary
The default system third-level background color. This value automatically switches to the correct variant depending on light or dark mode.
Separator
The default color to use for thin separators/lines that still allow content to be visible underneath. This value automatically switches to the correct variant depending on light or dark mode.
OpaqueSeparator
The default color to use for thin separators/lines that do not allow content underneath to be visible. This value automatically switches to the correct variant depending on light or dark mode.
Link
The default color to use for rendering links. This value automatically switches to the correct variant depending on light or dark mode.
DarkText
The un-adaptable color for text on a light background.
LightText
The un-adaptable color for text on a dark background.
MacOSWindowBackgroundColor
The background color for a given window in the system theme.
MacOSUnderPageBackgroundColor
The background color that should appear under a page per the system theme.
Implementations
sourceimpl Color
impl Color
sourcepub fn rgba(red: u8, green: u8, blue: u8, alpha: u8) -> Self
pub fn rgba(red: u8, green: u8, blue: u8, alpha: u8) -> Self
Creates and returns a color in the RGB space, with the specified alpha level.
sourcepub fn rgb(red: u8, green: u8, blue: u8) -> Self
pub fn rgb(red: u8, green: u8, blue: u8) -> Self
Creates and returns a color in the RGB space, with the alpha level
set to 255
by default. Shorthand for rgba
.
sourcepub fn hsba(hue: u8, saturation: u8, brightness: u8, alpha: u8) -> Self
pub fn hsba(hue: u8, saturation: u8, brightness: u8, alpha: u8) -> Self
Creates and returns a color in the HSB space, with the specified alpha level.
sourcepub fn hsb(hue: u8, saturation: u8, brightness: u8) -> Self
pub fn hsb(hue: u8, saturation: u8, brightness: u8) -> Self
Creates and returns a color in the RGB space, with the alpha level
set to 255
by default. Shorthand for hsba
.
sourcepub fn white_alpha(level: CGFloat, alpha: CGFloat) -> Self
pub fn white_alpha(level: CGFloat, alpha: CGFloat) -> Self
Creates and returns a white color with the specified level or intensity, along with the specified alpha.
sourcepub fn white(level: CGFloat) -> Self
pub fn white(level: CGFloat) -> Self
Creates and returns a white Color with the specified level or intensity, with the alpha
value set to 255
. Shorthand for white_alpha
.
sourcepub fn hexa(_hex: &str, _alpha: u8) -> Self
pub fn hexa(_hex: &str, _alpha: u8) -> Self
Given a hex code and alpha level, returns a Color
in the RGB space.
This method is not an ideal one to use, but is offered as a convenience method for those coming from other environments where these are more common.
sourcepub fn hex(hex: &str) -> Self
pub fn hex(hex: &str) -> Self
Given a hex code, returns a Color
in the RGB space with alpha pre-set to 255
.
This method is not an ideal one to use, but is offered as a convenience method for those coming from other environments where these are more common.
sourcepub fn dynamic<F>(handler: F) -> Self where
F: Fn(Style) -> Color + 'static,
pub fn dynamic<F>(handler: F) -> Self where
F: Fn(Style) -> Color + 'static,
Creates and returns a dynamic color, which stores a handler and enables returning specific colors at appearance time based on device traits (i.e, dark mode vs light mode, contrast settings, etc).
For systems that don’t support dark mode (macOS pre-Mojave) this will always paint with the “default” or “light” color.
Returning a dynamic color in your handler is unsupported and may panic.
sourcepub fn cg_color(&self) -> CGColor
pub fn cg_color(&self) -> CGColor
Returns a CGColor, which can be used in Core Graphics calls as well as other areas.
Note that CGColor is not a context-aware color, unlike our NSColor
and UIColor
objects. If you’re painting in a context that requires dark mode support, make sure
you’re not using a cached version of this unless you explicitly want the same color
in every context it’s used in.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more