Expand description
Color and gradient types, functions, properties and macros.
§Colors
The example demonstrates multiple ways of declaring or selecting a color, all blue in this case.
use zng::prelude::*;
fn sample(color: impl IntoVar<color::Rgba>) -> UiNode {
Wgt! {
layout::size = (100, 40);
widget::background_color = color;
}
}
Window! {
child = Stack!(
top_to_bottom,
5,
ui_vec![
sample(hex!(#00F)),
sample(rgb(0, 0, 255)),
sample(rgb(0.0, 0.0, 1.0)),
sample(colors::BLUE),
sample(hsv(240.deg(), 100.pct(), 100.pct())),
sample(hsl(240.deg(), 100.pct(), 50.pct())),
]
);
}The Rgba type also provides methods for basic color manipulation and mixing.
sample(colors::GREEN.darken(50.pct())),
sample(colors::GREEN),
sample(colors::GREEN.lighten(50.pct())),
sample(colors::GREEN.desaturate(50.pct())),
sample(colors::GREEN.with_alpha(50.pct()).mix_normal(colors::BLUE)),Color mixing methods apply the color over the parameter, that is foreground.mix_normal(background).
§Color Filters
The filter module provides implementation of pixel filter graphical effects that you may be
familiar with from CSS.
use zng::prelude::*;
Window! {
clear_color = colors::BLACK.transparent();
color::filter::opacity = 50.pct();
child = Text!("translucent window");
}The example above applies filter::opacity on the window, making it translucent in view-process
implementations that support transparent windows.
§Gradients
The gradient module provides implementation of linear, radial and conic gradients. Usually the
gradient nodes are wrapped in some other property like widget::background_conic, but they can be used directly.
use zng::prelude::*;
Window! {
widget::background = color::gradient::conic_gradient(
50.pct(),
45.deg(),
color::gradient::stops![colors::GREEN, (colors::RED, 30.pct()), colors::BLUE],
);
// OR
widget::background_conic = {
center: 50.pct(),
angle: 45.deg(),
stops: color::gradient::stops![colors::GREEN, (colors::RED, 30.pct()), colors::BLUE],
};
}See gradient::stops! for the macro syntax.
§Full API
See zng_color, zng_wgt_filter and zng_wgt_fill for the full API.
Modules§
- colors
- Named primary, secondary and tertiary colors.
- filter
- Color filter types and properties.
- gradient
- Color gradient types and nodes.
- web_
colors - Named web colors.
Macros§
- hex
- Hexadecimal color literal.
Structs§
- Hsla
- HSL + alpha.
- Hsva
- HSV + alpha
- Light
Dark - Represents a dark and light color.
- PreMul
Rgba - Pre-multiplied RGB + alpha.
- Rgba
- RGB + alpha.
Enums§
- Color
Scheme - Color scheme preference.
- Lerp
Space - Defines the color space for color interpolation.
- MixBlend
Mode - Color mix blend mode.
Statics§
- COLOR_
SCHEME_ VAR - Defines the preferred color scheme in a context.
Traits§
- Light
Dark VarExt - Extension methods for
Var<LightDark>. - MixAdjust
- Color mix and adjustment methods.
Functions§
- accent_
color PDefines the preferred accent color in the widget and descendants.- base_
color PDefines the seed color used by widgets to derive background, non active border.- color_
scheme PDefines the preferred color scheme in the widget and descendants.- flood
- Node that fills the widget area with a color.
- hsl
- HSL color, opaque, alpha is set to
1.0. - hsla
- HSLA color.
- hsla_
linear_ sampler - Animation sampler that sets the
lerp_spacetoLerpSpace::HslaLinear. - hsla_
sampler - Animation sampler that sets the
lerp_spacetoLerpSpace::Hsla. - hsv
- HSV color, opaque, alpha is set to
1.0. - hsva
- HSVA color.
- lerp_
space - Gets the lerp space used for color interpolation.
- light_
dark - RGBA color pair.
- rgb
- RGB color, opaque, alpha is set to
1.0. - rgba
- RGBA color.
- rgba_
sampler - Animation sampler that sets the
lerp_spacetoLerpSpace::Rgba. - with_
lerp_ space - Calls
fwithlerp_spaceset tospace.