pub struct ColorSchemeBuilder { /* private fields */ }Expand description
A builder for creating custom color schemes with intensity-based color stops.
ColorSchemeBuilder provides a fluent API for defining color gradients where
each color is associated with a specific intensity value (0.0 to 1.0). The
builder handles sorting, validation, and construction of the final ColorScheme.
§Builder Pattern
The builder follows a standard pattern:
- Create with
ColorSchemeBuilder::new - Add colors with
add_color - Build with
build
§Examples
use dotmax::color::scheme_builder::ColorSchemeBuilder;
use dotmax::Color;
// Create a "sunset" gradient
let scheme = ColorSchemeBuilder::new("sunset")
.add_color(0.0, Color::rgb(255, 100, 0)) // Orange
.add_color(0.5, Color::rgb(255, 0, 100)) // Pink
.add_color(1.0, Color::rgb(100, 0, 255)) // Purple
.build()?;
// Use the scheme
let mid_color = scheme.sample(0.5);Implementations§
Source§impl ColorSchemeBuilder
impl ColorSchemeBuilder
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new color scheme builder with the given name.
The builder starts with no color stops. Use add_color
to add color stops before calling build.
§Arguments
name- Human-readable name for the scheme (e.g., “fire”, “ocean”, “brand”)
§Examples
use dotmax::color::scheme_builder::ColorSchemeBuilder;
let builder = ColorSchemeBuilder::new("my_gradient");Sourcepub fn add_color(self, intensity: f32, color: Color) -> Self
pub fn add_color(self, intensity: f32, color: Color) -> Self
Add a color stop at the specified intensity.
Color stops define the gradient by mapping intensity values to colors.
Colors can be added in any order - they will be automatically sorted
by intensity when build is called.
§Arguments
intensity- Intensity value from 0.0 (low) to 1.0 (high)color- The RGB color at this intensity
§Returns
Returns self for method chaining.
§Note
Intensity validation happens during build,
not during add_color. This allows for flexible construction patterns.
§Examples
use dotmax::color::scheme_builder::ColorSchemeBuilder;
use dotmax::Color;
let builder = ColorSchemeBuilder::new("gradient")
.add_color(0.0, Color::black())
.add_color(0.5, Color::rgb(128, 128, 128))
.add_color(1.0, Color::white());Sourcepub fn build(self) -> Result<ColorScheme, DotmaxError>
pub fn build(self) -> Result<ColorScheme, DotmaxError>
Build the color scheme, validating the configuration.
This method validates all color stops and constructs the final ColorScheme.
Color stops are automatically sorted by intensity in ascending order.
§Validation Rules
The following conditions result in errors:
- Less than 2 color stops: Returns
DotmaxError::InvalidColorScheme - Intensity out of range (< 0.0 or > 1.0): Returns
DotmaxError::InvalidIntensity - Duplicate intensity values: Returns
DotmaxError::InvalidColorScheme
§Returns
Ok(ColorScheme)- A valid color scheme ready for useErr(DotmaxError)- If validation fails
§Examples
use dotmax::color::scheme_builder::ColorSchemeBuilder;
use dotmax::Color;
// Successful build
let scheme = ColorSchemeBuilder::new("valid")
.add_color(0.0, Color::black())
.add_color(1.0, Color::white())
.build()?;
// Failed build: not enough colors
let result = ColorSchemeBuilder::new("invalid")
.add_color(0.5, Color::white())
.build();
assert!(result.is_err());§Errors
Returns DotmaxError::InvalidColorScheme if:
- Fewer than 2 color stops are defined
- Two or more color stops have the same intensity value
Returns DotmaxError::InvalidIntensity if:
- Any intensity value is less than 0.0 or greater than 1.0
Trait Implementations§
Source§impl Clone for ColorSchemeBuilder
impl Clone for ColorSchemeBuilder
Source§fn clone(&self) -> ColorSchemeBuilder
fn clone(&self) -> ColorSchemeBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ColorSchemeBuilder
impl RefUnwindSafe for ColorSchemeBuilder
impl Send for ColorSchemeBuilder
impl Sync for ColorSchemeBuilder
impl Unpin for ColorSchemeBuilder
impl UnwindSafe for ColorSchemeBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more